From f3bcd0a7e163813436472b9cfd2f6e3cf0243486 Mon Sep 17 00:00:00 2001 From: Gary Gregory Date: Sat, 6 Jan 2024 15:37:21 -0500 Subject: [PATCH] Revert "Remove trailing whitespace" This reverts commit da48305845cf112c914fe0993c76fcc8ef43fef3. --- .../org/apache/bcel/classfile/Visitor.java | 2 +- .../ConstantPoolModuleToStringTestCase.java | 2 +- .../bcel/classfile/ConstantPoolTestCase.java | 4 +- .../bcel/classfile/UtilityTestCase.java | 2 +- src/test/java/org/apache/bcel/data/SWAP.java | 2 +- .../org/apache/bcel/generic/JavaHome.java | 2 +- .../org/apache/bcel/generic/TypeTestCase.java | 2 +- .../apache/bcel/util/BCELifierTestCase.java | 2 +- .../bcel/verifier/JiraBcel369TestCase.java | 2 +- .../bcel/verifier/JiraBcel370TestCase.java | 20 ++++----- .../statics/Pass3aVerifierTestCase.java | 44 +++++++++---------- .../InstConstraintVisitorTestCase.java | 18 ++++---- 12 files changed, 51 insertions(+), 51 deletions(-) diff --git a/src/main/java/org/apache/bcel/classfile/Visitor.java b/src/main/java/org/apache/bcel/classfile/Visitor.java index 4f4b5c2116..9a3388cf0d 100644 --- a/src/main/java/org/apache/bcel/classfile/Visitor.java +++ b/src/main/java/org/apache/bcel/classfile/Visitor.java @@ -230,7 +230,7 @@ default void visitNestMembers(final NestMembers obj) { * @param obj object to visit * @since 6.8.0 */ - default void visitStackMapType(final StackMapType obj) { + default void visitStackMapType(StackMapType obj) { // empty } diff --git a/src/test/java/org/apache/bcel/classfile/ConstantPoolModuleToStringTestCase.java b/src/test/java/org/apache/bcel/classfile/ConstantPoolModuleToStringTestCase.java index e7f08c96eb..8048b705cb 100644 --- a/src/test/java/org/apache/bcel/classfile/ConstantPoolModuleToStringTestCase.java +++ b/src/test/java/org/apache/bcel/classfile/ConstantPoolModuleToStringTestCase.java @@ -385,7 +385,7 @@ public void visitModuleRequires(final ModuleRequires constantModule) { append(constantModule); append(constantModule.toString(pool)); final String s = constantModule.toString(pool).trim(); - final boolean condition = StringUtils.startsWithAny(s, + boolean condition = StringUtils.startsWithAny(s, "jdk.", "java.", "org.junit", diff --git a/src/test/java/org/apache/bcel/classfile/ConstantPoolTestCase.java b/src/test/java/org/apache/bcel/classfile/ConstantPoolTestCase.java index 3454a1a8ee..3c154facb1 100644 --- a/src/test/java/org/apache/bcel/classfile/ConstantPoolTestCase.java +++ b/src/test/java/org/apache/bcel/classfile/ConstantPoolTestCase.java @@ -66,7 +66,7 @@ public void testClassWithDoubleConstantPoolItem() throws ClassNotFoundException, // Next constant pool entry will be invalid so skip it i++; } - } catch (final Throwable t) { + } catch (Throwable t) { t.printStackTrace(); fail(); } @@ -92,7 +92,7 @@ public void testClassWithLongConstantPoolItem() throws ClassNotFoundException, I // Next constant pool entry will be invalid so skip it i++; } - } catch (final Throwable t) { + } catch (Throwable t) { t.printStackTrace(); fail(); } diff --git a/src/test/java/org/apache/bcel/classfile/UtilityTestCase.java b/src/test/java/org/apache/bcel/classfile/UtilityTestCase.java index 54561d4cb3..8c3144b66e 100644 --- a/src/test/java/org/apache/bcel/classfile/UtilityTestCase.java +++ b/src/test/java/org/apache/bcel/classfile/UtilityTestCase.java @@ -44,7 +44,7 @@ public void testClearBit() { @Test public void testCodeToString() throws Exception { final class CodeToString { - int[][] a = {}; + int[][] a = new int[0][0]; CodeToString() { if (a instanceof int[][]) { diff --git a/src/test/java/org/apache/bcel/data/SWAP.java b/src/test/java/org/apache/bcel/data/SWAP.java index ce1e29a2bf..81a291e24b 100644 --- a/src/test/java/org/apache/bcel/data/SWAP.java +++ b/src/test/java/org/apache/bcel/data/SWAP.java @@ -32,6 +32,6 @@ public static Constructor getTestConstructor(final Class theClass) throws NoSuch return theClass.getConstructor(args); } catch (final NoSuchMethodException e) { } - return theClass.getConstructor(); + return theClass.getConstructor(new Class[0]); } } diff --git a/src/test/java/org/apache/bcel/generic/JavaHome.java b/src/test/java/org/apache/bcel/generic/JavaHome.java index f23be5537a..e4d04d45ba 100644 --- a/src/test/java/org/apache/bcel/generic/JavaHome.java +++ b/src/test/java/org/apache/bcel/generic/JavaHome.java @@ -68,7 +68,7 @@ public class JavaHome { private static Stream find(final Path start, final int maxDepth, final BiPredicate matcher, final FileVisitOption... options) { - // TODO Apache Commons 2.14.0: Use FilesUncheck + // TODO Apache Commons 2.14.0: Use FilesUncheck return Files.exists(start) ? Uncheck.apply(Files::find, start, maxDepth, matcher, options) : Stream.empty(); } diff --git a/src/test/java/org/apache/bcel/generic/TypeTestCase.java b/src/test/java/org/apache/bcel/generic/TypeTestCase.java index 303a75ba4c..8378058990 100644 --- a/src/test/java/org/apache/bcel/generic/TypeTestCase.java +++ b/src/test/java/org/apache/bcel/generic/TypeTestCase.java @@ -91,7 +91,7 @@ public void testLDC(final String className) throws Exception { for (final InstructionHandle instructionHandle : instructionList) { instructionHandle.accept(new EmptyVisitor() { @Override - public void visitLDC(final LDC obj) { + public void visitLDC(LDC obj) { assertNotNull(obj.getValue(cpg)); } }); diff --git a/src/test/java/org/apache/bcel/util/BCELifierTestCase.java b/src/test/java/org/apache/bcel/util/BCELifierTestCase.java index 8ab68d6c6d..1cdeff2d9d 100644 --- a/src/test/java/org/apache/bcel/util/BCELifierTestCase.java +++ b/src/test/java/org/apache/bcel/util/BCELifierTestCase.java @@ -174,7 +174,7 @@ public void testHelloWorld() throws Exception { /* * Dumps a class using "javap" and compare with the same class recreated using BCELifier, "javac", "java" and dumped with "javap". - * + * * TODO: detect if JDK present and skip test if not */ @ParameterizedTest diff --git a/src/test/java/org/apache/bcel/verifier/JiraBcel369TestCase.java b/src/test/java/org/apache/bcel/verifier/JiraBcel369TestCase.java index 5a8502d173..bfd84f28ce 100644 --- a/src/test/java/org/apache/bcel/verifier/JiraBcel369TestCase.java +++ b/src/test/java/org/apache/bcel/verifier/JiraBcel369TestCase.java @@ -109,7 +109,7 @@ public void testCompileAndVerify() throws ClassNotFoundException { at org.apache.bcel.verifier.structurals.Pass3bVerifier.do_verify(Pass3bVerifier.java:386) ... 74 more * } - * + * * @throws ClassNotFoundException */ @Test diff --git a/src/test/java/org/apache/bcel/verifier/JiraBcel370TestCase.java b/src/test/java/org/apache/bcel/verifier/JiraBcel370TestCase.java index a92a92240f..659a9abe25 100644 --- a/src/test/java/org/apache/bcel/verifier/JiraBcel370TestCase.java +++ b/src/test/java/org/apache/bcel/verifier/JiraBcel370TestCase.java @@ -46,19 +46,19 @@ public class JiraBcel370TestCase extends AbstractTestCase { public void testLdcGetType(final String classFileName) throws Exception { try (FileInputStream file = new FileInputStream(classFileName)) { final ClassParser parser = new ClassParser(file, new File(classFileName).getName()); - final JavaClass clazz = parser.parse(); - - final Method[] methods = clazz.getMethods(); - - final ConstantPoolGen cp = new ConstantPoolGen(clazz.getConstantPool()); - final MethodGen methodGen = new MethodGen(methods[0], classFileName, cp); - + JavaClass clazz = parser.parse(); + + Method[] methods = clazz.getMethods(); + + ConstantPoolGen cp = new ConstantPoolGen(clazz.getConstantPool()); + MethodGen methodGen = new MethodGen(methods[0], classFileName, cp); + // The first instruction is an LDC CONSTANT_Dynamic added by Jacoco - final Instruction instruction = methodGen.getInstructionList().getInstructions()[0]; + Instruction instruction = methodGen.getInstructionList().getInstructions()[0]; instruction.accept(new EmptyVisitor() { @Override - public void visitLDC(final LDC ldc) { + public void visitLDC(LDC ldc) { // Without the change to LDC.getType() this fails because the tag is CONSTANT_Dynamic ldc.getType(cp); } @@ -72,7 +72,7 @@ public void visitLDC(final LDC ldc) { "com.foo.Foo" }) // @formatter:on - public void testVerify(final String className) throws ClassNotFoundException { + public void testVerify(String className) throws ClassNotFoundException { // Without the changes to the verifier this fails because it doesn't allow LDC CONSTANT_Dynamic Verifier.verifyType(className); } diff --git a/src/test/java/org/apache/bcel/verifier/statics/Pass3aVerifierTestCase.java b/src/test/java/org/apache/bcel/verifier/statics/Pass3aVerifierTestCase.java index c368c392c4..7cda6a874f 100644 --- a/src/test/java/org/apache/bcel/verifier/statics/Pass3aVerifierTestCase.java +++ b/src/test/java/org/apache/bcel/verifier/statics/Pass3aVerifierTestCase.java @@ -72,62 +72,62 @@ public static Stream constantsNotSupportedByLdc() { } @AfterAll public static void restoreRepository() { - // We have set our mock repository, revert the change + // We have set our mock repository, revert the change Repository.setRepository(SyntheticRepository.getInstance()); } private Verifier verifier; private org.apache.bcel.util.Repository repository; private ConstantPool cp; - + private JavaClass javaClass; - + @ParameterizedTest @MethodSource("constantsNotSupportedByLdc") - public void rejectLdcConstant(final Constant constant) { + public void rejectLdcConstant(Constant constant) { // LDC the constant 0 and then return - final byte[] methodCode = { + byte[] methodCode = new byte[] { Const.LDC, 0, 0, (byte) Const.RETURN, }; - - final Code code = new Code(0, 0, 0, 0, methodCode, new CodeException[0], new Attribute[0], cp); + + Code code = new Code(0, 0, 0, 0, methodCode, new CodeException[0], new Attribute[0], cp); when(cp.getConstantPool()).thenReturn(new Constant[] {constant}); - - final Attribute[] attributes = {code}; - final Method method = new Method(0, 0, 0, attributes, cp); - + + Attribute[] attributes = new Attribute[] {code}; + Method method = new Method(0, 0, 0, attributes, cp); + when(javaClass.getMethods()).thenReturn(new Method[] {method}); - - final Pass3aVerifier pass3aVerifier = new Pass3aVerifier(verifier, 0); - final VerificationResult verificationResult = pass3aVerifier.do_verify(); - + + Pass3aVerifier pass3aVerifier = new Pass3aVerifier(verifier, 0); + VerificationResult verificationResult = pass3aVerifier.do_verify(); + assertThat(verificationResult.getStatus()).isEqualTo(VerificationResult.VERIFIED_REJECTED); assertThat(verificationResult.getMessage()).startsWith("Instruction ldc[18](2) 0 constraint violated: Operand of LDC"); } - + @BeforeEach void setup() throws ClassNotFoundException { - final String className = "org.apache.bcel.verifier.statics.Pass3aVerifierTestCase.foo"; - + String className = "org.apache.bcel.verifier.statics.Pass3aVerifierTestCase.foo"; + verifier = spy(VerifierFactory.getVerifier(className)); repository = mock(org.apache.bcel.util.Repository.class); cp = mock(ConstantPool.class); javaClass = mock(JavaClass.class); - + // Mock the verifier doReturn(VerificationResult.VR_OK).when(verifier).doPass2(); - + // Mock the repository Repository.setRepository(repository); when(repository.loadClass(className)).thenReturn(javaClass); - + // Mock the constant pool when(cp.getConstantPool()).thenReturn(new Constant[] {new ConstantModule(0)}); - + // Mock the java class when(javaClass.getConstantPool()).thenReturn(cp); } diff --git a/src/test/java/org/apache/bcel/verifier/structurals/InstConstraintVisitorTestCase.java b/src/test/java/org/apache/bcel/verifier/structurals/InstConstraintVisitorTestCase.java index 72d4c04b6e..3ebc5e29a7 100644 --- a/src/test/java/org/apache/bcel/verifier/structurals/InstConstraintVisitorTestCase.java +++ b/src/test/java/org/apache/bcel/verifier/structurals/InstConstraintVisitorTestCase.java @@ -29,22 +29,22 @@ public class InstConstraintVisitorTestCase { private ConstantPoolGen cp; - + @ParameterizedTest @MethodSource("org.apache.bcel.verifier.statics.Pass3aVerifierTestCase#constantsNotSupportedByLdc") - public void rejectLdcConstantModule(final Constant constant) { - final InstConstraintVisitor visitor = new InstConstraintVisitor(); - + public void rejectLdcConstantModule(Constant constant) { + InstConstraintVisitor visitor = new InstConstraintVisitor(); + cp = mock(ConstantPoolGen.class); when(cp.getConstant(0)).thenReturn(constant); - + visitor.setConstantPoolGen(cp); - - final LDC ldc = new LDC(0); - + + LDC ldc = new LDC(0); + assertThatCode(() -> visitor.visitLDC(ldc)).hasMessageStartingWith("Instruction LDC constraint violated: Referenced constant should be a"); } - + @BeforeEach public void setup() { cp = mock(ConstantPoolGen.class);