diff --git a/src/java.xml/share/classes/com/sun/org/apache/bcel/internal/generic/InstructionComparator.java b/src/java.xml/share/classes/com/sun/org/apache/bcel/internal/generic/InstructionComparator.java index 9f806a2d3d7..3f6bb56e70e 100644 --- a/src/java.xml/share/classes/com/sun/org/apache/bcel/internal/generic/InstructionComparator.java +++ b/src/java.xml/share/classes/com/sun/org/apache/bcel/internal/generic/InstructionComparator.java @@ -35,12 +35,14 @@ public interface InstructionComparator { InstructionComparator DEFAULT = (i1, i2) -> { + // Affirm the identity used by HashMap to identify an instance + if (i1 == i2) { + return true; + } if (i1.getOpcode() == i2.getOpcode()) { if (i1 instanceof BranchInstruction) { // BIs are never equal to make targeters work correctly (BCEL-195) return false; -// } else if (i1 == i2) { TODO consider adding this shortcut -// return true; // this must be AFTER the BI test } if (i1 instanceof ConstantPushInstruction) { return ((ConstantPushInstruction) i1).getValue().equals(((ConstantPushInstruction) i2).getValue()); diff --git a/test/jaxp/javax/xml/jaxp/unittest/transform/InstCompareTest.java b/test/jaxp/javax/xml/jaxp/unittest/transform/InstCompareTest.java new file mode 100644 index 00000000000..ca11d2a2cde --- /dev/null +++ b/test/jaxp/javax/xml/jaxp/unittest/transform/InstCompareTest.java @@ -0,0 +1,44 @@ +/* + * Copyright (c) 2025, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +package transform; + +import com.sun.org.apache.bcel.internal.generic.GOTO; +import com.sun.org.apache.bcel.internal.generic.GotoInstruction; +import org.testng.Assert; +import org.testng.annotations.Test; + +/* + * @test + * @modules java.xml/com.sun.org.apache.bcel.internal.generic + * @run testng transform.InstCompareTest + * @summary Verify GotoInstruction .equals is == to itself + */ +public class InstCompareTest { + + @Test + void testInstCompare() { + GotoInstruction gotox = new GOTO(null); + Assert.assertTrue(gotox.equals(gotox), "Goto instruction should be .equals self"); + } +}