You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by se...@apache.org on 2015/08/28 01:08:28 UTC
svn commit: r1698243 - in /commons/proper/bcel/trunk/src: changes/changes.xml
main/java/org/apache/commons/bcel6/generic/InstructionComparator.java
test/java/org/apache/commons/bcel6/generic/InstructionHandleTestCase.java
Author: sebb
Date: Thu Aug 27 23:08:28 2015
New Revision: 1698243
URL: http://svn.apache.org/r1698243
Log:
BCEL-195 addition of hashCode() to generic/Instruction.java breaks Targeters. Never make distinct BranchInstructions compare equal
Modified:
commons/proper/bcel/trunk/src/changes/changes.xml
commons/proper/bcel/trunk/src/main/java/org/apache/commons/bcel6/generic/InstructionComparator.java
commons/proper/bcel/trunk/src/test/java/org/apache/commons/bcel6/generic/InstructionHandleTestCase.java
Modified: commons/proper/bcel/trunk/src/changes/changes.xml
URL: http://svn.apache.org/viewvc/commons/proper/bcel/trunk/src/changes/changes.xml?rev=1698243&r1=1698242&r2=1698243&view=diff
==============================================================================
--- commons/proper/bcel/trunk/src/changes/changes.xml (original)
+++ commons/proper/bcel/trunk/src/changes/changes.xml Thu Aug 27 23:08:28 2015
@@ -63,6 +63,7 @@ The <action> type attribute can be add,u
<body>
<release version="6.0" date="TBA" description="Major release with Java 7 and 8 support">
+ <action issue="BCEL-195" type="fix">addition of hashCode() to generic/Instruction.java breaks Targeters. Never make distinct BranchInstructions compare equal</action>
<action issue="BCEL-261" type="fix">Select constructor allows partially constructed instance to escape. Re-ordered code to delay the escape.</action>
<action issue="BCEL-259" type="fix">Minor doc error in BranchInstruction.java</action>
<action issue="BCEL-260" type="fix">ClassDumper example duplicates field attribute types</action>
Modified: commons/proper/bcel/trunk/src/main/java/org/apache/commons/bcel6/generic/InstructionComparator.java
URL: http://svn.apache.org/viewvc/commons/proper/bcel/trunk/src/main/java/org/apache/commons/bcel6/generic/InstructionComparator.java?rev=1698243&r1=1698242&r2=1698243&view=diff
==============================================================================
--- commons/proper/bcel/trunk/src/main/java/org/apache/commons/bcel6/generic/InstructionComparator.java (original)
+++ commons/proper/bcel/trunk/src/main/java/org/apache/commons/bcel6/generic/InstructionComparator.java Thu Aug 27 23:08:28 2015
@@ -35,20 +35,13 @@ public interface InstructionComparator {
@Override
public boolean equals( Instruction i1, Instruction i2 ) {
+ if (i1 == i2) {
+ return true; // shortcut for identical objects
+ }
if (i1.getOpcode() == i2.getOpcode()) {
- if (i1 instanceof Select) {
- InstructionHandle[] t1 = ((Select) i1).getTargets();
- InstructionHandle[] t2 = ((Select) i2).getTargets();
- if (t1.length == t2.length) {
- for (int i = 0; i < t1.length; i++) {
- if (t1[i] != t2[i]) {
- return false;
- }
- }
- return true;
- }
- } else if (i1 instanceof BranchInstruction) {
- return ((BranchInstruction) i1).getTarget() == ((BranchInstruction) i2).getTarget();
+ if (i1 instanceof BranchInstruction) {
+ // Different BIs are never equal to make targeters work correctly (BCEL-195)
+ return false; // identity checked above
} else if (i1 instanceof ConstantPushInstruction) {
return ((ConstantPushInstruction) i1).getValue().equals(
((ConstantPushInstruction) i2).getValue());
Modified: commons/proper/bcel/trunk/src/test/java/org/apache/commons/bcel6/generic/InstructionHandleTestCase.java
URL: http://svn.apache.org/viewvc/commons/proper/bcel/trunk/src/test/java/org/apache/commons/bcel6/generic/InstructionHandleTestCase.java?rev=1698243&r1=1698242&r2=1698243&view=diff
==============================================================================
--- commons/proper/bcel/trunk/src/test/java/org/apache/commons/bcel6/generic/InstructionHandleTestCase.java (original)
+++ commons/proper/bcel/trunk/src/test/java/org/apache/commons/bcel6/generic/InstructionHandleTestCase.java Thu Aug 27 23:08:28 2015
@@ -35,4 +35,12 @@ public class InstructionHandleTestCase {
public void testGetIHnull() {
InstructionHandle.getInstructionHandle(null);
}
+
+ @Test
+ public void testBCEL195() {
+ InstructionList il = new InstructionList();
+ InstructionHandle ih = il.append(InstructionConstants.NOP);
+ new TABLESWITCH(new int[0], new InstructionHandle[0], ih);
+ new TABLESWITCH(new int[0], new InstructionHandle[0], ih);
+ }
}