Skip to content

Commit

Permalink
Revert "Remove trailing whitespace"
Browse files Browse the repository at this point in the history
This reverts commit da48305.
  • Loading branch information
garydgregory committed Jan 6, 2024
1 parent f20946d commit f3bcd0a
Show file tree
Hide file tree
Showing 12 changed files with 51 additions and 51 deletions.
2 changes: 1 addition & 1 deletion src/main/java/org/apache/bcel/classfile/Visitor.java
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Expand All @@ -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();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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[][]) {
Expand Down
2 changes: 1 addition & 1 deletion src/test/java/org/apache/bcel/data/SWAP.java
Original file line number Diff line number Diff line change
Expand Up @@ -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]);
}
}
2 changes: 1 addition & 1 deletion src/test/java/org/apache/bcel/generic/JavaHome.java
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ public class JavaHome {

private static Stream<Path> find(final Path start, final int maxDepth, final BiPredicate<Path, BasicFileAttributes> 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();
}

Expand Down
2 changes: 1 addition & 1 deletion src/test/java/org/apache/bcel/generic/TypeTestCase.java
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}
});
Expand Down
2 changes: 1 addition & 1 deletion src/test/java/org/apache/bcel/util/BCELifierTestCase.java
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ public void testCompileAndVerify() throws ClassNotFoundException {
at org.apache.bcel.verifier.structurals.Pass3bVerifier.do_verify(Pass3bVerifier.java:386)
... 74 more
* }</pre>
*
*
* @throws ClassNotFoundException
*/
@Test
Expand Down
20 changes: 10 additions & 10 deletions src/test/java/org/apache/bcel/verifier/JiraBcel370TestCase.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand All @@ -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);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,62 +72,62 @@ public static Stream<Constant> 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);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit f3bcd0a

Please sign in to comment.