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 2022/11/06 18:49:59 UTC
[commons-bcel] branch master updated: code coverage and assertions, compile with parameters (#165)
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
The following commit(s) were added to refs/heads/master by this push:
new a082f8ad code coverage and assertions, compile with parameters (#165)
a082f8ad is described below
commit a082f8add4608a845a6761ef0cf3aa5dbf096a17
Author: nbauma109 <nb...@users.noreply.github.com>
AuthorDate: Sun Nov 6 19:49:53 2022 +0100
code coverage and assertions, compile with parameters (#165)
Co-authored-by: nbauma109 <nb...@github.com>
---
pom.xml | 2 +
.../org/apache/bcel/ElementValueGenTestCase.java | 2 +-
.../ConstantPoolModuleToStringTestCase.java | 168 +++++++++++++++++++--
.../bcel/classfile/ConstantPoolTestCase.java | 57 +++++--
.../apache/bcel/generic/EmptyVisitorTestCase.java | 82 ++++++++++
.../bcel/verifier/VerifierArrayAccessTestCase.java | 25 ++-
.../bcel/verifier/VerifierReturnTestCase.java | 30 +++-
.../verifier/tests/TestArrayAccess04Creator.java | 16 +-
.../tests/TestArrayAccess04DoubleCreator.java | 27 ++++
.../tests/TestArrayAccess04FloatCreator.java | 27 ++++
.../tests/TestArrayAccess04IntCreator.java | 27 ++++
.../tests/TestArrayAccess04LongCreator.java | 27 ++++
.../tests/TestArrayAccess04ShortCreator.java | 27 ++++
.../tests/TestArrayAccess04UnknownCreator.java | 27 ++++
.../verifier/tests/TestReturn03BooleanCreator.java | 27 ++++
.../verifier/tests/TestReturn03ByteCreator.java | 27 ++++
.../bcel/verifier/tests/TestReturn03Creator.java | 14 +-
.../verifier/tests/TestReturn03DoubleCreator.java | 27 ++++
.../verifier/tests/TestReturn03FloatCreator.java | 27 ++++
.../verifier/tests/TestReturn03IntCreator.java | 27 ++++
.../verifier/tests/TestReturn03LongCreator.java | 27 ++++
.../verifier/tests/TestReturn03ObjectCreator.java | 27 ++++
.../verifier/tests/TestReturn03ShortCreator.java | 27 ++++
.../verifier/tests/TestReturn03UnknownCreator.java | 27 ++++
24 files changed, 754 insertions(+), 47 deletions(-)
diff --git a/pom.xml b/pom.xml
index 24e1c510..aba9d6c1 100644
--- a/pom.xml
+++ b/pom.xml
@@ -268,6 +268,8 @@
<testExcludes>
<testExclude>**/*Benchmark*</testExclude>
</testExcludes>
+ <!-- MethodParameters attribute in class file -->
+ <parameters>true</parameters>
</configuration>
</plugin>
<plugin>
diff --git a/src/test/java/org/apache/bcel/ElementValueGenTestCase.java b/src/test/java/org/apache/bcel/ElementValueGenTestCase.java
index dbc7f1ab..a8f0d022 100644
--- a/src/test/java/org/apache/bcel/ElementValueGenTestCase.java
+++ b/src/test/java/org/apache/bcel/ElementValueGenTestCase.java
@@ -71,7 +71,7 @@ public class ElementValueGenTestCase extends AbstractTestCase {
public void testCreateByteElementValue() throws Exception {
final ClassGen cg = createClassGen("HelloWorld");
final ConstantPoolGen cp = cg.getConstantPool();
- final SimpleElementValueGen evg = new SimpleElementValueGen(ElementValueGen.PRIMITIVE_CHAR, cp, (byte) 'z');
+ final SimpleElementValueGen evg = new SimpleElementValueGen(ElementValueGen.PRIMITIVE_BYTE, cp, (byte) 'z');
// Creation of an element like that should leave a new entry in the
// cpool
final int idx = cp.lookupInteger((byte) 'z');
diff --git a/src/test/java/org/apache/bcel/classfile/ConstantPoolModuleToStringTestCase.java b/src/test/java/org/apache/bcel/classfile/ConstantPoolModuleToStringTestCase.java
index 2fba4444..d480d667 100644
--- a/src/test/java/org/apache/bcel/classfile/ConstantPoolModuleToStringTestCase.java
+++ b/src/test/java/org/apache/bcel/classfile/ConstantPoolModuleToStringTestCase.java
@@ -16,13 +16,23 @@
*/
package org.apache.bcel.classfile;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.junit.jupiter.api.Assertions.fail;
+import java.io.IOException;
import java.io.InputStream;
+import java.net.URL;
import java.nio.file.Files;
import java.nio.file.Paths;
+import java.util.Enumeration;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+import org.apache.bcel.util.SyntheticRepository;
+import org.apache.commons.lang3.StringUtils;
+import org.junit.jupiter.api.Test;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.ValueSource;
@@ -31,7 +41,7 @@ import org.junit.jupiter.params.provider.ValueSource;
*/
public class ConstantPoolModuleToStringTestCase {
- static class ToStringVisitor implements Visitor {
+ static class ToStringVisitor extends EmptyVisitor {
private final StringBuilder stringBuilder = new StringBuilder();
private final ConstantPool pool;
@@ -55,292 +65,386 @@ public class ConstantPoolModuleToStringTestCase {
@Override
public void visitAnnotation(final Annotations obj) {
+ super.visitAnnotation(obj);
append(obj);
}
@Override
public void visitAnnotationDefault(final AnnotationDefault obj) {
+ super.visitAnnotationDefault(obj);
append(obj);
}
@Override
public void visitAnnotationEntry(final AnnotationEntry obj) {
+ super.visitAnnotationEntry(obj);
append(obj);
}
@Override
public void visitBootstrapMethods(final BootstrapMethods obj) {
+ super.visitBootstrapMethods(obj);
append(obj);
}
@Override
public void visitCode(final Code obj) {
+ super.visitCode(obj);
append(obj.toString(true));
}
@Override
public void visitCodeException(final CodeException obj) {
+ super.visitCodeException(obj);
append(obj.toString(pool, true));
}
@Override
public void visitConstantClass(final ConstantClass obj) {
+ super.visitConstantClass(obj);
append(obj);
}
@Override
public void visitConstantDouble(final ConstantDouble obj) {
+ super.visitConstantDouble(obj);
append(obj);
}
@Override
public void visitConstantDynamic(final ConstantDynamic constantDynamic) {
+ super.visitConstantDynamic(constantDynamic);
append(constantDynamic);
}
@Override
public void visitConstantFieldref(final ConstantFieldref obj) {
+ super.visitConstantFieldref(obj);
append(obj);
}
@Override
public void visitConstantFloat(final ConstantFloat obj) {
+ super.visitConstantFloat(obj);
append(obj);
}
@Override
public void visitConstantInteger(final ConstantInteger obj) {
+ super.visitConstantInteger(obj);
append(obj);
}
@Override
public void visitConstantInterfaceMethodref(final ConstantInterfaceMethodref obj) {
+ super.visitConstantInterfaceMethodref(obj);
append(obj);
}
@Override
public void visitConstantInvokeDynamic(final ConstantInvokeDynamic obj) {
+ super.visitConstantInvokeDynamic(obj);
append(obj);
}
@Override
public void visitConstantLong(final ConstantLong obj) {
+ super.visitConstantLong(obj);
append(obj);
}
@Override
public void visitConstantMethodHandle(final ConstantMethodHandle obj) {
+ super.visitConstantMethodHandle(obj);
append(obj);
}
@Override
public void visitConstantMethodref(final ConstantMethodref obj) {
+ super.visitConstantMethodref(obj);
append(obj);
}
@Override
public void visitConstantMethodType(final ConstantMethodType obj) {
+ super.visitConstantMethodType(obj);
append(obj);
}
@Override
public void visitConstantModule(final ConstantModule constantModule) {
+ super.visitConstantModule(constantModule);
append(constantModule);
}
@Override
public void visitConstantNameAndType(final ConstantNameAndType obj) {
+ super.visitConstantNameAndType(obj);
append(obj);
}
@Override
public void visitConstantPackage(final ConstantPackage constantPackage) {
+ super.visitConstantPackage(constantPackage);
append(constantPackage);
}
@Override
public void visitConstantPool(final ConstantPool obj) {
+ super.visitConstantPool(obj);
append(obj);
}
@Override
public void visitConstantString(final ConstantString obj) {
+ super.visitConstantString(obj);
append(obj);
}
@Override
public void visitConstantUtf8(final ConstantUtf8 obj) {
+ super.visitConstantUtf8(obj);
append(obj);
}
@Override
public void visitConstantValue(final ConstantValue obj) {
+ super.visitConstantValue(obj);
append(obj);
}
@Override
public void visitDeprecated(final Deprecated obj) {
+ super.visitDeprecated(obj);
append(obj);
}
@Override
public void visitEnclosingMethod(final EnclosingMethod obj) {
+ super.visitEnclosingMethod(obj);
append(obj);
}
@Override
public void visitExceptionTable(final ExceptionTable obj) {
+ super.visitExceptionTable(obj);
append(obj);
}
@Override
public void visitField(final Field obj) {
+ super.visitField(obj);
append(obj);
}
@Override
public void visitInnerClass(final InnerClass obj) {
+ super.visitInnerClass(obj);
append(obj.toString(pool));
}
@Override
public void visitInnerClasses(final InnerClasses obj) {
+ super.visitInnerClasses(obj);
append(obj);
}
@Override
public void visitJavaClass(final JavaClass obj) {
+ super.visitJavaClass(obj);
append(obj);
}
@Override
public void visitLineNumber(final LineNumber obj) {
+ super.visitLineNumber(obj);
append(obj);
}
@Override
public void visitLineNumberTable(final LineNumberTable obj) {
+ super.visitLineNumberTable(obj);
append(obj);
}
@Override
public void visitLocalVariable(final LocalVariable obj) {
+ super.visitLocalVariable(obj);
append(obj);
}
@Override
public void visitLocalVariableTable(final LocalVariableTable obj) {
+ super.visitLocalVariableTable(obj);
append(obj);
}
@Override
public void visitLocalVariableTypeTable(final LocalVariableTypeTable obj) {
+ super.visitLocalVariableTypeTable(obj);
append(obj);
}
@Override
public void visitMethod(final Method obj) {
+ super.visitMethod(obj);
append(obj);
}
@Override
public void visitMethodParameter(final MethodParameter obj) {
+ super.visitMethodParameter(obj);
append(obj);
}
@Override
public void visitMethodParameters(final MethodParameters obj) {
+ super.visitMethodParameters(obj);
append(obj);
}
@Override
public void visitModule(final Module constantModule) {
+ super.visitModule(constantModule);
+ final String s = constantModule.toString();
+ final Matcher matcher = Pattern.compile(" (\\w+)([:(])").matcher(s);
+ while (matcher.find()) {
+ switch (matcher.group(2)) {
+ case ":":
+ assertTrue(StringUtils.containsAny(matcher.group(1), "name", "flags", "version"));
+ break;
+ case "(":
+ assertTrue(StringUtils.containsAny(matcher.group(1), "requires", "exports", "opens", "uses", "provides"));
+ break;
+ default:
+ break;
+ }
+ }
append(constantModule);
}
@Override
public void visitModuleExports(final ModuleExports constantModule) {
+ super.visitModuleExports(constantModule);
append(constantModule);
- append(constantModule.toString(pool));
+ final String s = constantModule.toString(pool);
+ final String[] tokens = s.split(", ");
+ assertNotNull(tokens);
+ assertEquals(3, tokens.length);
+ assertEquals("0000", tokens[1]);
+ final Matcher matcher = Pattern.compile("to\\((\\d+)\\):").matcher(tokens[2]);
+ assertTrue(matcher.find());
+ assertEquals(Integer.parseInt(matcher.group(1)), StringUtils.countMatches(s, '\n'));
}
@Override
public void visitModuleMainClass(final ModuleMainClass obj) {
+ super.visitModuleMainClass(obj);
append(obj);
}
@Override
public void visitModuleOpens(final ModuleOpens constantModule) {
+ super.visitModuleOpens(constantModule);
append(constantModule);
- append(constantModule.toString(pool));
+ final String s = constantModule.toString(pool);
+ final String[] tokens = s.split(", ");
+ assertNotNull(tokens);
+ assertEquals(3, tokens.length);
+ assertEquals("0000", tokens[1]);
+ final Matcher matcher = Pattern.compile("to\\((\\d+)\\):").matcher(tokens[2]);
+ assertTrue(matcher.find());
+ assertEquals(Integer.parseInt(matcher.group(1)), StringUtils.countMatches(s, '\n'));
}
@Override
public void visitModulePackages(final ModulePackages constantModule) {
+ super.visitModulePackages(constantModule);
append(constantModule);
+ final String s = constantModule.toString();
+ assertEquals(constantModule.getNumberOfPackages(), StringUtils.countMatches(s, '\n'));
}
@Override
public void visitModuleProvides(final ModuleProvides constantModule) {
+ super.visitModuleProvides(constantModule);
append(constantModule);
- append(constantModule.toString(pool));
+ final String s = constantModule.toString(pool);
+ final String[] tokens = s.split(", ");
+ assertNotNull(tokens);
+ assertEquals(2, tokens.length);
+ final Matcher matcher = Pattern.compile("with\\((\\d+)\\):").matcher(tokens[1]);
+ assertTrue(matcher.find());
+ assertEquals(Integer.parseInt(matcher.group(1)), StringUtils.countMatches(s, '\n'));
+ append(s);
}
@Override
public void visitModuleRequires(final ModuleRequires constantModule) {
+ super.visitModuleRequires(constantModule);
append(constantModule);
append(constantModule.toString(pool));
final String s = constantModule.toString(pool).trim();
- assertTrue(s.startsWith("java.base") || s.startsWith("Othermodularthing"), s);
+ assertTrue(StringUtils.startsWithAny(s, "jdk.", "java.", "org.junit", "org.apiguardian.api", "org.opentest4j"), s);
}
@Override
public void visitNestHost(final NestHost obj) {
+ super.visitNestHost(obj);
append(obj);
}
@Override
public void visitNestMembers(final NestMembers obj) {
+ super.visitNestMembers(obj);
append(obj);
}
@Override
public void visitParameterAnnotation(final ParameterAnnotations obj) {
+ super.visitParameterAnnotation(obj);
append(obj);
}
@Override
public void visitParameterAnnotationEntry(final ParameterAnnotationEntry obj) {
+ super.visitParameterAnnotationEntry(obj);
append(obj);
}
@Override
public void visitSignature(final Signature obj) {
+ super.visitSignature(obj);
append(obj);
}
@Override
public void visitSourceFile(final SourceFile obj) {
+ super.visitSourceFile(obj);
append(obj);
}
@Override
public void visitStackMap(final StackMap obj) {
+ super.visitStackMap(obj);
append(obj);
}
@Override
public void visitStackMapEntry(final StackMapEntry obj) {
+ super.visitStackMapEntry(obj);
append(obj);
}
@Override
public void visitSynthetic(final Synthetic obj) {
+ super.visitSynthetic(obj);
append(obj);
}
@Override
public void visitUnknown(final Unknown obj) {
+ super.visitUnknown(obj);
append(obj);
}
}
@@ -355,17 +459,53 @@ public class ConstantPoolModuleToStringTestCase {
// @formatter:on
public void test(final String first) throws Exception {
try (final InputStream inputStream = Files.newInputStream(Paths.get(first))) {
- final ClassParser classParser = new ClassParser(inputStream, "module-info.class");
- final JavaClass javaClass = classParser.parse();
- final ConstantPool constantPool = javaClass.getConstantPool();
- final ToStringVisitor visitor = new ToStringVisitor(constantPool);
- final DescendingVisitor descendingVisitor = new DescendingVisitor(javaClass, visitor);
- try {
- javaClass.accept(descendingVisitor);
- } catch (Exception | Error e) {
- fail(visitor.toString(), e);
+ test(inputStream);
+ }
+ }
+
+ @Test
+ public void test() throws Exception {
+ final Enumeration<URL> moduleURLs = getClass().getClassLoader().getResources("module-info.class");
+ while (moduleURLs.hasMoreElements()) {
+ final URL url = moduleURLs.nextElement();
+ try (InputStream inputStream = url.openStream()) {
+ test(inputStream);
}
}
}
+
+ @ParameterizedTest
+ @ValueSource(strings = {
+ // @formatter:off
+ "java.lang.CharSequence$1CharIterator", // contains attribute EnclosingMethod
+ "org.apache.commons.lang3.function.TriFunction", // contains attributes BootstrapMethods, InnerClasses, LineNumberTable, LocalVariableTable, LocalVariableTypeTable, RuntimeVisibleAnnotations, Signature, SourceFile
+ "org.apache.commons.lang3.math.NumberUtils", // contains attribute ConstantFloat, ConstantDouble
+ "org.apache.bcel.Const", // contains attributes MethodParameters
+ "java.io.StringBufferInputStream", // contains attributes Deprecated, StackMap
+ "java.nio.file.Files", // contains attributes ConstantValue, ExceptionTable, NestMembers
+ "org.junit.jupiter.api.AssertionsKt", // contains attribute ParameterAnnotation
+ "javax.annotation.ManagedBean", // contains attribute AnnotationDefault
+ "javax.management.remote.rmi.RMIConnectionImpl_Stub"}) // contains attribute Synthetic
+ // @formatter:on
+ public void testClass(final String className) throws Exception {
+ testJavaClass(SyntheticRepository.getInstance().loadClass(className));
+ }
+
+ private static void test(final InputStream inputStream) throws IOException {
+ final ClassParser classParser = new ClassParser(inputStream, "module-info.class");
+ final JavaClass javaClass = classParser.parse();
+ testJavaClass(javaClass);
+ }
+ private static void testJavaClass(final JavaClass javaClass) {
+ final ConstantPool constantPool = javaClass.getConstantPool();
+ final ToStringVisitor visitor = new ToStringVisitor(constantPool);
+ final DescendingVisitor descendingVisitor = new DescendingVisitor(javaClass, visitor);
+ try {
+ javaClass.accept(descendingVisitor);
+ assertNotNull(visitor.toString());
+ } catch (Exception | Error e) {
+ fail(visitor.toString(), e);
+ }
+ }
}
diff --git a/src/test/java/org/apache/bcel/classfile/ConstantPoolTestCase.java b/src/test/java/org/apache/bcel/classfile/ConstantPoolTestCase.java
index 8ee490c4..4b0bbf35 100644
--- a/src/test/java/org/apache/bcel/classfile/ConstantPoolTestCase.java
+++ b/src/test/java/org/apache/bcel/classfile/ConstantPoolTestCase.java
@@ -18,6 +18,7 @@
package org.apache.bcel.classfile;
import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
+import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertThrows;
@@ -43,7 +44,7 @@ class ClassWithLongConstantPoolItem {
public class ConstantPoolTestCase extends AbstractTestCase {
- private InstructionHandle[] getInstructionHandles(final JavaClass clazz, final ConstantPoolGen cp, final Method method) {
+ private static InstructionHandle[] getInstructionHandles(final JavaClass clazz, final ConstantPoolGen cp, final Method method) {
final MethodGen methodGen = new MethodGen(method, clazz.getClassName(), cp);
return methodGen.getInstructionList().getInstructionHandles();
}
@@ -56,31 +57,63 @@ public class ConstantPoolTestCase extends AbstractTestCase {
for (final Method method : methods) {
if (method.getName().equals("<init>")) {
for (final InstructionHandle instructionHandle : getInstructionHandles(clazz, cp, method)) {
- assertNotNull(instructionHandle.getInstruction().toString(cp.getConstantPool()));
- // TODO Need real assertions.
- // System.out.println(string);
+ final String instruction = instructionHandle.getInstruction().toString(cp.getConstantPool());
+ assertNotNull(instruction);
+ switch (instructionHandle.getPosition()) {
+ case 0:
+ assertEquals("aload_0", instruction);
+ break;
+ case 1:
+ assertEquals("invokespecial java/lang/Object/<init>()V", instruction);
+ break;
+ case 4:
+ assertEquals("return", instruction);
+ break;
+ default:
+ break;
+ }
}
}
}
}
@Test
- public void testDoubleConstantWontThrowClassFormatException() throws ClassNotFoundException, IOException {
+ public void testClassWithDoubleConstantPoolItem() throws ClassNotFoundException, IOException {
try (final ClassPath cp = new ClassPath("target/test-classes/org/apache/bcel/classfile")) {
- final JavaClass c = new ClassPathRepository(cp).loadClass("ClassWithDoubleConstantPoolItem");
-
+ final ClassWithDoubleConstantPoolItem classWithDoubleConstantPoolItem = new ClassWithDoubleConstantPoolItem();
+ final JavaClass c = new ClassPathRepository(cp).loadClass(classWithDoubleConstantPoolItem.getClass());
+ final Field[] fields = c.getFields();
+ assertNotNull(fields);
+ assertEquals(1, fields.length);
+ assertEquals(ClassWithDoubleConstantPoolItem.class.getDeclaredFields()[0].getName(), fields[0].getName());
final ConstantPool pool = c.getConstantPool();
- IntStream.range(0, pool.getLength()).forEach(i -> assertDoesNotThrow(() -> pool.getConstant(i)));
+ IntStream.range(0, pool.getLength()).forEach(i -> assertDoesNotThrow(() -> {
+ final Constant constant = pool.getConstant(i);
+ if (constant instanceof ConstantDouble) {
+ assertEquals(classWithDoubleConstantPoolItem.d, ((ConstantDouble) constant).getBytes());
+ }
+ return constant;
+ }));
}
}
@Test
- public void testLongConstantWontThrowClassFormatException() throws ClassNotFoundException, IOException {
+ public void testClassWithLongConstantPoolItem() throws ClassNotFoundException, IOException {
try (final ClassPath cp = new ClassPath("target/test-classes/org/apache/bcel/classfile")) {
- final JavaClass c = new ClassPathRepository(cp).loadClass("ClassWithLongConstantPoolItem");
-
+ final ClassWithLongConstantPoolItem classWithLongConstantPoolItem = new ClassWithLongConstantPoolItem();
+ final JavaClass c = new ClassPathRepository(cp).loadClass(classWithLongConstantPoolItem.getClass());
+ final Field[] fields = c.getFields();
+ assertNotNull(fields);
+ assertEquals(1, fields.length);
+ assertEquals(ClassWithLongConstantPoolItem.class.getDeclaredFields()[0].getName(), fields[0].getName());
final ConstantPool pool = c.getConstantPool();
- IntStream.range(0, pool.getLength()).forEach(i -> assertDoesNotThrow(() -> pool.getConstant(i)));
+ IntStream.range(0, pool.getLength()).forEach(i -> assertDoesNotThrow(() -> {
+ final Constant constant = pool.getConstant(i);
+ if (constant instanceof ConstantLong) {
+ assertEquals(classWithLongConstantPoolItem.l, ((ConstantLong) constant).getBytes());
+ }
+ return constant;
+ }));
}
}
diff --git a/src/test/java/org/apache/bcel/generic/EmptyVisitorTestCase.java b/src/test/java/org/apache/bcel/generic/EmptyVisitorTestCase.java
new file mode 100644
index 00000000..cf43293e
--- /dev/null
+++ b/src/test/java/org/apache/bcel/generic/EmptyVisitorTestCase.java
@@ -0,0 +1,82 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.bcel.generic;
+
+import static org.junit.jupiter.api.Assertions.fail;
+
+import org.apache.bcel.classfile.Code;
+import org.apache.bcel.classfile.JavaClass;
+import org.apache.bcel.classfile.Method;
+import org.apache.bcel.util.SyntheticRepository;
+import org.junit.jupiter.params.ParameterizedTest;
+import org.junit.jupiter.params.provider.ValueSource;
+
+class EmptyVisitorTestCase {
+
+ /*
+ * https://docs.oracle.com/javase/specs/jvms/se17/html/jvms-6.html#jvms-6.2
+ */
+ private static final String RESERVED_OPCODE = "Reserved opcode";
+
+ @ParameterizedTest
+ @ValueSource(strings = {
+ // @formatter:off
+ "java.math.BigInteger", // contains instructions [AALOAD, AASTORE, ACONST_NULL, ALOAD, ANEWARRAY, ARETURN, ARRAYLENGTH, ASTORE, ATHROW, BALOAD, BASTORE, BIPUSH, CALOAD, CHECKCAST, D2I, DADD, DALOAD, DASTORE, DCONST, DDIV, DMUL, DRETURN, DSUB, DUP, DUP2, DUP_X2, FCONST, FRETURN, GETFIELD, GETSTATIC, GOTO, I2B, I2D, I2L, IADD, IALOAD, IAND, IASTORE, ICONST, IDIV, IFEQ, IFGE, IFGT, IFLE, IFLT, IFNE, IFNONNULL, IFNULL, IF_ACMPNE, IF_ICMPEQ, IF_ICMPGE, IF_ICMP [...]
+ "java.math.BigDecimal", // contains instructions [CASTORE, D2L, DLOAD, FALOAD, FASTORE, FDIV, FMUL, I2S, IF_ACMPEQ, LXOR, MONITORENTER, MONITOREXIT, TABLESWITCH]
+ "java.awt.Color", // contains instructions [D2F, DCMPG, DCMPL, F2D, F2I, FADD, FCMPG, FCMPL, FLOAD, FSTORE, FSUB, I2F, INVOKEDYNAMIC]
+ "java.util.Map", // contains instruction INVOKEINTERFACE
+ "java.io.Bits", // contains instruction I2C
+ "java.io.BufferedInputStream", // contains instruction DUP_X1
+ "java.io.StreamTokenizer", // contains instruction DNEG, DSTORE
+ "java.lang.Float", // contains instruction F2L
+ "java.lang.invoke.LambdaForm", // contains instruction MULTIANEWARRAY,
+ "java.nio.Bits", // contains instruction POP2,
+ "java.nio.HeapShortBuffer", // contains instruction SALOAD, SASTORE
+ "java.awt.GradientPaintContext", // contains instruction DREM
+ "java.util.concurrent.atomic.DoubleAccumulator", // contains instruction DUP2_X1
+ "java.util.Hashtable", // contains instruction FNEG
+ "javax.swing.text.html.CSS" // contains instruction DUP2_X2
+ // @formatter:on
+ })
+ public void test(final String className) throws ClassNotFoundException {
+ final JavaClass javaClass = SyntheticRepository.getInstance().loadClass(className);
+ for (final Method method : javaClass.getMethods()) {
+ final Code code = method.getCode();
+ if (code != null) {
+ final InstructionList instructionList = new InstructionList(code.getCode());
+ for (final InstructionHandle instructionHandle : instructionList) {
+ instructionHandle.accept(new EmptyVisitor() {
+ @Override
+ public void visitIMPDEP1(final IMPDEP1 obj) {
+ fail(RESERVED_OPCODE);
+ }
+
+ @Override
+ public void visitIMPDEP2(final IMPDEP2 obj) {
+ fail(RESERVED_OPCODE);
+ }
+
+ @Override
+ public void visitBREAKPOINT(final BREAKPOINT obj) {
+ fail(RESERVED_OPCODE);
+ }
+ });
+ }
+ }
+ }
+ }
+}
diff --git a/src/test/java/org/apache/bcel/verifier/VerifierArrayAccessTestCase.java b/src/test/java/org/apache/bcel/verifier/VerifierArrayAccessTestCase.java
index eea59268..79bcb21b 100644
--- a/src/test/java/org/apache/bcel/verifier/VerifierArrayAccessTestCase.java
+++ b/src/test/java/org/apache/bcel/verifier/VerifierArrayAccessTestCase.java
@@ -18,20 +18,35 @@
package org.apache.bcel.verifier;
import java.io.IOException;
-
import org.apache.bcel.verifier.tests.TestArrayAccess02Creator;
import org.apache.bcel.verifier.tests.TestArrayAccess03Creator;
-import org.apache.bcel.verifier.tests.TestArrayAccess04Creator;
+import org.apache.bcel.verifier.tests.TestArrayAccess04DoubleCreator;
+import org.apache.bcel.verifier.tests.TestArrayAccess04FloatCreator;
+import org.apache.bcel.verifier.tests.TestArrayAccess04IntCreator;
+import org.apache.bcel.verifier.tests.TestArrayAccess04LongCreator;
+import org.apache.bcel.verifier.tests.TestArrayAccess04UnknownCreator;
+import org.apache.bcel.verifier.tests.TestArrayAccess04ShortCreator;
+import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
-public class VerifierArrayAccessTestCase extends AbstractVerifierTestCase {
+class VerifierArrayAccessTestCase extends AbstractVerifierTestCase {
@Test
public void testInvalidArrayAccess() throws IOException, ClassNotFoundException {
new TestArrayAccess03Creator().create();
assertVerifyRejected("TestArrayAccess03", "Verification of an arraystore instruction on an object must fail.");
- new TestArrayAccess04Creator().create();
- assertVerifyRejected("TestArrayAccess04", "Verification of an arraystore instruction of an int on an array of references must fail.");
+ new TestArrayAccess04IntCreator().create();
+ assertVerifyRejected("TestArrayAccess04Int", "Verification of an arraystore instruction of an int on an array of references must fail.");
+ new TestArrayAccess04FloatCreator().create();
+ assertVerifyRejected("TestArrayAccess04Float", "Verification of an arraystore instruction of a float on an array of references must fail.");
+ new TestArrayAccess04DoubleCreator().create();
+ assertVerifyRejected("TestArrayAccess04Double", "Verification of an arraystore instruction of a double on an array of references must fail.");
+ new TestArrayAccess04LongCreator().create();
+ assertVerifyRejected("TestArrayAccess04Long", "Verification of an arraystore instruction of a long on an array of references must fail.");
+ new TestArrayAccess04ShortCreator().create();
+ assertVerifyRejected("TestArrayAccess04Short", "Verification of an arraystore instruction of a short on an array of references must fail.");
+ final TestArrayAccess04UnknownCreator testArrayAccess04UnknownCreator = new TestArrayAccess04UnknownCreator();
+ Assertions.assertThrowsExactly(IllegalArgumentException.class, testArrayAccess04UnknownCreator::create, "Invalid type <unknown object>");
}
@Test
diff --git a/src/test/java/org/apache/bcel/verifier/VerifierReturnTestCase.java b/src/test/java/org/apache/bcel/verifier/VerifierReturnTestCase.java
index d21a55cf..692c73a0 100644
--- a/src/test/java/org/apache/bcel/verifier/VerifierReturnTestCase.java
+++ b/src/test/java/org/apache/bcel/verifier/VerifierReturnTestCase.java
@@ -20,17 +20,39 @@ package org.apache.bcel.verifier;
import java.io.IOException;
import org.apache.bcel.verifier.tests.TestReturn01Creator;
-import org.apache.bcel.verifier.tests.TestReturn03Creator;
+import org.apache.bcel.verifier.tests.TestReturn03BooleanCreator;
+import org.apache.bcel.verifier.tests.TestReturn03ByteCreator;
+import org.apache.bcel.verifier.tests.TestReturn03DoubleCreator;
+import org.apache.bcel.verifier.tests.TestReturn03FloatCreator;
+import org.apache.bcel.verifier.tests.TestReturn03IntCreator;
+import org.apache.bcel.verifier.tests.TestReturn03LongCreator;
+import org.apache.bcel.verifier.tests.TestReturn03ObjectCreator;
+import org.apache.bcel.verifier.tests.TestReturn03UnknownCreator;
+import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
-public class VerifierReturnTestCase extends AbstractVerifierTestCase {
+class VerifierReturnTestCase extends AbstractVerifierTestCase {
@Test
public void testInvalidReturn() throws IOException, ClassNotFoundException {
new TestReturn01Creator().create();
assertVerifyRejected("TestReturn01", "Verification of a void method that returns an object must fail.");
- new TestReturn03Creator().create();
- assertVerifyRejected("TestReturn03", "Verification of an int method that returns null must fail.");
+ new TestReturn03IntCreator().create();
+ assertVerifyRejected("TestReturn03Int", "Verification of an int method that returns null int must fail.");
+ new TestReturn03FloatCreator().create();
+ assertVerifyRejected("TestReturn03Float", "Verification of a int method that returns null float must fail.");
+ new TestReturn03DoubleCreator().create();
+ assertVerifyRejected("TestReturn03Double", "Verification of a int method that returns null double must fail.");
+ new TestReturn03LongCreator().create();
+ assertVerifyRejected("TestReturn03Long", "Verification of a int method that returns null long must fail.");
+ new TestReturn03ByteCreator().create();
+ assertVerifyRejected("TestReturn03Byte", "Verification of a int method that returns null byte must fail.");
+ new TestReturn03BooleanCreator().create();
+ assertVerifyRejected("TestReturn03Boolean", "Verification of a int method that returns null boolean must fail.");
+ new TestReturn03ObjectCreator().create();
+ assertVerifyRejected("TestReturn03Object", "Verification of a int method that returns null Object must fail.");
+ final TestReturn03UnknownCreator testReturn03UnknownCreator = new TestReturn03UnknownCreator();
+ Assertions.assertThrowsExactly(IllegalArgumentException.class, testReturn03UnknownCreator::create, "Invalid type <unknown object>");
}
@Test
diff --git a/src/test/java/org/apache/bcel/verifier/tests/TestArrayAccess04Creator.java b/src/test/java/org/apache/bcel/verifier/tests/TestArrayAccess04Creator.java
index 80f418d3..c02d6e98 100644
--- a/src/test/java/org/apache/bcel/verifier/tests/TestArrayAccess04Creator.java
+++ b/src/test/java/org/apache/bcel/verifier/tests/TestArrayAccess04Creator.java
@@ -33,17 +33,21 @@ import org.apache.bcel.generic.MethodGen;
import org.apache.bcel.generic.PUSH;
import org.apache.bcel.generic.Type;
-public class TestArrayAccess04Creator extends TestCreator {
+public abstract class TestArrayAccess04Creator extends TestCreator {
private final InstructionFactory _factory;
private final ConstantPoolGen _cp;
private final ClassGen _cg;
+ private final Type primitiveType;
+ private final String genClassSuffix;
- public TestArrayAccess04Creator() {
- _cg = new ClassGen(TEST_PACKAGE + ".TestArrayAccess04", "java.lang.Object", "TestArrayAccess04.java", Const.ACC_PUBLIC | Const.ACC_SUPER,
+ protected TestArrayAccess04Creator(final Type primitiveType, final String genClassSuffix) {
+ _cg = new ClassGen(TEST_PACKAGE + ".TestArrayAccess04" + genClassSuffix, "java.lang.Object", "TestArrayAccess04.java", Const.ACC_PUBLIC | Const.ACC_SUPER,
new String[] {});
_cp = _cg.getConstantPool();
_factory = new InstructionFactory(_cg, _cp);
+ this.primitiveType = primitiveType;
+ this.genClassSuffix = genClassSuffix;
}
@Override
@@ -72,7 +76,7 @@ public class TestArrayAccess04Creator extends TestCreator {
private void createMethod_1() {
final InstructionList il = new InstructionList();
final MethodGen method = new MethodGen(Const.ACC_PUBLIC | Const.ACC_STATIC, Type.VOID, new Type[] {Type.OBJECT}, new String[] {"arg0"}, "test",
- TEST_PACKAGE + ".TestArrayAccess04", il, _cp);
+ TEST_PACKAGE + ".TestArrayAccess04" + genClassSuffix, il, _cp);
final InstructionHandle ih_0 = il.append(new PUSH(_cp, 1));
assertNotNull(ih_0); // TODO why is this not used
@@ -80,11 +84,11 @@ public class TestArrayAccess04Creator extends TestCreator {
il.append(InstructionFactory.createStore(Type.OBJECT, 1));
final InstructionHandle ih_5 = il.append(new PUSH(_cp, 1));
assertNotNull(ih_5); // TODO why is this not used
- il.append(InstructionFactory.createStore(Type.INT, 2));
+ il.append(InstructionFactory.createStore(primitiveType, 2));
final InstructionHandle ih_7 = il.append(InstructionFactory.createLoad(Type.OBJECT, 1));
assertNotNull(ih_7); // TODO why is this not used
il.append(new PUSH(_cp, 0));
- il.append(InstructionFactory.createLoad(Type.INT, 2));
+ il.append(InstructionFactory.createLoad(primitiveType, 2));
il.append(InstructionConst.AASTORE);
final InstructionHandle ih_11 = il.append(InstructionFactory.createReturn(Type.VOID));
assertNotNull(ih_11); // TODO why is this not used
diff --git a/src/test/java/org/apache/bcel/verifier/tests/TestArrayAccess04DoubleCreator.java b/src/test/java/org/apache/bcel/verifier/tests/TestArrayAccess04DoubleCreator.java
new file mode 100644
index 00000000..932650ba
--- /dev/null
+++ b/src/test/java/org/apache/bcel/verifier/tests/TestArrayAccess04DoubleCreator.java
@@ -0,0 +1,27 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.bcel.verifier.tests;
+
+import org.apache.bcel.generic.Type;
+
+public class TestArrayAccess04DoubleCreator extends TestArrayAccess04Creator {
+
+ public TestArrayAccess04DoubleCreator() {
+ super(Type.DOUBLE, "Double");
+ }
+}
diff --git a/src/test/java/org/apache/bcel/verifier/tests/TestArrayAccess04FloatCreator.java b/src/test/java/org/apache/bcel/verifier/tests/TestArrayAccess04FloatCreator.java
new file mode 100644
index 00000000..0a0e6be1
--- /dev/null
+++ b/src/test/java/org/apache/bcel/verifier/tests/TestArrayAccess04FloatCreator.java
@@ -0,0 +1,27 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.bcel.verifier.tests;
+
+import org.apache.bcel.generic.Type;
+
+public class TestArrayAccess04FloatCreator extends TestArrayAccess04Creator {
+
+ public TestArrayAccess04FloatCreator() {
+ super(Type.FLOAT, "Float");
+ }
+}
diff --git a/src/test/java/org/apache/bcel/verifier/tests/TestArrayAccess04IntCreator.java b/src/test/java/org/apache/bcel/verifier/tests/TestArrayAccess04IntCreator.java
new file mode 100644
index 00000000..7b1574d7
--- /dev/null
+++ b/src/test/java/org/apache/bcel/verifier/tests/TestArrayAccess04IntCreator.java
@@ -0,0 +1,27 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.bcel.verifier.tests;
+
+import org.apache.bcel.generic.Type;
+
+public class TestArrayAccess04IntCreator extends TestArrayAccess04Creator {
+
+ public TestArrayAccess04IntCreator() {
+ super(Type.INT, "Int");
+ }
+}
diff --git a/src/test/java/org/apache/bcel/verifier/tests/TestArrayAccess04LongCreator.java b/src/test/java/org/apache/bcel/verifier/tests/TestArrayAccess04LongCreator.java
new file mode 100644
index 00000000..15a2bd62
--- /dev/null
+++ b/src/test/java/org/apache/bcel/verifier/tests/TestArrayAccess04LongCreator.java
@@ -0,0 +1,27 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.bcel.verifier.tests;
+
+import org.apache.bcel.generic.Type;
+
+public class TestArrayAccess04LongCreator extends TestArrayAccess04Creator {
+
+ public TestArrayAccess04LongCreator() {
+ super(Type.LONG, "Long");
+ }
+}
diff --git a/src/test/java/org/apache/bcel/verifier/tests/TestArrayAccess04ShortCreator.java b/src/test/java/org/apache/bcel/verifier/tests/TestArrayAccess04ShortCreator.java
new file mode 100644
index 00000000..2678b537
--- /dev/null
+++ b/src/test/java/org/apache/bcel/verifier/tests/TestArrayAccess04ShortCreator.java
@@ -0,0 +1,27 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.bcel.verifier.tests;
+
+import org.apache.bcel.generic.Type;
+
+public class TestArrayAccess04ShortCreator extends TestArrayAccess04Creator {
+
+ public TestArrayAccess04ShortCreator() {
+ super(Type.SHORT, "Short");
+ }
+}
diff --git a/src/test/java/org/apache/bcel/verifier/tests/TestArrayAccess04UnknownCreator.java b/src/test/java/org/apache/bcel/verifier/tests/TestArrayAccess04UnknownCreator.java
new file mode 100644
index 00000000..86fb2bf3
--- /dev/null
+++ b/src/test/java/org/apache/bcel/verifier/tests/TestArrayAccess04UnknownCreator.java
@@ -0,0 +1,27 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.bcel.verifier.tests;
+
+import org.apache.bcel.generic.Type;
+
+public class TestArrayAccess04UnknownCreator extends TestArrayAccess04Creator {
+
+ public TestArrayAccess04UnknownCreator() {
+ super(Type.UNKNOWN, null);
+ }
+}
diff --git a/src/test/java/org/apache/bcel/verifier/tests/TestReturn03BooleanCreator.java b/src/test/java/org/apache/bcel/verifier/tests/TestReturn03BooleanCreator.java
new file mode 100644
index 00000000..5971e1f5
--- /dev/null
+++ b/src/test/java/org/apache/bcel/verifier/tests/TestReturn03BooleanCreator.java
@@ -0,0 +1,27 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.bcel.verifier.tests;
+
+import org.apache.bcel.generic.Type;
+
+public class TestReturn03BooleanCreator extends TestReturn03Creator {
+
+ public TestReturn03BooleanCreator() {
+ super(Type.BOOLEAN, "Boolean");
+ }
+
+}
diff --git a/src/test/java/org/apache/bcel/verifier/tests/TestReturn03ByteCreator.java b/src/test/java/org/apache/bcel/verifier/tests/TestReturn03ByteCreator.java
new file mode 100644
index 00000000..919e82c2
--- /dev/null
+++ b/src/test/java/org/apache/bcel/verifier/tests/TestReturn03ByteCreator.java
@@ -0,0 +1,27 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.bcel.verifier.tests;
+
+import org.apache.bcel.generic.Type;
+
+public class TestReturn03ByteCreator extends TestReturn03Creator {
+
+ public TestReturn03ByteCreator() {
+ super(Type.BYTE, "Byte");
+ }
+
+}
diff --git a/src/test/java/org/apache/bcel/verifier/tests/TestReturn03Creator.java b/src/test/java/org/apache/bcel/verifier/tests/TestReturn03Creator.java
index 4cd221a5..d753226d 100644
--- a/src/test/java/org/apache/bcel/verifier/tests/TestReturn03Creator.java
+++ b/src/test/java/org/apache/bcel/verifier/tests/TestReturn03Creator.java
@@ -31,16 +31,20 @@ import org.apache.bcel.generic.InstructionList;
import org.apache.bcel.generic.MethodGen;
import org.apache.bcel.generic.Type;
-public class TestReturn03Creator extends TestCreator {
+public abstract class TestReturn03Creator extends TestCreator {
private final InstructionFactory _factory;
private final ConstantPoolGen _cp;
private final ClassGen _cg;
+ private final Type returnType;
+ private final String genClassSuffix;
- public TestReturn03Creator() {
- _cg = new ClassGen(TEST_PACKAGE + ".TestReturn03", "java.lang.Object", "TestReturn03.java", Const.ACC_PUBLIC | Const.ACC_SUPER, new String[] {});
+ protected TestReturn03Creator(final Type returnType, final String genClassSuffix) {
+ _cg = new ClassGen(TEST_PACKAGE + ".TestReturn03" + genClassSuffix, "java.lang.Object", "TestReturn03.java", Const.ACC_PUBLIC | Const.ACC_SUPER, new String[] {});
_cp = _cg.getConstantPool();
_factory = new InstructionFactory(_cg, _cp);
+ this.returnType = returnType;
+ this.genClassSuffix = genClassSuffix;
}
@Override
@@ -68,11 +72,11 @@ public class TestReturn03Creator extends TestCreator {
private void createMethod_1() {
final InstructionList il = new InstructionList();
final MethodGen method = new MethodGen(Const.ACC_PUBLIC | Const.ACC_STATIC, Type.INT, Type.NO_ARGS, new String[] {}, "test3",
- TEST_PACKAGE + ".TestReturn03", il, _cp);
+ TEST_PACKAGE + ".TestReturn03" + genClassSuffix, il, _cp);
final InstructionHandle ih_0 = il.append(InstructionConst.ACONST_NULL);
assertNotNull(ih_0); // TODO why is this not used
- il.append(InstructionFactory.createReturn(Type.OBJECT));
+ il.append(InstructionFactory.createReturn(returnType));
method.setMaxStack();
method.setMaxLocals();
_cg.addMethod(method.getMethod());
diff --git a/src/test/java/org/apache/bcel/verifier/tests/TestReturn03DoubleCreator.java b/src/test/java/org/apache/bcel/verifier/tests/TestReturn03DoubleCreator.java
new file mode 100644
index 00000000..dd73e01c
--- /dev/null
+++ b/src/test/java/org/apache/bcel/verifier/tests/TestReturn03DoubleCreator.java
@@ -0,0 +1,27 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.bcel.verifier.tests;
+
+import org.apache.bcel.generic.Type;
+
+public class TestReturn03DoubleCreator extends TestReturn03Creator {
+
+ public TestReturn03DoubleCreator() {
+ super(Type.DOUBLE, "Double");
+ }
+
+}
diff --git a/src/test/java/org/apache/bcel/verifier/tests/TestReturn03FloatCreator.java b/src/test/java/org/apache/bcel/verifier/tests/TestReturn03FloatCreator.java
new file mode 100644
index 00000000..c7524b73
--- /dev/null
+++ b/src/test/java/org/apache/bcel/verifier/tests/TestReturn03FloatCreator.java
@@ -0,0 +1,27 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.bcel.verifier.tests;
+
+import org.apache.bcel.generic.Type;
+
+public class TestReturn03FloatCreator extends TestReturn03Creator {
+
+ public TestReturn03FloatCreator() {
+ super(Type.FLOAT, "Float");
+ }
+
+}
diff --git a/src/test/java/org/apache/bcel/verifier/tests/TestReturn03IntCreator.java b/src/test/java/org/apache/bcel/verifier/tests/TestReturn03IntCreator.java
new file mode 100644
index 00000000..a6f9f59e
--- /dev/null
+++ b/src/test/java/org/apache/bcel/verifier/tests/TestReturn03IntCreator.java
@@ -0,0 +1,27 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.bcel.verifier.tests;
+
+import org.apache.bcel.generic.Type;
+
+public class TestReturn03IntCreator extends TestReturn03Creator {
+
+ public TestReturn03IntCreator() {
+ super(Type.INT, "Int");
+ }
+
+}
diff --git a/src/test/java/org/apache/bcel/verifier/tests/TestReturn03LongCreator.java b/src/test/java/org/apache/bcel/verifier/tests/TestReturn03LongCreator.java
new file mode 100644
index 00000000..63b7c964
--- /dev/null
+++ b/src/test/java/org/apache/bcel/verifier/tests/TestReturn03LongCreator.java
@@ -0,0 +1,27 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.bcel.verifier.tests;
+
+import org.apache.bcel.generic.Type;
+
+public class TestReturn03LongCreator extends TestReturn03Creator {
+
+ public TestReturn03LongCreator() {
+ super(Type.LONG, "Long");
+ }
+
+}
diff --git a/src/test/java/org/apache/bcel/verifier/tests/TestReturn03ObjectCreator.java b/src/test/java/org/apache/bcel/verifier/tests/TestReturn03ObjectCreator.java
new file mode 100644
index 00000000..4e65c4b8
--- /dev/null
+++ b/src/test/java/org/apache/bcel/verifier/tests/TestReturn03ObjectCreator.java
@@ -0,0 +1,27 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.bcel.verifier.tests;
+
+import org.apache.bcel.generic.Type;
+
+public class TestReturn03ObjectCreator extends TestReturn03Creator {
+
+ public TestReturn03ObjectCreator() {
+ super(Type.OBJECT, "Object");
+ }
+
+}
diff --git a/src/test/java/org/apache/bcel/verifier/tests/TestReturn03ShortCreator.java b/src/test/java/org/apache/bcel/verifier/tests/TestReturn03ShortCreator.java
new file mode 100644
index 00000000..15159a91
--- /dev/null
+++ b/src/test/java/org/apache/bcel/verifier/tests/TestReturn03ShortCreator.java
@@ -0,0 +1,27 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.bcel.verifier.tests;
+
+import org.apache.bcel.generic.Type;
+
+public class TestReturn03ShortCreator extends TestReturn03Creator {
+
+ public TestReturn03ShortCreator() {
+ super(Type.SHORT, "Short");
+ }
+
+}
diff --git a/src/test/java/org/apache/bcel/verifier/tests/TestReturn03UnknownCreator.java b/src/test/java/org/apache/bcel/verifier/tests/TestReturn03UnknownCreator.java
new file mode 100644
index 00000000..0a2b091e
--- /dev/null
+++ b/src/test/java/org/apache/bcel/verifier/tests/TestReturn03UnknownCreator.java
@@ -0,0 +1,27 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.bcel.verifier.tests;
+
+import org.apache.bcel.generic.Type;
+
+public class TestReturn03UnknownCreator extends TestReturn03Creator {
+
+ public TestReturn03UnknownCreator() {
+ super(Type.UNKNOWN, null);
+ }
+
+}