Skip to content

Commit

Permalink
Fixes BCEL-273 by partly reverting
Browse files Browse the repository at this point in the history
adf9fc1.

java.lang.ClassCastException: edu.umd.cs.findbugs.bcel.generic.NULL2Z
cannot be cast to org.apache.commons.bcel6.generic.BranchInstruction
At
org.apache.commons.bcel6.generic.BranchHandle.getBI(BranchHandle.java:64)
At
org.apache.commons.bcel6.generic.BranchHandle.getPosition(BranchHandle.java:73)
At
edu.umd.cs.findbugs.ba.BetterCFGBuilder2$Subroutine.addInstruction(BetterCFGBuilder2.java:296)
At
edu.umd.cs.findbugs.ba.BetterCFGBuilder2.build(BetterCFGBuilder2.java:867)
  • Loading branch information
iloveeclipse committed Jun 8, 2016
1 parent 452b5e6 commit 25dfa20
Showing 1 changed file with 15 additions and 15 deletions.
30 changes: 15 additions & 15 deletions src/main/java/org/apache/bcel/generic/BranchHandle.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,12 @@
*/
public final class BranchHandle extends InstructionHandle {

private BranchInstruction bi; // An alias in fact, but saves lots of casts


private BranchHandle(final BranchInstruction i) {
super(i);
bi = i;
}

/** Factory methods.
Expand All @@ -58,34 +62,29 @@ protected void addHandle() {
bh_list = this;
}

// get the instruction as a BranchInstruction
// (do the cast once)
private BranchInstruction getBI() {
return (BranchInstruction) super.getInstruction();
}

/* Override InstructionHandle methods: delegate to branch instruction.
* Through this overriding all access to the private i_position field should
* be prevented.
*/
@Override
public int getPosition() {
return getBI().getPosition();
return bi.getPosition();
}


@Override
void setPosition( final int pos ) {
// Original code: i_position = bi.position = pos;
getBI().setPosition(pos);
super.setPosition(pos);
void setPosition( int pos ) {
// Original code: i_position = bi.position = pos;
bi.setPosition(pos);
super.setPosition(pos);
}


@Override
protected int updatePosition( final int offset, final int max_offset ) {
int x = getBI().updatePosition(offset, max_offset);
super.setPosition(getBI().getPosition());
int x = bi.updatePosition(offset, max_offset);
super.setPosition(bi.getPosition());
return x;
}

Expand All @@ -94,23 +93,23 @@ protected int updatePosition( final int offset, final int max_offset ) {
* Pass new target to instruction.
*/
public void setTarget( final InstructionHandle ih ) {
getBI().setTarget(ih);
bi.setTarget(ih);
}


/**
* Update target of instruction.
*/
public void updateTarget( final InstructionHandle old_ih, final InstructionHandle new_ih ) {
getBI().updateTarget(old_ih, new_ih);
bi.updateTarget(old_ih, new_ih);
}


/**
* @return target of instruction.
*/
public InstructionHandle getTarget() {
return getBI().getTarget();
return bi.getTarget();
}


Expand All @@ -124,5 +123,6 @@ public void setInstruction( final Instruction i ) { // TODO could be package-pro
throw new ClassGenException("Assigning " + i
+ " to branch handle which is not a branch instruction");
}
bi = (BranchInstruction) i;
}
}

0 comments on commit 25dfa20

Please sign in to comment.