Return-Path: X-Original-To: apmail-commons-commits-archive@minotaur.apache.org Delivered-To: apmail-commons-commits-archive@minotaur.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 7093E17BEC for ; Thu, 27 Aug 2015 23:08:29 +0000 (UTC) Received: (qmail 5288 invoked by uid 500); 27 Aug 2015 23:08:29 -0000 Delivered-To: apmail-commons-commits-archive@commons.apache.org Received: (qmail 5204 invoked by uid 500); 27 Aug 2015 23:08:29 -0000 Mailing-List: contact commits-help@commons.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@commons.apache.org Delivered-To: mailing list commits@commons.apache.org Received: (qmail 5194 invoked by uid 99); 27 Aug 2015 23:08:29 -0000 Received: from eris.apache.org (HELO hades.apache.org) (140.211.11.105) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 27 Aug 2015 23:08:29 +0000 Received: from hades.apache.org (localhost [127.0.0.1]) by hades.apache.org (ASF Mail Server at hades.apache.org) with ESMTP id F27C3AC009E for ; Thu, 27 Aug 2015 23:08:28 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: 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 Date: Thu, 27 Aug 2015 23:08:28 -0000 To: commits@commons.apache.org From: sebb@apache.org X-Mailer: svnmailer-1.0.9 Message-Id: <20150827230828.F27C3AC009E@hades.apache.org> 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 type attribute can be add,u + addition of hashCode() to generic/Instruction.java breaks Targeters. Never make distinct BranchInstructions compare equal Select constructor allows partially constructed instance to escape. Re-ordered code to delay the escape. Minor doc error in BranchInstruction.java ClassDumper example duplicates field attribute types 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); + } }