This is an automated email from the ASF dual-hosted git repository. garydgregory pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/commons-bcel.git
commit 8ffd9176429a31b76fddb4824ffd6341a8f53cbf Author: Gary Gregory <[email protected]> AuthorDate: Thu Nov 19 11:26:52 2026 -0500 Sort members --- .../structurals/InstConstraintVisitor.java | 62 +++++++++++----------- .../apache/bcel/generic/JdkGenericDumpTest.java | 6 +-- .../apache/bcel/verifier/VerifierInvokeTest.java | 44 +++++++-------- 3 files changed, 56 insertions(+), 56 deletions(-) diff --git a/src/main/java/org/apache/bcel/verifier/structurals/InstConstraintVisitor.java b/src/main/java/org/apache/bcel/verifier/structurals/InstConstraintVisitor.java index 7ffd865d..462522aa 100644 --- a/src/main/java/org/apache/bcel/verifier/structurals/InstConstraintVisitor.java +++ b/src/main/java/org/apache/bcel/verifier/structurals/InstConstraintVisitor.java @@ -344,6 +344,22 @@ public class InstConstraintVisitor extends EmptyVisitor { return frame.getLocals(); } + /** + * Ensures an initialized object reference is assignment compatible with the class named by a GETFIELD or PUTFIELD field reference. + * + * <p> + * The null type is permitted because dereferencing null fails at execution time, not during verification. The caller checks for disallowed reference types. + * </p> + */ + private void objectrefIsInstanceOfFieldClass(final FieldInstruction o, final Type objectref) throws ClassNotFoundException { + if (objectref instanceof ObjectType) { + final String theClass = getObjectType(o).getClassName(); + if (!Repository.instanceOf(((ObjectType) objectref).getClassName(), theClass)) { + constraintViolated(o, "The 'objectref' item '" + objectref + "' is not an instance of '" + theClass + "' as expected."); + } + } + } + /** * Assures the ReferenceType r is initialized (or Type.NULL). Formally, this means (!(r instanceof * UninitializedObjectType)), because there are no uninitialized array types. @@ -378,6 +394,11 @@ public class InstConstraintVisitor extends EmptyVisitor { // throw new AssertionViolatedException("Forgot to set important values first."); } + /* + * "generic"visitXXXX methods where XXXX is an interface therefore, we don't know the order of visiting; but we know these methods are called before the + * visitYYYY methods below + */ + /** * Sets the MethodGen instance needed for constraint checking prior to execution. * @@ -387,11 +408,6 @@ public class InstConstraintVisitor extends EmptyVisitor { this.mg = mg; } - /* - * "generic"visitXXXX methods where XXXX is an interface therefore, we don't know the order of visiting; but we know these methods are called before the - * visitYYYY methods below - */ - /** * The OperandStack we're working on. * @@ -522,6 +538,10 @@ public class InstConstraintVisitor extends EmptyVisitor { // } } + /* + /* "special"visitXXXX methods for one type of instruction each. + */ + /** * Ensures the specific preconditions of the said instruction. */ @@ -549,10 +569,6 @@ public class InstConstraintVisitor extends EmptyVisitor { } } - /* - /* "special"visitXXXX methods for one type of instruction each. - */ - /** * Ensures the specific preconditions of the said instruction. */ @@ -603,6 +619,12 @@ public class InstConstraintVisitor extends EmptyVisitor { throw new AssertionViolatedException("This JustIce verification pass should not encounter an illegal instruction such as BREAKPOINT."); } + /* + * "generic" visitYYYY methods where YYYY is a superclass. + * therefore, we know the order of visiting; we know + * these methods are called after the visitXXXX methods above. + */ + /** * Ensures the specific preconditions of the said instruction. */ @@ -617,12 +639,6 @@ public class InstConstraintVisitor extends EmptyVisitor { } } - /* - * "generic" visitYYYY methods where YYYY is a superclass. - * therefore, we know the order of visiting; we know - * these methods are called after the visitXXXX methods above. - */ - /** * Ensures the specific preconditions of the said instruction. */ @@ -1046,22 +1062,6 @@ public class InstConstraintVisitor extends EmptyVisitor { } } - /** - * Ensures an initialized object reference is assignment compatible with the class named by a GETFIELD or PUTFIELD field reference. - * - * <p> - * The null type is permitted because dereferencing null fails at execution time, not during verification. The caller checks for disallowed reference types. - * </p> - */ - private void objectrefIsInstanceOfFieldClass(final FieldInstruction o, final Type objectref) throws ClassNotFoundException { - if (objectref instanceof ObjectType) { - final String theClass = getObjectType(o).getClassName(); - if (!Repository.instanceOf(((ObjectType) objectref).getClassName(), theClass)) { - constraintViolated(o, "The 'objectref' item '" + objectref + "' is not an instance of '" + theClass + "' as expected."); - } - } - } - private Field visitFieldInstructionInternals(final FieldInstruction o) throws ClassNotFoundException { final String fieldName = o.getFieldName(cpg); final JavaClass jc = Repository.lookupClass(getObjectType(o).getClassName()); diff --git a/src/test/java/org/apache/bcel/generic/JdkGenericDumpTest.java b/src/test/java/org/apache/bcel/generic/JdkGenericDumpTest.java index 7a3c81a6..7c135163 100644 --- a/src/test/java/org/apache/bcel/generic/JdkGenericDumpTest.java +++ b/src/test/java/org/apache/bcel/generic/JdkGenericDumpTest.java @@ -78,9 +78,6 @@ import org.junit.jupiter.params.provider.MethodSource; */ class JdkGenericDumpTest { - private static final boolean PRINT_CLASS_NAME = Boolean.getBoolean("bcel.print.ClassNames"); - private static final boolean PRINT_JAR_NAME = Boolean.getBoolean("bcel.print.JarNames"); - private static class ClassParserFilesVisitor extends SimpleFileVisitor<Path> { private final PathMatcher matcher; @@ -118,6 +115,9 @@ class JdkGenericDumpTest { return FileVisitResult.CONTINUE; } } + private static final boolean PRINT_CLASS_NAME = Boolean.getBoolean("bcel.print.ClassNames"); + + private static final boolean PRINT_JAR_NAME = Boolean.getBoolean("bcel.print.JarNames"); private static final char[] hexArray = "0123456789ABCDEF".toCharArray(); diff --git a/src/test/java/org/apache/bcel/verifier/VerifierInvokeTest.java b/src/test/java/org/apache/bcel/verifier/VerifierInvokeTest.java index 18243065..73d9ec61 100644 --- a/src/test/java/org/apache/bcel/verifier/VerifierInvokeTest.java +++ b/src/test/java/org/apache/bcel/verifier/VerifierInvokeTest.java @@ -77,6 +77,28 @@ class VerifierInvokeTest extends AbstractVerifierTest { } } + @Test + void testLegalInvokeInterface() throws ClassNotFoundException { + assertVerifyOK("TestLegalInvokeInterface01", "Verification of invokeinterface on a method defined in a superinterface must pass."); + } + + @Test + void testLegalInvokeSpecial() throws ClassNotFoundException { + assertVerifyOK("TestLegalInvokeSpecial01", "Verification of invokespecial on a method defined in a superclass must pass."); + assertVerifyOK("TestLegalInvokeSpecial02", "Verification of invokespecial on a method defined in a superclass must pass."); + } + + @Test + void testLegalInvokeStatic() throws ClassNotFoundException { + assertVerifyOK("TestLegalInvokeStatic01", "Verification of invokestatic on a method defined in a superclass must pass."); + } + + @Test + void testLegalInvokeVirtual() throws ClassNotFoundException { + assertVerifyOK("TestLegalInvokeVirtual01", "Verification of invokevirtual on a method defined in a superclass must pass."); + assertVerifyOK("TestLegalInvokeVirtual02", "Verification of invokevirtual on a method defined in a superinterface must pass."); + } + @Test void testMethodHandleSignatures() throws ClassNotFoundException { for (final String name : new String[] { "invoke", "invokeExact" }) { @@ -102,26 +124,4 @@ class VerifierInvokeTest extends AbstractVerifierTest { assertInvokeVirtual("java.lang.invoke.VarHandle", "compareAndSet", Type.BOOLEAN, new Type[] { Type.OBJECT, Type.INT, Type.INT }, true); assertInvokeVirtual("java.lang.invoke.VarHandle", "toString", Type.INT, Type.NO_ARGS, false); } - - @Test - void testLegalInvokeInterface() throws ClassNotFoundException { - assertVerifyOK("TestLegalInvokeInterface01", "Verification of invokeinterface on a method defined in a superinterface must pass."); - } - - @Test - void testLegalInvokeSpecial() throws ClassNotFoundException { - assertVerifyOK("TestLegalInvokeSpecial01", "Verification of invokespecial on a method defined in a superclass must pass."); - assertVerifyOK("TestLegalInvokeSpecial02", "Verification of invokespecial on a method defined in a superclass must pass."); - } - - @Test - void testLegalInvokeStatic() throws ClassNotFoundException { - assertVerifyOK("TestLegalInvokeStatic01", "Verification of invokestatic on a method defined in a superclass must pass."); - } - - @Test - void testLegalInvokeVirtual() throws ClassNotFoundException { - assertVerifyOK("TestLegalInvokeVirtual01", "Verification of invokevirtual on a method defined in a superclass must pass."); - assertVerifyOK("TestLegalInvokeVirtual02", "Verification of invokevirtual on a method defined in a superinterface must pass."); - } }
