You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by gg...@apache.org on 2024/01/06 20:34:07 UTC
(commons-bcel) 01/02: Sort members
This is an automated email from the ASF dual-hosted git repository.
ggregory pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/commons-bcel.git
commit e5111d66561b11a726b7a37911bcac3bcfb65a81
Author: Gary Gregory <ga...@gmail.com>
AuthorDate: Sat Jan 6 15:33:35 2024 -0500
Sort members
---
.../org/apache/bcel/classfile/ConstantUtf8.java | 10 ++--
.../apache/bcel/verifier/JiraBcel370TestCase.java | 22 +++----
.../verifier/statics/Pass3aVerifierTestCase.java | 68 +++++++++++-----------
.../structurals/InstConstraintVisitorTestCase.java | 10 ++--
4 files changed, 55 insertions(+), 55 deletions(-)
diff --git a/src/main/java/org/apache/bcel/classfile/ConstantUtf8.java b/src/main/java/org/apache/bcel/classfile/ConstantUtf8.java
index edbdfef8..7ac35fb5 100644
--- a/src/main/java/org/apache/bcel/classfile/ConstantUtf8.java
+++ b/src/main/java/org/apache/bcel/classfile/ConstantUtf8.java
@@ -112,6 +112,11 @@ public final class ConstantUtf8 extends Constant {
hits = considered = skipped = created = 0;
}
+ // Avoid Spotbugs complaint about Write to static field
+ private static void countCreated() {
+ created++;
+ }
+
/**
* Gets a new or cached instance of the given value.
* <p>
@@ -178,11 +183,6 @@ public final class ConstantUtf8 extends Constant {
Cache.MAX_ENTRY_SIZE);
}
- // Avoid Spotbugs complaint about Write to static field
- private static void countCreated() {
- created++;
- }
-
private final String value;
/**
diff --git a/src/test/java/org/apache/bcel/verifier/JiraBcel370TestCase.java b/src/test/java/org/apache/bcel/verifier/JiraBcel370TestCase.java
index ac9e09e4..659a9abe 100644
--- a/src/test/java/org/apache/bcel/verifier/JiraBcel370TestCase.java
+++ b/src/test/java/org/apache/bcel/verifier/JiraBcel370TestCase.java
@@ -36,17 +36,6 @@ import org.junit.jupiter.params.provider.ValueSource;
* Tests BCEL-370.
*/
public class JiraBcel370TestCase extends AbstractTestCase {
- @ParameterizedTest
- @ValueSource(strings = {
- // @formatter:off
- "com.foo.Foo"
- })
- // @formatter:on
- 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);
- }
-
@ParameterizedTest
@ValueSource(strings = {
// @formatter:off
@@ -76,4 +65,15 @@ public class JiraBcel370TestCase extends AbstractTestCase {
});
}
}
+
+ @ParameterizedTest
+ @ValueSource(strings = {
+ // @formatter:off
+ "com.foo.Foo"
+ })
+ // @formatter:on
+ 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 7128b235..7cda6a87 100644
--- a/src/test/java/org/apache/bcel/verifier/statics/Pass3aVerifierTestCase.java
+++ b/src/test/java/org/apache/bcel/verifier/statics/Pass3aVerifierTestCase.java
@@ -54,40 +54,6 @@ import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.MethodSource;
class Pass3aVerifierTestCase {
- private Verifier verifier;
- private org.apache.bcel.util.Repository repository;
- private ConstantPool cp;
- private JavaClass javaClass;
-
- @BeforeEach
- void setup() throws ClassNotFoundException {
- 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);
- }
-
- @AfterAll
- public static void restoreRepository() {
- // We have set our mock repository, revert the change
- Repository.setRepository(SyntheticRepository.getInstance());
- }
-
public static Stream<Constant> constantsNotSupportedByLdc() {
return Stream.of(
new ConstantFieldref(0, 0),
@@ -104,6 +70,17 @@ class Pass3aVerifierTestCase {
new ConstantUtf8("constant")
);
}
+ @AfterAll
+ public static void restoreRepository() {
+ // 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")
@@ -131,5 +108,28 @@ class Pass3aVerifierTestCase {
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 {
+ 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 7b12a62b..3ebc5e29 100644
--- a/src/test/java/org/apache/bcel/verifier/structurals/InstConstraintVisitorTestCase.java
+++ b/src/test/java/org/apache/bcel/verifier/structurals/InstConstraintVisitorTestCase.java
@@ -30,11 +30,6 @@ import org.junit.jupiter.params.provider.MethodSource;
public class InstConstraintVisitorTestCase {
private ConstantPoolGen cp;
- @BeforeEach
- public void setup() {
- cp = mock(ConstantPoolGen.class);
- }
-
@ParameterizedTest
@MethodSource("org.apache.bcel.verifier.statics.Pass3aVerifierTestCase#constantsNotSupportedByLdc")
public void rejectLdcConstantModule(Constant constant) {
@@ -49,4 +44,9 @@ public class InstConstraintVisitorTestCase {
assertThatCode(() -> visitor.visitLDC(ldc)).hasMessageStartingWith("Instruction LDC constraint violated: Referenced constant should be a");
}
+
+ @BeforeEach
+ public void setup() {
+ cp = mock(ConstantPoolGen.class);
+ }
}