diff --git a/src/java.xml/share/classes/com/sun/org/apache/bcel/internal/generic/BranchInstruction.java b/src/java.xml/share/classes/com/sun/org/apache/bcel/internal/generic/BranchInstruction.java index aea205a78f2..e650bea8ec5 100644 --- a/src/java.xml/share/classes/com/sun/org/apache/bcel/internal/generic/BranchInstruction.java +++ b/src/java.xml/share/classes/com/sun/org/apache/bcel/internal/generic/BranchInstruction.java @@ -30,7 +30,7 @@ import com.sun.org.apache.bcel.internal.util.ByteSequence; * LOOKUPSWITCH and TABLESWITCH. * * @see InstructionList - * @LastModified: Jan 2020 + * @LastModified: July 2020 */ public abstract class BranchInstruction extends Instruction implements InstructionTargeter { @@ -230,6 +230,23 @@ public abstract class BranchInstruction extends Instruction implements Instructi return target == ih; } + /** + * Updates the opcode. Before changing the opcode, reset the target so that + * the old instruction is removed from the HashSet and the new one then added. + * @param opcode the opcode + */ + @Override + void setOpcode( final short opcode ) { + if (target == null) { + super.setOpcode(opcode); + } else { + // reset target before changing the opcode + InstructionHandle t = target; + setTarget(null); + super.setOpcode(opcode); + setTarget(t); + } + } /** * Inform target that it's not targeted anymore. diff --git a/src/java.xml/share/classes/com/sun/org/apache/bcel/internal/generic/Instruction.java b/src/java.xml/share/classes/com/sun/org/apache/bcel/internal/generic/Instruction.java index 08f801a0bb4..20188a9f16a 100644 --- a/src/java.xml/share/classes/com/sun/org/apache/bcel/internal/generic/Instruction.java +++ b/src/java.xml/share/classes/com/sun/org/apache/bcel/internal/generic/Instruction.java @@ -29,7 +29,7 @@ import com.sun.org.apache.bcel.internal.util.ByteSequence; /** * Abstract super class for all Java byte codes. * - * @LastModified: Jan 2020 + * @LastModified: July 2020 */ public abstract class Instruction implements Cloneable { @@ -511,7 +511,7 @@ public abstract class Instruction implements Cloneable { /** * Needed in readInstruction and subclasses in this package */ - final void setOpcode( final short opcode ) { + void setOpcode( final short opcode ) { this.opcode = opcode; } diff --git a/test/jaxp/javax/xml/jaxp/unittest/transform/BCELHashCodeTest.java b/test/jaxp/javax/xml/jaxp/unittest/transform/BCELHashCodeTest.java new file mode 100644 index 00000000000..538aa9e2909 --- /dev/null +++ b/test/jaxp/javax/xml/jaxp/unittest/transform/BCELHashCodeTest.java @@ -0,0 +1,58 @@ +/* + * Copyright (c) 2020, 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 javax.xml.transform.Transformer; +import javax.xml.transform.TransformerConfigurationException; +import javax.xml.transform.TransformerFactory; +import javax.xml.transform.stream.StreamSource; +import org.testng.annotations.Test; + +/* + * @test + * @bug 8248348 + * @library /javax/xml/jaxp/libs /javax/xml/jaxp/unittest + * @run testng transform.BCELHashCodeTest + * @summary The addition of the hashCode() method to Instruction.java in BCEL 6.0 + * caused a regression. This test verifies that the issue has been fixed. + */ +public class BCELHashCodeTest { + /** + * Verifies the patch by attempting to create a transformer from the stylesheet. + * The stylesheet contains an extra table-row with element-id="17921" that + * causes the generated bytecode to exceed the 64Kbyte method size limit. + * Splitting it into multiple methods requires mutating the instructions that + * results in an Exception without the fix. The stylesheet would pass with + * or without the fix if the extra table-row is removed. + * + * @throws TransformerConfigurationException if the test fails + */ + @Test + public void test() throws TransformerConfigurationException { + StreamSource stylesheet = new StreamSource(this.getClass() + .getResourceAsStream("BCELHashCodeTest.xsl")); + TransformerFactory tFactory =TransformerFactory.newInstance(); + Transformer transformer = tFactory.newTransformer(stylesheet); + } +} diff --git a/test/jaxp/javax/xml/jaxp/unittest/transform/BCELHashCodeTest.xsl b/test/jaxp/javax/xml/jaxp/unittest/transform/BCELHashCodeTest.xsl new file mode 100644 index 00000000000..a6f37e14db2 --- /dev/null +++ b/test/jaxp/javax/xml/jaxp/unittest/transform/BCELHashCodeTest.xsl @@ -0,0 +1,2160 @@ + + +en +GB + + +null +file:. +true +null + + + + + + + + +27.94cm +29.7cm + + + + +21.59cm +21cm + + + + + + + + + + + +2.3cm +2.0cm + + +2.0cm + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +