Author: sebb
Date: Fri Jun 10 12:07:25 2016
New Revision: 1747689
URL: http://svn.apache.org/viewvc?rev=1747689&view=rev
Log:
BCEL-273 - Regressions running FindBugs on BCEL6
Reverted to previous code; added comments
Modified:
commons/proper/bcel/trunk/src/main/java/org/apache/bcel/generic/BranchHandle.java
commons/proper/bcel/trunk/src/main/java/org/apache/bcel/generic/InstructionHandle.java
Modified:
commons/proper/bcel/trunk/src/main/java/org/apache/bcel/generic/BranchHandle.java
URL:
http://svn.apache.org/viewvc/commons/proper/bcel/trunk/src/main/java/org/apache/bcel/generic/BranchHandle.java?rev=1747689&r1=1747688&r2=1747689&view=diff
==============================================================================
---
commons/proper/bcel/trunk/src/main/java/org/apache/bcel/generic/BranchHandle.java
(original)
+++
commons/proper/bcel/trunk/src/main/java/org/apache/bcel/generic/BranchHandle.java
Fri Jun 10 12:07:25 2016
@@ -30,8 +30,14 @@ package org.apache.bcel.generic;
*/
public final class BranchHandle extends InstructionHandle {
+ // This is also a cache in case the InstructionHandle#swapInstruction()
method is used
+ // See BCEL-273
+ private BranchInstruction bi; // An alias in fact, but saves lots of casts
+
+
private BranchHandle(final BranchInstruction i) {
super(i);
+ bi = i;
}
/** Factory methods.
@@ -58,11 +64,6 @@ public final class BranchHandle extends
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
@@ -70,22 +71,22 @@ public final class BranchHandle extends
*/
@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);
+ 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;
}
@@ -94,7 +95,7 @@ public final class BranchHandle extends
* Pass new target to instruction.
*/
public void setTarget( final InstructionHandle ih ) {
- getBI().setTarget(ih);
+ bi.setTarget(ih);
}
@@ -102,7 +103,7 @@ public final class BranchHandle extends
* 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);
}
@@ -110,7 +111,7 @@ public final class BranchHandle extends
* @return target of instruction.
*/
public InstructionHandle getTarget() {
- return getBI().getTarget();
+ return bi.getTarget();
}
@@ -124,5 +125,6 @@ public final class BranchHandle extends
throw new ClassGenException("Assigning " + i
+ " to branch handle which is not a branch instruction");
}
+ bi = (BranchInstruction) i;
}
}
Modified:
commons/proper/bcel/trunk/src/main/java/org/apache/bcel/generic/InstructionHandle.java
URL:
http://svn.apache.org/viewvc/commons/proper/bcel/trunk/src/main/java/org/apache/bcel/generic/InstructionHandle.java?rev=1747689&r1=1747688&r2=1747689&view=diff
==============================================================================
---
commons/proper/bcel/trunk/src/main/java/org/apache/bcel/generic/InstructionHandle.java
(original)
+++
commons/proper/bcel/trunk/src/main/java/org/apache/bcel/generic/InstructionHandle.java
Fri Jun 10 12:07:25 2016
@@ -95,7 +95,13 @@ public class InstructionHandle {
* Temporarily swap the current instruction, without disturbing
* anything. Meant to be used by a debugger, implementing
* breakpoints. Current instruction is returned.
+ * <p>
+ * Warning: if this is used on a BranchHandle then some methods such as
+ * getPosition() will still refer to the original cached instruction,
whereas
+ * other BH methods may affect the cache and the replacement instruction.
*/
+ // See BCEL-273
+ // TODO remove this method in any redesign of BCEL
public Instruction swapInstruction( final Instruction i ) {
Instruction oldInstruction = instruction;
instruction = i;