From 4bd04e91e13962719b51edf0cc4eafa17df87889 Mon Sep 17 00:00:00 2001
From: Mark Roberts
diff --git a/src/main/java/org/apache/bcel/classfile/StackMapEntry.java b/src/main/java/org/apache/bcel/classfile/StackMapEntry.java
index 4afe9c0f4f..ca2d7bdee5 100644
--- a/src/main/java/org/apache/bcel/classfile/StackMapEntry.java
+++ b/src/main/java/org/apache/bcel/classfile/StackMapEntry.java
@@ -224,7 +224,6 @@ public int getFrameType() {
/**
* Calculate stack map entry size
- *
*/
int getMapEntrySize() {
if (frameType >= Const.SAME_FRAME && frameType <= Const.SAME_FRAME_MAX) {
diff --git a/src/main/java/org/apache/bcel/classfile/Utility.java b/src/main/java/org/apache/bcel/classfile/Utility.java
index 691577e06f..76fc8932ab 100644
--- a/src/main/java/org/apache/bcel/classfile/Utility.java
+++ b/src/main/java/org/apache/bcel/classfile/Utility.java
@@ -37,6 +37,7 @@
import org.apache.bcel.Const;
import org.apache.bcel.util.ByteSequence;
+import org.apache.commons.lang3.ArrayFill;
import org.apache.commons.lang3.ArrayUtils;
/**
@@ -715,8 +716,7 @@ public static String encode(byte[] bytes, final boolean compress) throws IOExcep
*/
public static String fillup(final String str, final int length, final boolean leftJustify, final char fill) {
final int len = length - str.length();
- final char[] buf = new char[Math.max(len, 0)];
- Arrays.fill(buf, fill);
+ final char[] buf = ArrayFill.fill(new char[Math.max(len, 0)], fill);
if (leftJustify) {
return str + new String(buf);
}
@@ -1169,7 +1169,7 @@ public static String signatureToString(final String signature, final boolean cho
type = typeParams + typeSignaturesToString(signature.substring(index), chopit, ')');
index += unwrap(CONSUMER_CHARS); // update position
// add return type
- type = type + typeSignatureToString(signature.substring(index), chopit);
+ type += typeSignatureToString(signature.substring(index), chopit);
index += unwrap(CONSUMER_CHARS); // update position
// ignore any throws information in the signature
return type;
diff --git a/src/main/java/org/apache/bcel/classfile/Visitor.java b/src/main/java/org/apache/bcel/classfile/Visitor.java
index 4f4b5c2116..3f0a7b3cf8 100644
--- a/src/main/java/org/apache/bcel/classfile/Visitor.java
+++ b/src/main/java/org/apache/bcel/classfile/Visitor.java
@@ -212,11 +212,32 @@ default void visitNestMembers(final NestMembers obj) {
*/
void visitParameterAnnotation(ParameterAnnotations obj);
+
/**
* @since 6.0
*/
void visitParameterAnnotationEntry(ParameterAnnotationEntry obj);
+ /**
+ * Visits a {@link Record} object.
+ *
+ * @param obj Record to visit
+ * @since 6.9.0
+ */
+ default void visitRecord(final Record obj) {
+ // empty
+ }
+
+ /**
+ * Visits a {@link RecordComponentInfo} object.
+ *
+ * @param record component to visit
+ * @since 6.9.0
+ */
+ default void visitRecordComponent(final RecordComponentInfo record) {
+ // noop
+ }
+
void visitSignature(Signature obj);
void visitSourceFile(SourceFile obj);
@@ -227,6 +248,7 @@ default void visitNestMembers(final NestMembers obj) {
/**
* Visits a {@link StackMapType} object.
+ *
* @param obj object to visit
* @since 6.8.0
*/
@@ -237,4 +259,5 @@ default void visitStackMapType(final StackMapType obj) {
void visitSynthetic(Synthetic obj);
void visitUnknown(Unknown obj);
+
}
diff --git a/src/main/java/org/apache/bcel/generic/AnnotationEntryGen.java b/src/main/java/org/apache/bcel/generic/AnnotationEntryGen.java
index 603404a213..e0e04ec4aa 100644
--- a/src/main/java/org/apache/bcel/generic/AnnotationEntryGen.java
+++ b/src/main/java/org/apache/bcel/generic/AnnotationEntryGen.java
@@ -24,6 +24,7 @@
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
+import java.util.stream.Collectors;
import org.apache.bcel.classfile.AnnotationEntry;
import org.apache.bcel.classfile.Attribute;
@@ -33,6 +34,8 @@
import org.apache.bcel.classfile.RuntimeInvisibleParameterAnnotations;
import org.apache.bcel.classfile.RuntimeVisibleAnnotations;
import org.apache.bcel.classfile.RuntimeVisibleParameterAnnotations;
+import org.apache.commons.lang3.ArrayUtils;
+import org.apache.commons.lang3.stream.Streams;
/**
* @since 6.0
@@ -48,7 +51,7 @@ public class AnnotationEntryGen {
* @param annotationEntryGens An array of AnnotationGen objects
*/
static Attribute[] getAnnotationAttributes(final ConstantPoolGen cp, final AnnotationEntryGen[] annotationEntryGens) {
- if (annotationEntryGens.length == 0) {
+ if (ArrayUtils.isEmpty(annotationEntryGens)) {
return Attribute.EMPTY_ARRAY;
}
@@ -250,11 +253,7 @@ public void addElementNameValuePair(final ElementValuePairGen evp) {
}
private List copyValues(final ElementValuePair[] in, final ConstantPoolGen cpool, final boolean copyPoolEntries) {
- final List out = new ArrayList<>();
- for (final ElementValuePair nvp : in) {
- out.add(new ElementValuePairGen(nvp, cpool, copyPoolEntries));
- }
- return out;
+ return Streams.of(in).map(nvp -> new ElementValuePairGen(nvp, cpool, copyPoolEntries)).collect(Collectors.toList());
}
public void dump(final DataOutputStream dos) throws IOException {
diff --git a/src/main/java/org/apache/bcel/generic/ArrayElementValueGen.java b/src/main/java/org/apache/bcel/generic/ArrayElementValueGen.java
index 744a1ce8ae..21442263d5 100644
--- a/src/main/java/org/apache/bcel/generic/ArrayElementValueGen.java
+++ b/src/main/java/org/apache/bcel/generic/ArrayElementValueGen.java
@@ -20,9 +20,11 @@
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
+import java.util.stream.Collectors;
import org.apache.bcel.classfile.ArrayElementValue;
import org.apache.bcel.classfile.ElementValue;
+import org.apache.commons.lang3.stream.Streams;
/**
* @since 6.0
@@ -50,15 +52,12 @@ public ArrayElementValueGen(final ConstantPoolGen cp) {
evalues = new ArrayList<>();
}
- public ArrayElementValueGen(final int type, final ElementValue[] datums, final ConstantPoolGen cpool) {
+ public ArrayElementValueGen(final int type, final ElementValue[] elementValues, final ConstantPoolGen cpool) {
super(type, cpool);
if (type != ARRAY) {
throw new IllegalArgumentException("Only element values of type array can be built with this ctor - type specified: " + type);
}
- this.evalues = new ArrayList<>();
- for (final ElementValue datum : datums) {
- evalues.add(ElementValueGen.copy(datum, cpool, true));
- }
+ this.evalues = Streams.of(elementValues).map(e -> ElementValueGen.copy(e, cpool, true)).collect(Collectors.toList());
}
public void addElement(final ElementValueGen gen) {
diff --git a/src/main/java/org/apache/bcel/generic/ClassGen.java b/src/main/java/org/apache/bcel/generic/ClassGen.java
index b612050a93..e961cbcb54 100644
--- a/src/main/java/org/apache/bcel/generic/ClassGen.java
+++ b/src/main/java/org/apache/bcel/generic/ClassGen.java
@@ -95,7 +95,7 @@ public static void setComparator(final BCELComparator comparator) {
private List observers;
/**
- * Initialize with existing class.
+ * Constructs a new instance from an existing class.
*
* @param clazz JavaClass object (e.g. read from file)
*/
@@ -112,15 +112,26 @@ public ClassGen(final JavaClass clazz) {
final Attribute[] attributes = clazz.getAttributes();
// J5TODO: Could make unpacking lazy, done on first reference
final AnnotationEntryGen[] annotations = unpackAnnotations(attributes);
- Collections.addAll(interfaceList, clazz.getInterfaceNames());
- for (final Attribute attribute : attributes) {
- if (!(attribute instanceof Annotations)) {
- addAttribute(attribute);
+ final String[] interfaceNames = clazz.getInterfaceNames();
+ if (interfaceNames != null) {
+ Collections.addAll(interfaceList, interfaceNames);
+ }
+ if (attributes != null) {
+ for (final Attribute attribute : attributes) {
+ if (!(attribute instanceof Annotations)) {
+ addAttribute(attribute);
+ }
}
}
Collections.addAll(annotationList, annotations);
- Collections.addAll(methodList, clazz.getMethods());
- Collections.addAll(fieldList, clazz.getFields());
+ final Method[] methods = clazz.getMethods();
+ if (methods != null) {
+ Collections.addAll(methodList, methods);
+ }
+ final Field[] fields = clazz.getFields();
+ if (fields != null) {
+ Collections.addAll(fieldList, fields);
+ }
}
/**
@@ -486,7 +497,9 @@ public void setMethodAt(final Method method, final int pos) {
public void setMethods(final Method[] methods) {
methodList.clear();
- Collections.addAll(methodList, methods);
+ if (methods != null) {
+ Collections.addAll(methodList, methods);
+ }
}
/**
@@ -509,17 +522,19 @@ public void setSuperclassNameIndex(final int superclassNameIndex) {
}
/**
- * Look for attributes representing annotations and unpack them.
+ * Unpacks attributes representing annotations.
*/
- private AnnotationEntryGen[] unpackAnnotations(final Attribute[] attrs) {
+ private AnnotationEntryGen[] unpackAnnotations(final Attribute[] attributes) {
final List annotationGenObjs = new ArrayList<>();
- for (final Attribute attr : attrs) {
- if (attr instanceof RuntimeVisibleAnnotations) {
- final RuntimeVisibleAnnotations rva = (RuntimeVisibleAnnotations) attr;
- rva.forEach(a -> annotationGenObjs.add(new AnnotationEntryGen(a, getConstantPool(), false)));
- } else if (attr instanceof RuntimeInvisibleAnnotations) {
- final RuntimeInvisibleAnnotations ria = (RuntimeInvisibleAnnotations) attr;
- ria.forEach(a -> annotationGenObjs.add(new AnnotationEntryGen(a, getConstantPool(), false)));
+ if (attributes != null) {
+ for (final Attribute attr : attributes) {
+ if (attr instanceof RuntimeVisibleAnnotations) {
+ final RuntimeVisibleAnnotations rva = (RuntimeVisibleAnnotations) attr;
+ rva.forEach(a -> annotationGenObjs.add(new AnnotationEntryGen(a, getConstantPool(), false)));
+ } else if (attr instanceof RuntimeInvisibleAnnotations) {
+ final RuntimeInvisibleAnnotations ria = (RuntimeInvisibleAnnotations) attr;
+ ria.forEach(a -> annotationGenObjs.add(new AnnotationEntryGen(a, getConstantPool(), false)));
+ }
}
}
return annotationGenObjs.toArray(AnnotationEntryGen.EMPTY_ARRAY);
diff --git a/src/main/java/org/apache/bcel/generic/FieldGenOrMethodGen.java b/src/main/java/org/apache/bcel/generic/FieldGenOrMethodGen.java
index 9f6c5b2d5d..9b6fbabedf 100644
--- a/src/main/java/org/apache/bcel/generic/FieldGenOrMethodGen.java
+++ b/src/main/java/org/apache/bcel/generic/FieldGenOrMethodGen.java
@@ -62,8 +62,10 @@ protected FieldGenOrMethodGen(final int accessFlags) { // TODO could this be pac
super(accessFlags);
}
- protected void addAll(final Attribute[] attrs) {
- Collections.addAll(attributeList, attrs);
+ protected void addAll(final Attribute[] attributes) {
+ if (attributes != null) {
+ Collections.addAll(attributeList, attributes);
+ }
}
/**
diff --git a/src/main/java/org/apache/bcel/generic/FieldOrMethod.java b/src/main/java/org/apache/bcel/generic/FieldOrMethod.java
index 1075e06237..80fd33af9f 100644
--- a/src/main/java/org/apache/bcel/generic/FieldOrMethod.java
+++ b/src/main/java/org/apache/bcel/generic/FieldOrMethod.java
@@ -48,7 +48,6 @@ protected FieldOrMethod(final short opcode, final int index) {
* generated by Java 1.5, this answer is sometimes wrong (e.g., if the "clone()" method is called on an
* array). A better idea is to use the {@link #getReferenceType(ConstantPoolGen)} method, which correctly
* distinguishes between class types and array types.
- *
*/
@Deprecated
public String getClassName(final ConstantPoolGen cpg) {
diff --git a/src/main/java/org/apache/bcel/generic/InstructionFactory.java b/src/main/java/org/apache/bcel/generic/InstructionFactory.java
index 2f1f91323b..90c82cfdcd 100644
--- a/src/main/java/org/apache/bcel/generic/InstructionFactory.java
+++ b/src/main/java/org/apache/bcel/generic/InstructionFactory.java
@@ -640,8 +640,10 @@ public InvokeInstruction createInvoke(final String className, final String name,
int index;
int nargs = 0;
final String signature = Type.getMethodSignature(retType, argTypes);
- for (final Type argType : argTypes) {
- nargs += argType.getSize();
+ if (argTypes != null) {
+ for (final Type argType : argTypes) {
+ nargs += argType.getSize();
+ }
}
if (useInterface) {
index = cp.addInterfaceMethodref(className, name, signature);
diff --git a/src/main/java/org/apache/bcel/generic/InstructionList.java b/src/main/java/org/apache/bcel/generic/InstructionList.java
index ca053e4418..0f4340b70f 100644
--- a/src/main/java/org/apache/bcel/generic/InstructionList.java
+++ b/src/main/java/org/apache/bcel/generic/InstructionList.java
@@ -31,6 +31,7 @@
import org.apache.bcel.classfile.Constant;
import org.apache.bcel.util.ByteSequence;
import org.apache.commons.lang3.ArrayUtils;
+import org.apache.commons.lang3.stream.Streams;
/**
* This class is a container for a list of Instruction objects. Instructions can be
@@ -57,23 +58,25 @@ public class InstructionList implements Iterable {
* @return target position's instruction handle if available
*/
public static InstructionHandle findHandle(final InstructionHandle[] ihs, final int[] pos, final int count, final int target) {
- int l = 0;
- int r = count - 1;
- /*
- * Do a binary search since the pos array is orderd.
- */
- do {
- final int i = l + r >>> 1;
- final int j = pos[i];
- if (j == target) {
- return ihs[i];
- }
- if (target < j) {
- r = i - 1;
- } else {
- l = i + 1;
- }
- } while (l <= r);
+ if (ihs != null && pos != null) {
+ int l = 0;
+ int r = count - 1;
+ /*
+ * Do a binary search since the pos array is orderd.
+ */
+ do {
+ final int i = l + r >>> 1;
+ final int j = pos[i];
+ if (j == target) {
+ return ihs[i];
+ }
+ if (target < j) {
+ r = i - 1;
+ } else {
+ l = i + 1;
+ }
+ } while (l <= r);
+ }
return null;
}
@@ -956,7 +959,7 @@ public void redirectBranches(final InstructionHandle oldTarget, final Instructio
* @see MethodGen
*/
public void redirectExceptionHandlers(final CodeExceptionGen[] exceptions, final InstructionHandle oldTarget, final InstructionHandle newTarget) {
- for (final CodeExceptionGen exception : exceptions) {
+ Streams.of(exceptions).forEach(exception -> {
if (exception.getStartPC() == oldTarget) {
exception.setStartPC(newTarget);
}
@@ -966,7 +969,7 @@ public void redirectExceptionHandlers(final CodeExceptionGen[] exceptions, final
if (exception.getHandlerPC() == oldTarget) {
exception.setHandlerPC(newTarget);
}
- }
+ });
}
/**
@@ -978,16 +981,14 @@ public void redirectExceptionHandlers(final CodeExceptionGen[] exceptions, final
* @see MethodGen
*/
public void redirectLocalVariables(final LocalVariableGen[] lg, final InstructionHandle oldTarget, final InstructionHandle newTarget) {
- for (final LocalVariableGen element : lg) {
- final InstructionHandle start = element.getStart();
- final InstructionHandle end = element.getEnd();
- if (start == oldTarget) {
+ Streams.of(lg).forEach(element -> {
+ if (element.getStart() == oldTarget) {
element.setStart(newTarget);
}
- if (end == oldTarget) {
+ if (element.getEnd() == oldTarget) {
element.setEnd(newTarget);
}
- }
+ });
}
/**
diff --git a/src/main/java/org/apache/bcel/generic/MethodGen.java b/src/main/java/org/apache/bcel/generic/MethodGen.java
index 1cccda44a9..0f3cc8c95a 100644
--- a/src/main/java/org/apache/bcel/generic/MethodGen.java
+++ b/src/main/java/org/apache/bcel/generic/MethodGen.java
@@ -24,6 +24,7 @@
import java.util.List;
import java.util.Objects;
import java.util.Stack;
+import java.util.stream.Collectors;
import org.apache.bcel.Const;
import org.apache.bcel.classfile.AnnotationEntry;
@@ -44,6 +45,7 @@
import org.apache.bcel.classfile.Utility;
import org.apache.bcel.util.BCELComparator;
import org.apache.commons.lang3.ArrayUtils;
+import org.apache.commons.lang3.stream.Streams;
/**
* Template class for building up a method. This is done by defining exception handlers, adding thrown exceptions, local
@@ -893,11 +895,7 @@ public int hashCode() {
}
private List makeMutableVersion(final AnnotationEntry[] mutableArray) {
- final List result = new ArrayList<>();
- for (final AnnotationEntry element : mutableArray) {
- result.add(new AnnotationEntryGen(element, getConstantPool(), false));
- }
- return result;
+ return Streams.of(mutableArray).map(ae -> new AnnotationEntryGen(ae, getConstantPool(), false)).collect(Collectors.toList());
}
/**
@@ -1023,10 +1021,8 @@ public void removeObserver(final MethodObserver o) {
*
* @since 6.5.0
*/
- public void removeRuntimeAttributes(final Attribute[] attrs) {
- for (final Attribute attr : attrs) {
- removeAttribute(attr);
- }
+ public void removeRuntimeAttributes(final Attribute[] attributes) {
+ Streams.of(attributes).forEach(this::removeAttribute);
}
public void setArgumentName(final int i, final String name) {
@@ -1034,7 +1030,7 @@ public void setArgumentName(final int i, final String name) {
}
public void setArgumentNames(final String[] argNames) {
- this.argNames = argNames;
+ this.argNames = ArrayUtils.nullToEmpty(argNames);
}
public void setArgumentType(final int i, final Type type) {
@@ -1042,7 +1038,7 @@ public void setArgumentType(final int i, final Type type) {
}
public void setArgumentTypes(final Type[] argTypes) {
- this.argTypes = argTypes;
+ this.argTypes = argTypes != null ? argTypes : Type.NO_ARGS;
}
public void setClassName(final String className) { // TODO could be package-protected?
@@ -1059,10 +1055,8 @@ public void setInstructionList(final InstructionList il) { // TODO could be pack
public void setMaxLocals() { // TODO could be package-protected? (some tests would need repackaging)
if (il != null) {
int max = isStatic() ? 0 : 1;
- if (argTypes != null) {
- for (final Type argType : argTypes) {
- max += argType.getSize();
- }
+ for (final Type argType : argTypes) {
+ max += argType.getSize();
}
for (InstructionHandle ih = il.getStart(); ih != null; ih = ih.getNext()) {
final Instruction ins = ih.getInstruction();
diff --git a/src/main/java/org/apache/bcel/generic/Select.java b/src/main/java/org/apache/bcel/generic/Select.java
index ce1efc3b48..b08e5596b1 100644
--- a/src/main/java/org/apache/bcel/generic/Select.java
+++ b/src/main/java/org/apache/bcel/generic/Select.java
@@ -83,7 +83,7 @@ public abstract class Select extends BranchInstruction implements VariableLength
* @param defaultTarget default instruction target
*/
Select(final short opcode, final int[] match, final InstructionHandle[] targets, final InstructionHandle defaultTarget) {
- // don't set default target before instuction is built
+ // don't set default target before instruction is built
super(opcode, null);
this.match = match;
this.targets = targets;
diff --git a/src/main/java/org/apache/bcel/util/Class2HTML.java b/src/main/java/org/apache/bcel/util/Class2HTML.java
index 13952db0a4..603b05fb91 100644
--- a/src/main/java/org/apache/bcel/util/Class2HTML.java
+++ b/src/main/java/org/apache/bcel/util/Class2HTML.java
@@ -85,7 +85,7 @@ public static void main(final String[] argv) throws IOException {
if (argv[i].equals("-d")) { // Specify target directory, default '.'
dir = argv[++i];
if (!dir.endsWith("" + sep)) {
- dir = dir + sep;
+ dir += sep;
}
final File store = new File(dir);
if (!store.isDirectory()) {
diff --git a/src/main/java/org/apache/bcel/util/InstructionFinder.java b/src/main/java/org/apache/bcel/util/InstructionFinder.java
index 62169817ee..e501635110 100644
--- a/src/main/java/org/apache/bcel/util/InstructionFinder.java
+++ b/src/main/java/org/apache/bcel/util/InstructionFinder.java
@@ -65,7 +65,6 @@ public class InstructionFinder {
/**
* Code patterns found may be checked using an additional user-defined constraint object whether they really match the
* needed criterion. I.e., check constraints that can not expressed with regular expressions.
- *
*/
public interface CodeConstraint {
diff --git a/src/main/java/org/apache/bcel/util/SyntheticRepository.java b/src/main/java/org/apache/bcel/util/SyntheticRepository.java
index c046cb4eb3..f1889a8139 100644
--- a/src/main/java/org/apache/bcel/util/SyntheticRepository.java
+++ b/src/main/java/org/apache/bcel/util/SyntheticRepository.java
@@ -16,8 +16,8 @@
*/
package org.apache.bcel.util;
-import java.util.HashMap;
import java.util.Map;
+import java.util.concurrent.ConcurrentHashMap;
/**
* This repository is used in situations where a Class is created outside the realm of a ClassLoader. Classes are loaded
@@ -32,7 +32,7 @@
*/
public class SyntheticRepository extends MemorySensitiveClassPathRepository {
- private static final Map MAP = new HashMap<>(); // CLASSPATH X REPOSITORY
+ private static final Map MAP = new ConcurrentHashMap<>(); // CLASSPATH X REPOSITORY
public static SyntheticRepository getInstance() {
return getInstance(ClassPath.SYSTEM_CLASS_PATH);
diff --git a/src/main/java/org/apache/bcel/verifier/statics/Pass2Verifier.java b/src/main/java/org/apache/bcel/verifier/statics/Pass2Verifier.java
index 34f9f5f35f..6ea0d18d1a 100644
--- a/src/main/java/org/apache/bcel/verifier/statics/Pass2Verifier.java
+++ b/src/main/java/org/apache/bcel/verifier/statics/Pass2Verifier.java
@@ -665,7 +665,7 @@ public void visitInnerClasses(final InnerClasses innerClasses) { // vmspec2 4.7.
checkIndex(innerClasses, innernameIdx, CONST_Utf8);
}
int acc = ic.getInnerAccessFlags();
- acc = acc & ~(Const.ACC_PUBLIC | Const.ACC_PRIVATE | Const.ACC_PROTECTED | Const.ACC_STATIC | Const.ACC_FINAL | Const.ACC_INTERFACE |
+ acc &= ~(Const.ACC_PUBLIC | Const.ACC_PRIVATE | Const.ACC_PROTECTED | Const.ACC_STATIC | Const.ACC_FINAL | Const.ACC_INTERFACE |
Const.ACC_ABSTRACT);
if (acc != 0) {
addMessage("Unknown access flag for inner class '" + tostring(ic) + "' set (InnerClasses attribute '" + tostring(innerClasses) + "').");
diff --git a/src/main/java/org/apache/bcel/verifier/statics/Pass3aVerifier.java b/src/main/java/org/apache/bcel/verifier/statics/Pass3aVerifier.java
index 25def60f6e..b9a67e5cf1 100644
--- a/src/main/java/org/apache/bcel/verifier/statics/Pass3aVerifier.java
+++ b/src/main/java/org/apache/bcel/verifier/statics/Pass3aVerifier.java
@@ -1043,8 +1043,7 @@ public VerificationResult do_verify() {
try {
delayedPass2Checks();
} catch (final ClassConstraintException | ClassFormatException cce) {
- vr = new VerificationResult(VerificationResult.VERIFIED_REJECTED, cce.getMessage());
- return vr;
+ return new VerificationResult(VerificationResult.VERIFIED_REJECTED, cce.getMessage());
}
try {
pass3StaticInstructionChecks();
diff --git a/src/main/java/org/apache/bcel/verifier/statics/StringRepresentation.java b/src/main/java/org/apache/bcel/verifier/statics/StringRepresentation.java
index a894174608..d8c663b0f7 100644
--- a/src/main/java/org/apache/bcel/verifier/statics/StringRepresentation.java
+++ b/src/main/java/org/apache/bcel/verifier/statics/StringRepresentation.java
@@ -59,6 +59,8 @@
import org.apache.bcel.classfile.Node;
import org.apache.bcel.classfile.ParameterAnnotationEntry;
import org.apache.bcel.classfile.ParameterAnnotations;
+import org.apache.bcel.classfile.Record;
+import org.apache.bcel.classfile.RecordComponentInfo;
import org.apache.bcel.classfile.Signature;
import org.apache.bcel.classfile.SourceFile;
import org.apache.bcel.classfile.StackMap;
@@ -397,6 +399,16 @@ public void visitParameterAnnotationEntry(final ParameterAnnotationEntry obj) {
tostring = toString(obj);
}
+ @Override
+ public void visitRecord(final Record obj) {
+ tostring = toString(obj);
+ }
+
+ @Override
+ public void visitRecordComponent(final RecordComponentInfo obj) {
+ tostring = toString(obj);
+ }
+
@Override
public void visitSignature(final Signature obj) {
tostring = toString(obj);
@@ -429,4 +441,5 @@ public void visitSynthetic(final Synthetic obj) {
public void visitUnknown(final Unknown obj) {
tostring = toString(obj);
}
+
}
diff --git a/src/main/java/org/apache/bcel/verifier/structurals/Frame.java b/src/main/java/org/apache/bcel/verifier/structurals/Frame.java
index b847b4d498..24da459e60 100644
--- a/src/main/java/org/apache/bcel/verifier/structurals/Frame.java
+++ b/src/main/java/org/apache/bcel/verifier/structurals/Frame.java
@@ -48,17 +48,14 @@ public static void setThis(final UninitializedObjectType _this) {
}
/**
- *
*/
private final LocalVariables locals;
/**
- *
*/
private final OperandStack stack;
/**
- *
*/
public Frame(final int maxLocals, final int maxStack) {
locals = new LocalVariables(maxLocals);
@@ -66,7 +63,6 @@ public Frame(final int maxLocals, final int maxStack) {
}
/**
- *
*/
public Frame(final LocalVariables locals, final OperandStack stack) {
this.locals = locals;
@@ -74,7 +70,6 @@ public Frame(final LocalVariables locals, final OperandStack stack) {
}
/**
- *
*/
@Override
protected Object clone() {
@@ -82,7 +77,6 @@ protected Object clone() {
}
/**
- *
*/
@Override
public boolean equals(final Object o) {
@@ -94,21 +88,18 @@ public boolean equals(final Object o) {
}
/**
- *
*/
public Frame getClone() {
return (Frame) clone();
}
/**
- *
*/
public LocalVariables getLocals() {
return locals;
}
/**
- *
*/
public OperandStack getStack() {
return stack;
@@ -127,10 +118,10 @@ public int hashCode() {
*/
@Override
public String toString() {
- String s = "Local Variables:\n";
- s += locals;
- s += "OperandStack:\n";
- s += stack;
- return s;
+ final StringBuilder s = new StringBuilder("Local Variables:\n");
+ s.append(locals);
+ s.append("OperandStack:\n");
+ s.append(stack);
+ return s.toString();
}
}
diff --git a/src/main/java/org/apache/bcel/verifier/structurals/LocalVariables.java b/src/main/java/org/apache/bcel/verifier/structurals/LocalVariables.java
index 9f9c887fb9..1b27bb6769 100644
--- a/src/main/java/org/apache/bcel/verifier/structurals/LocalVariables.java
+++ b/src/main/java/org/apache/bcel/verifier/structurals/LocalVariables.java
@@ -16,12 +16,11 @@
*/
package org.apache.bcel.verifier.structurals;
-import java.util.Arrays;
-
import org.apache.bcel.generic.ReferenceType;
import org.apache.bcel.generic.Type;
import org.apache.bcel.verifier.exc.AssertionViolatedException;
import org.apache.bcel.verifier.exc.StructuralCodeConstraintException;
+import org.apache.commons.lang3.ArrayFill;
/**
* This class implements an array of local variables used for symbolic JVM simulation.
@@ -37,8 +36,7 @@ public class LocalVariables implements Cloneable {
* @param localVariableCount local variable count.
*/
public LocalVariables(final int localVariableCount) {
- locals = new Type[localVariableCount];
- Arrays.fill(locals, Type.UNKNOWN);
+ locals = ArrayFill.fill(new Type[localVariableCount], Type.UNKNOWN);
}
/**
diff --git a/src/main/java/org/apache/bcel/verifier/structurals/UninitializedObjectType.java b/src/main/java/org/apache/bcel/verifier/structurals/UninitializedObjectType.java
index c045ac9b23..8a040783a2 100644
--- a/src/main/java/org/apache/bcel/verifier/structurals/UninitializedObjectType.java
+++ b/src/main/java/org/apache/bcel/verifier/structurals/UninitializedObjectType.java
@@ -43,7 +43,6 @@ public UninitializedObjectType(final ObjectType objectType) {
/**
* Returns true on equality of this and o. Equality means the ObjectType instances of "initialized" equal one another in
* this and the o instance.
- *
*/
@Override
public boolean equals(final Object o) {
diff --git a/src/site/xdoc/download_bcel.xml b/src/site/xdoc/download_bcel.xml
index 4d6c7b02a2..1aee8987df 100644
--- a/src/site/xdoc/download_bcel.xml
+++ b/src/site/xdoc/download_bcel.xml
@@ -113,32 +113,32 @@ limitations under the License.
-
+
- bcel-6.8.1-bin.tar.gz
- sha512
- pgp
+ bcel-6.9.0-bin.tar.gz
+ sha512
+ pgp
- bcel-6.8.1-bin.zip
- sha512
- pgp
+ bcel-6.9.0-bin.zip
+ sha512
+ pgp
- bcel-6.8.1-src.tar.gz
- sha512
- pgp
+ bcel-6.9.0-src.tar.gz
+ sha512
+ pgp
- bcel-6.8.1-src.zip
- sha512
- pgp
+ bcel-6.9.0-src.zip
+ sha512
+ pgp
diff --git a/src/site/xdoc/index.xml b/src/site/xdoc/index.xml
index da5692d481..e1bbcee28c 100644
--- a/src/site/xdoc/index.xml
+++ b/src/site/xdoc/index.xml
@@ -1,87 +1,87 @@
-
-
-
-
-
- Home
- Commons Documentation Team
-
-
-
-
- The Byte Code Engineering Library (Apache Commons BCEL™) is intended to give users a
- convenient way to analyze, create, and manipulate (binary)
- Java class files (those ending with .class). Classes are
- represented by objects which contain all the symbolic information
- of the given class: methods, fields and byte code instructions, in
- particular.
-
-
- Such objects can be read from an existing file, be transformed
- by a program (e.g. a class loader at run-time) and written to a file again.
- An even more interesting application is the creation of classes from scratch
- at run-time. The Byte Code Engineering Library (BCEL) may be also useful
- if you want to learn about the Java Virtual Machine (JVM) and the format of
- Java .class files.
-
-
- BCEL contains a byte code verifier named JustIce, which usually
- gives you much better information about what's wrong with your
- code than the standard JVM message.
-
-
- BCEL is already being used successfully in several projects such
- as compilers, optimizers, obsfuscators, code generators
- and analysis tools. Unfortunately there hasn't been much development
- going on over the past few years. Feel free to help out or you
- might want to have a look into the ASM project at objectweb.
-
-
-
-
- The package descriptions in the Javadoc give an overview of the available features
- and various project reports are provided.
-
-
- The source repository can be
- browsed, or you can browse/contribute via GitHub.
-
-
-
- The latest stable release of BCEL is here, you may:
-
- - Download
- - Read the release notes
- - Inspect the extended Clirr report comparing 5.2 with 6.x
-
-
- Alternatively, you can pull it from the central Maven repositories through a dependency.
-
-
-
-
-
- The commons developer mailing list is the main channel of communication for contributors. Please remember that the lists are shared between all commons components, so prefix your email by [bcel].
- You can also peruse JIRA.
- Alternatively you can go through the Needs Work tags in the TagList report.
- If you'd like to offer up pull requests via GitHub rather than applying patches to JIRA, we have a GitHub mirror.
-
-
-
+
+
+
+
+
+ Home
+ Commons Documentation Team
+
+
+
+
+ The Byte Code Engineering Library (Apache Commons BCEL™) is intended to give users a
+ convenient way to analyze, create, and manipulate (binary)
+ Java class files (those ending with .class). Classes are
+ represented by objects which contain all the symbolic information
+ of the given class: methods, fields and byte code instructions, in
+ particular.
+
+
+ Such objects can be read from an existing file, be transformed
+ by a program (e.g. a class loader at run-time) and written to a file again.
+ An even more interesting application is the creation of classes from scratch
+ at run-time. The Byte Code Engineering Library (BCEL) may be also useful
+ if you want to learn about the Java Virtual Machine (JVM) and the format of
+ Java .class files.
+
+
+ BCEL contains a byte code verifier named JustIce, which usually
+ gives you much better information about what's wrong with your
+ code than the standard JVM message.
+
+
+ BCEL is already being used successfully in several projects such
+ as compilers, optimizers, obsfuscators, code generators
+ and analysis tools. Unfortunately there hasn't been much development
+ going on over the past few years. Feel free to help out or you
+ might want to have a look into the ASM project at objectweb.
+
+
+
+
+ The package descriptions in the Javadoc give an overview of the available features
+ and various project reports are provided.
+
+
+ The source repository can be
+ browsed, or you can browse/contribute via GitHub.
+
+
+
+ The latest stable release of BCEL is here, you may:
+
+ - Download
+ - Read the release notes
+ - Inspect the extended Clirr report comparing 5.2 with 6.x
+
+
+ Alternatively, you can pull it from the central Maven repositories through a dependency.
+
+
+
+
+
+ The commons developer mailing list is the main channel of communication for contributors. Please remember that the lists are shared between all commons components, so prefix your email by [bcel].
+ You can also peruse JIRA.
+ Alternatively you can go through the Needs Work tags in the TagList report.
+ If you'd like to offer up pull requests via GitHub rather than applying patches to JIRA, we have a GitHub mirror.
+
+
+
diff --git a/src/test/java/org/apache/bcel/CounterVisitorTestCase.java b/src/test/java/org/apache/bcel/CounterVisitorTestCase.java
index d1fcfa5e35..6ecf3da8b9 100644
--- a/src/test/java/org/apache/bcel/CounterVisitorTestCase.java
+++ b/src/test/java/org/apache/bcel/CounterVisitorTestCase.java
@@ -183,6 +183,11 @@ public void testParameterAnnotationCount() {
assertEquals(0, getVisitor().parameterAnnotationCount, "parameterAnnotationCount");
}
+ @Test
+ public void testRecordCount() {
+ assertEquals(0, getVisitor().recordCount, "recordCount");
+ }
+
@Test
public void testSignatureCount() {
assertEquals(0, getVisitor().signatureAnnotationCount, "signatureAnnotationCount");
diff --git a/src/test/java/org/apache/bcel/HandleTestCase.java b/src/test/java/org/apache/bcel/HandleTestCase.java
index d2fbb737a7..6646c4e0ae 100644
--- a/src/test/java/org/apache/bcel/HandleTestCase.java
+++ b/src/test/java/org/apache/bcel/HandleTestCase.java
@@ -1,148 +1,148 @@
-/*
- * 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;
-
-import org.apache.bcel.generic.GOTO;
-import org.apache.bcel.generic.ILOAD;
-import org.apache.bcel.generic.InstructionHandle;
-import org.apache.bcel.generic.InstructionList;
-import org.apache.bcel.generic.NOP;
-import org.junit.jupiter.api.Test;
-
-/**
- * Test for https://issues.apache.org/jira/browse/BCEL-267 "Race conditions on static fields in BranchHandle and
- * InstructionHandle".
- */
-public class HandleTestCase {
-
- static Throwable exception;
- static final int MAXI = 100;
- static final int MAXJ = 1000;
-
- /**
- * Asserts that branch handles can be added an instruction list, without corrupting the list.
- */
- static void branchHandles() {
- for (int i = 0; i < MAXI; i++) {
- final InstructionList list = new InstructionList();
- final InstructionHandle start = list.append(new NOP());
- try {
- for (int j = 0; j < MAXJ; j++) {
- list.append(new GOTO(start));
- }
- final InstructionHandle[] instructionHandles = list.getInstructionHandles();
- for (int j = 0; j < instructionHandles.length; j++) {
- final InstructionHandle handle = instructionHandles[j];
- if (j > 0) {
- checkLinkage(handle, j);
- if (start != ((GOTO) handle.getInstruction()).getTarget()) {
- final AssertionError error = new AssertionError("unexpected instruction at index " + j);
- exception = error;
- throw error;
- }
- }
- }
- if (exception != null) {
- return;
- }
- } catch (final NullPointerException e) {
- System.out.println("NPE at i=" + i);
- exception = e;
- throw e;
- }
- list.dispose(); // this initializes caching of unused instruction handles
- }
- }
-
- /**
- * Assert that opposite next/prev pairs always match.
- */
- static void checkLinkage(final InstructionHandle ih, final int index) {
- final InstructionHandle prev = ih.getPrev();
- final InstructionHandle next = ih.getNext();
- if (prev != null && prev.getNext() != ih || next != null && next.getPrev() != ih) {
- final AssertionError error = new AssertionError("corrupt instruction list at index " + index);
- exception = error;
- throw error;
- }
- }
-
- /**
- * Asserts that instruction handles can be added an instruction list, without corrupting the list.
- */
- static void handles() {
- for (int i = 0; i < MAXI; i++) {
- final InstructionList list = new InstructionList();
- try {
- for (int j = 0; j < MAXJ; j++) {
- list.append(new ILOAD(j));
- }
- final InstructionHandle[] instructionHandles = list.getInstructionHandles();
- for (int j = 0; j < instructionHandles.length; j++) {
- final InstructionHandle handle = instructionHandles[j];
- checkLinkage(handle, j);
- if (j != ((ILOAD) handle.getInstruction()).getIndex()) {
- final AssertionError error = new AssertionError("unexpected instruction at index " + j);
- exception = error;
- throw error;
- }
- }
- if (exception != null) {
- return;
- }
- } catch (final NullPointerException e) {
- System.out.println("NPE at i=" + i);
- exception = e;
- throw e;
- }
- list.dispose(); // this initializes caching of unused instruction handles
- }
- }
-
- /**
- * Concurrently run the given runnable in two threads.
- */
- private void perform(final Runnable r) throws Throwable {
- exception = null;
- final Thread t1 = new Thread(r);
- final Thread t2 = new Thread(r);
- t1.start();
- t2.start();
- t1.join();
- t2.join();
- if (exception != null) {
- throw exception;
- }
- }
-
- /**
- * Assert that two independent instruction lists can be modified concurrently. Here: inserting branch instructions.
- */
- @Test
- public void testBranchHandle() throws Throwable {
- perform(HandleTestCase::branchHandles);
- }
-
- /**
- * Assert that two independent instruction lists can be modified concurrently. Here: inserting regular instructions.
- */
- @Test
- public void testInstructionHandle() throws Throwable {
- perform(HandleTestCase::handles);
- }
-}
+/*
+ * 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;
+
+import org.apache.bcel.generic.GOTO;
+import org.apache.bcel.generic.ILOAD;
+import org.apache.bcel.generic.InstructionHandle;
+import org.apache.bcel.generic.InstructionList;
+import org.apache.bcel.generic.NOP;
+import org.junit.jupiter.api.Test;
+
+/**
+ * Test for https://issues.apache.org/jira/browse/BCEL-267 "Race conditions on static fields in BranchHandle and
+ * InstructionHandle".
+ */
+public class HandleTestCase {
+
+ static Throwable exception;
+ static final int MAXI = 100;
+ static final int MAXJ = 1000;
+
+ /**
+ * Asserts that branch handles can be added an instruction list, without corrupting the list.
+ */
+ static void branchHandles() {
+ for (int i = 0; i < MAXI; i++) {
+ final InstructionList list = new InstructionList();
+ final InstructionHandle start = list.append(new NOP());
+ try {
+ for (int j = 0; j < MAXJ; j++) {
+ list.append(new GOTO(start));
+ }
+ final InstructionHandle[] instructionHandles = list.getInstructionHandles();
+ for (int j = 0; j < instructionHandles.length; j++) {
+ final InstructionHandle handle = instructionHandles[j];
+ if (j > 0) {
+ checkLinkage(handle, j);
+ if (start != ((GOTO) handle.getInstruction()).getTarget()) {
+ final AssertionError error = new AssertionError("unexpected instruction at index " + j);
+ exception = error;
+ throw error;
+ }
+ }
+ }
+ if (exception != null) {
+ return;
+ }
+ } catch (final NullPointerException e) {
+ System.out.println("NPE at i=" + i);
+ exception = e;
+ throw e;
+ }
+ list.dispose(); // this initializes caching of unused instruction handles
+ }
+ }
+
+ /**
+ * Assert that opposite next/prev pairs always match.
+ */
+ static void checkLinkage(final InstructionHandle ih, final int index) {
+ final InstructionHandle prev = ih.getPrev();
+ final InstructionHandle next = ih.getNext();
+ if (prev != null && prev.getNext() != ih || next != null && next.getPrev() != ih) {
+ final AssertionError error = new AssertionError("corrupt instruction list at index " + index);
+ exception = error;
+ throw error;
+ }
+ }
+
+ /**
+ * Asserts that instruction handles can be added an instruction list, without corrupting the list.
+ */
+ static void handles() {
+ for (int i = 0; i < MAXI; i++) {
+ final InstructionList list = new InstructionList();
+ try {
+ for (int j = 0; j < MAXJ; j++) {
+ list.append(new ILOAD(j));
+ }
+ final InstructionHandle[] instructionHandles = list.getInstructionHandles();
+ for (int j = 0; j < instructionHandles.length; j++) {
+ final InstructionHandle handle = instructionHandles[j];
+ checkLinkage(handle, j);
+ if (j != ((ILOAD) handle.getInstruction()).getIndex()) {
+ final AssertionError error = new AssertionError("unexpected instruction at index " + j);
+ exception = error;
+ throw error;
+ }
+ }
+ if (exception != null) {
+ return;
+ }
+ } catch (final NullPointerException e) {
+ System.out.println("NPE at i=" + i);
+ exception = e;
+ throw e;
+ }
+ list.dispose(); // this initializes caching of unused instruction handles
+ }
+ }
+
+ /**
+ * Concurrently run the given runnable in two threads.
+ */
+ private void perform(final Runnable r) throws Throwable {
+ exception = null;
+ final Thread t1 = new Thread(r);
+ final Thread t2 = new Thread(r);
+ t1.start();
+ t2.start();
+ t1.join();
+ t2.join();
+ if (exception != null) {
+ throw exception;
+ }
+ }
+
+ /**
+ * Assert that two independent instruction lists can be modified concurrently. Here: inserting branch instructions.
+ */
+ @Test
+ public void testBranchHandle() throws Throwable {
+ perform(HandleTestCase::branchHandles);
+ }
+
+ /**
+ * Assert that two independent instruction lists can be modified concurrently. Here: inserting regular instructions.
+ */
+ @Test
+ public void testInstructionHandle() throws Throwable {
+ perform(HandleTestCase::handles);
+ }
+}
diff --git a/src/test/java/org/apache/bcel/classfile/ConstantPoolModuleToStringTestCase.java b/src/test/java/org/apache/bcel/classfile/ConstantPoolModuleToStringTestCase.java
index e7f08c96eb..b63564b58e 100644
--- a/src/test/java/org/apache/bcel/classfile/ConstantPoolModuleToStringTestCase.java
+++ b/src/test/java/org/apache/bcel/classfile/ConstantPoolModuleToStringTestCase.java
@@ -506,7 +506,8 @@ public void test(final String first) throws Exception {
@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.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
diff --git a/src/test/java/org/apache/bcel/classfile/RecordTestCase.java b/src/test/java/org/apache/bcel/classfile/RecordTestCase.java
new file mode 100644
index 0000000000..8056250a7d
--- /dev/null
+++ b/src/test/java/org/apache/bcel/classfile/RecordTestCase.java
@@ -0,0 +1,121 @@
+/*
+ * 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.classfile;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+
+import java.io.File;
+import java.io.IOException;
+
+import org.apache.bcel.AbstractTestCase;
+import org.apache.bcel.util.SyntheticRepository;
+import org.apache.bcel.visitors.CountingVisitor;
+import org.junit.jupiter.api.Test;
+
+public class RecordTestCase extends AbstractTestCase {
+
+ /**
+ * Check that we can copy a attribute correctly.
+ */
+ @Test
+ public void recordsCanBeCopied() throws ClassNotFoundException, IOException {
+ final JavaClass clazz = new ClassParser("src/test/resources/record/SimpleRecord.class").parse();
+ final JavaClass copyClazz = clazz.copy();
+ assertEquals(clazz.toString(), copyClazz.toString(), "both records should have the same value");
+ }
+
+ /**
+ * Check that a record can be visited by our visitors
+ */
+ @Test
+ public void recordsCanBeVisited() throws ClassNotFoundException, IOException {
+ final JavaClass clazz = new ClassParser("src/test/resources/record/SimpleRecord.class").parse();
+ final CountingVisitor countVisitor = new CountingVisitor();
+ final DescendingVisitor desendingVisitor = new DescendingVisitor(clazz, countVisitor);
+ desendingVisitor.visit();
+ assertEquals(1,countVisitor.recordCount, "should count one record");
+ assertEquals(2,countVisitor.recordComponentCount, "should count two record components");
+ }
+
+
+ /**
+ * Check that we can save and load the attribute correctly.
+ */
+ @Test
+ public void testAttributeSerializtion() throws ClassNotFoundException, IOException {
+ final JavaClass clazz = new ClassParser("src/test/resources/record/SimpleRecord.class").parse();
+ final File tfile = createTestdataFile("SimpleRecord.class");
+ final Record recordAttribute = (Record)findAttribute("Record",clazz)[0];
+ clazz.dump(tfile);
+ // Read in the new version and check it is OK
+ final SyntheticRepository repos2 = createRepos(".");
+ final JavaClass clazzFromRepo = repos2.loadClass("SimpleRecord");
+ assertNotNull(clazzFromRepo); // Use the variable to avoid a warning
+ final Record recordAttributeFromRepo = (Record)findAttribute("Record",clazzFromRepo)[0];
+ assertEquals(recordAttribute.toString(), recordAttributeFromRepo.toString(), "Both attributes needs to be equal");
+ tfile.deleteOnExit();
+ }
+
+ /**
+ * A record type, once compiled, should result in a class file that is
+ * marked such that we can determine from the access flags
+ * (through BCEL) that it is in fact a record.
+ *
+ * @throws IOException
+ * @throws ClassFormatException
+ */
+ @Test
+ public void testRecordClassSaysItIs() throws ClassNotFoundException, ClassFormatException, IOException {
+ final JavaClass clazz = new ClassParser("src/test/resources/record/SimpleRecord.class").parse();
+ assertTrue(clazz.isRecord(), "Expected SimpleRecord class to say it was a record - but it didn't !");
+ final JavaClass simpleClazz = getTestJavaClass(PACKAGE_BASE_NAME + ".data.SimpleClass");
+ assertFalse(simpleClazz.isRecord(), "Expected SimpleClass class to say it was not a record - but it didn't !");
+ }
+
+ /**
+ * A simple record with two simple fields, an integer and a String field, should
+ * show its content in its string representation.
+ *
+ * @throws ClassNotFoundException
+ * @throws ClassFormatException
+ * @throws IOException
+ */
+ @Test
+ public void testRecordToString() throws ClassNotFoundException, ClassFormatException, IOException {
+ final JavaClass clazz = new ClassParser("src/test/resources/record/SimpleRecord.class").parse();
+ final Attribute[] attributes = clazz.getAttributes();
+ final Record recordAttribute = (Record) findAttribute("Record",clazz)[0];
+ assertEquals(4, attributes.length);
+ assertEquals("SourceFile: SimpleRecord.java", attributes[0].toString());
+ assertEquals("Record(2):\n"
+ + " RecordComponentInfo(aNumber,I,0):\n"
+ + " RecordComponentInfo(aString,Ljava/lang/String;,1):\n"
+ + " RuntimeVisibleAnnotations:\n"
+ + " @Ljavax/annotation/Nonnull;"
+ ,recordAttribute.toString());
+ final RecordComponentInfo firstComponent = recordAttribute.getComponents()[0];
+ assertEquals(5, firstComponent.getIndex());
+ assertEquals(6, firstComponent.getDescriptorIndex());
+ assertEquals(0, firstComponent.getAttributes().length);
+ assertEquals(recordAttribute.getConstantPool(),firstComponent.getConstantPool());
+ assertEquals("RecordComponentInfo(aNumber,I,0):", firstComponent.toString());
+ }
+
+}
diff --git a/src/test/java/org/apache/bcel/classfile/UtilityTestCase.java b/src/test/java/org/apache/bcel/classfile/UtilityTestCase.java
index 8c3144b66e..7d6095d0c2 100644
--- a/src/test/java/org/apache/bcel/classfile/UtilityTestCase.java
+++ b/src/test/java/org/apache/bcel/classfile/UtilityTestCase.java
@@ -20,6 +20,7 @@
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertNull;
import static org.junit.jupiter.api.Assertions.assertTrue;
import java.util.Arrays;
@@ -59,7 +60,10 @@ final class CodeToString {
final String code = method.getCode().toString(false);
assertTrue(code.contains("0: aload_0"), code);
assertTrue(code.contains("1: aload_1"), code);
- assertTrue(code.contains("2: putfield\t\torg.apache.bcel.classfile.UtilityTestCase$1CodeToString.this$0 Lorg/apache/bcel/classfile/UtilityTestCase;"), code);
+ assertTrue(
+ code.contains(
+ "2: putfield\t\torg.apache.bcel.classfile.UtilityTestCase$1CodeToString.this$0 Lorg/apache/bcel/classfile/UtilityTestCase;"),
+ code);
assertTrue(code.contains("5: aload_0"), code);
assertTrue(code.contains("6: invokespecial\tjava.lang.Object. ()V"), code);
assertTrue(code.contains("9: aload_0"), code);
@@ -105,14 +109,14 @@ public void testIsSet() {
@Test
public void testPrintArray() {
- assertEquals(null, Utility.printArray(null, false, false));
+ assertNull(Utility.printArray(null, false, false));
assertEquals("", Utility.printArray(new Object[0], false, false));
assertEquals("{}", Utility.printArray(new Object[0], true, false));
- assertEquals("null", Utility.printArray(new Object[]{null}, false, false));
- assertEquals("a, b", Utility.printArray(new String[]{"a", "b"}, false, false));
- assertEquals("{a, b}", Utility.printArray(new String[]{"a", "b"}, true, false));
- assertEquals("\"a\", \"b\"", Utility.printArray(new String[]{"a", "b"}, false, true));
- assertEquals("{\"a\", \"b\"}", Utility.printArray(new String[]{"a", "b"}, true, true));
+ assertEquals("null", Utility.printArray(new Object[] { null }, false, false));
+ assertEquals("a, b", Utility.printArray(new String[] { "a", "b" }, false, false));
+ assertEquals("{a, b}", Utility.printArray(new String[] { "a", "b" }, true, false));
+ assertEquals("\"a\", \"b\"", Utility.printArray(new String[] { "a", "b" }, false, true));
+ assertEquals("{\"a\", \"b\"}", Utility.printArray(new String[] { "a", "b" }, true, true));
}
@Test
@@ -141,35 +145,35 @@ public void testSignatureToStringWithGenerics() throws Exception {
// tests for BCEL-197
assertEquals("java.util.Map>", Utility.signatureToString("Ljava/util/Map;>;"), "generic signature");
assertEquals("java.util.Set extends java.nio.file.OpenOption>", Utility.signatureToString("Ljava/util/Set<+Ljava/nio/file/OpenOption;>;"),
- "generic signature");
+ "generic signature");
assertEquals("java.nio.file.attribute.FileAttribute>[]", Utility.signatureToString("[Ljava/nio/file/attribute/FileAttribute<*>;"),
- "generic signature");
+ "generic signature");
// tests for BCEL-286
assertEquals(
- "boofcv.alg.tracker.tld.TldTracker, boofcv.struct.image.GrayI>",
+ "boofcv.alg.tracker.tld.TldTracker, boofcv.struct.image.GrayI>",
Utility.signatureToString(
- "Lboofcv/alg/tracker/tld/TldTracker;Lboofcv/struct/image/GrayI;>;"),
- "generic signature");
+ "Lboofcv/alg/tracker/tld/TldTracker;Lboofcv/struct/image/GrayI;>;"),
+ "generic signature");
assertEquals("java.util.Map, ?>", Utility.signatureToString("Ljava/util/Map<**>;"), "generic signature");
assertEquals("com.jme3.util.IntMap.IntMapIterator", Utility.signatureToString("Lcom/jme3/util/IntMap.IntMapIterator;"), "generic signature");
// tests for BCEL-279
assertEquals("(com.google.common.io.ByteProcessor, int)T",
- Utility.signatureToString("(Lcom/google/common/io/ByteProcessor;I)TT;", false), "type parameters signature");
+ Utility.signatureToString("(Lcom/google/common/io/ByteProcessor;I)TT;", false), "type parameters signature");
assertEquals("(com.google.common.io.ByteProcessor, int)T",
- Utility.signatureToString("(Lcom/google/common/io/ByteProcessor;I)TT;", true), "type parameters signature");
+ Utility.signatureToString("(Lcom/google/common/io/ByteProcessor;I)TT;", true), "type parameters signature");
assertEquals("(M)void",
- Utility.signatureToString("(TM;)V"), "type parameters signature");
+ Utility.signatureToString("(TM;)V"), "type parameters signature");
assertEquals("()com.google.common.cache.Weigher",
- Utility.signatureToString("()Lcom/google/common/cache/Weigher;"), "type parameters signature");
+ Utility.signatureToString("()Lcom/google/common/cache/Weigher;"), "type parameters signature");
assertEquals("(com.google.common.cache.Weigher super K1, ? super V1>)com.google.common.cache.CacheBuilder",
- Utility.signatureToString("(Lcom/google/common/cache/Weigher<-TK1;-TV1;>;)Lcom/google/common/cache/CacheBuilder;"),
- "type parameters signature");
+ Utility.signatureToString("(Lcom/google/common/cache/Weigher<-TK1;-TV1;>;)Lcom/google/common/cache/CacheBuilder;"),
+ "type parameters signature");
assertEquals(" extends java.lang.Object implements com.google.common.graph.Network",
- Utility.signatureToString("Ljava/lang/Object;Lcom/google/common/graph/Network;", false),
- "class signature");
+ Utility.signatureToString("Ljava/lang/Object;Lcom/google/common/graph/Network;", false),
+ "class signature");
assertEquals(" extends Object",
- Utility.signatureToString("Ljava/lang/Object;"), "class signature");
+ Utility.signatureToString("Ljava/lang/Object;"), "class signature");
}
}
diff --git a/src/test/java/org/apache/bcel/data/PLSETestClass2.java b/src/test/java/org/apache/bcel/data/PLSETestClass2.java
index d54b9a55a9..b771e2015a 100644
--- a/src/test/java/org/apache/bcel/data/PLSETestClass2.java
+++ b/src/test/java/org/apache/bcel/data/PLSETestClass2.java
@@ -1,29 +1,29 @@
-/*
- * 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.data;
-
-public class PLSETestClass2 {
- public static void main(final String[] args) {
- @SuppressWarnings("unused")
- int t = 0;
-
- for (int i = 0; i < 100; i++) {
- t += i;
- }
- }
-}
+/*
+ * 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.data;
+
+public class PLSETestClass2 {
+ public static void main(final String[] args) {
+ @SuppressWarnings("unused")
+ int t = 0;
+
+ for (int i = 0; i < 100; i++) {
+ t += i;
+ }
+ }
+}
diff --git a/src/test/java/org/apache/bcel/generic/EmptyVisitorTestCase.java b/src/test/java/org/apache/bcel/generic/EmptyVisitorTestCase.java
index cdbb808bb5..15647fcf66 100644
--- a/src/test/java/org/apache/bcel/generic/EmptyVisitorTestCase.java
+++ b/src/test/java/org/apache/bcel/generic/EmptyVisitorTestCase.java
@@ -38,9 +38,19 @@ final class EmptyVisitorTestCase {
@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_ICMPGT, IF_ICMPLE, IF_ICMPLT, IF_ICMPNE, IINC, ILOAD, IMUL, INEG, INSTANCEOF, INVOKESPECIAL, INVOKESTATIC, INVOKEVIRTUAL, IOR, IREM, IRETURN, ISHL, ISHR, ISTORE, ISUB, IUSHR, IXOR, L2D, L2F, L2I, LADD, LALOAD, LAND, LASTORE, LCMP, LCONST, LDC, LDC2_W, LDC_W, LDIV, LLOAD, LMUL, LNEG, LOOKUPSWITCH, LOR, LREM, LRETURN, LSHL, LSHR, LSTORE, LSUB, LUSHR, NEW, NEWARRAY, POP, PUTFIELD, PUTSTATIC, RETURN, SIPUSH]
- "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.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_ICMPGT, IF_ICMPLE, IF_ICMPLT, IF_ICMPNE,
+ // IINC, ILOAD, IMUL, INEG, INSTANCEOF, INVOKESPECIAL, INVOKESTATIC, INVOKEVIRTUAL, IOR, IREM,
+ // IRETURN, ISHL, ISHR, ISTORE, ISUB, IUSHR, IXOR, L2D, L2F, L2I, LADD, LALOAD, LAND, LASTORE, LCMP,
+ // LCONST, LDC, LDC2_W, LDC_W, LDIV, LLOAD, LMUL, LNEG, LOOKUPSWITCH, LOR, LREM, LRETURN, LSHL, LSHR,
+ // LSTORE, LSUB, LUSHR, NEW, NEWARRAY, POP, PUTFIELD, PUTSTATIC, RETURN, SIPUSH]
+ "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
diff --git a/src/test/java/org/apache/bcel/generic/GeneratingAnnotatedClassesTestCase.java b/src/test/java/org/apache/bcel/generic/GeneratingAnnotatedClassesTestCase.java
index 762f6fdbb2..056453c1b0 100644
--- a/src/test/java/org/apache/bcel/generic/GeneratingAnnotatedClassesTestCase.java
+++ b/src/test/java/org/apache/bcel/generic/GeneratingAnnotatedClassesTestCase.java
@@ -291,8 +291,7 @@ public AnnotationEntryGen createSimpleInvisibleAnnotation(final ConstantPoolGen
final ObjectType t = new ObjectType("SimpleAnnotation");
final List elements = new ArrayList<>();
elements.add(nvGen);
- final AnnotationEntryGen a = new AnnotationEntryGen(t, elements, false, cp);
- return a;
+ return new AnnotationEntryGen(t, elements, false, cp);
}
public AnnotationEntryGen createSimpleVisibleAnnotation(final ConstantPoolGen cp) {
@@ -301,8 +300,7 @@ public AnnotationEntryGen createSimpleVisibleAnnotation(final ConstantPoolGen cp
final ObjectType t = new ObjectType("SimpleAnnotation");
final List elements = new ArrayList<>();
elements.add(nvGen);
- final AnnotationEntryGen a = new AnnotationEntryGen(t, elements, true, cp);
- return a;
+ return new AnnotationEntryGen(t, elements, true, cp);
}
private void dumpClass(final ClassGen cg, final String fname) {
diff --git a/src/test/java/org/apache/bcel/generic/InstructionFactoryTestCase.java b/src/test/java/org/apache/bcel/generic/InstructionFactoryTestCase.java
index 84782d6743..6b07992dcb 100644
--- a/src/test/java/org/apache/bcel/generic/InstructionFactoryTestCase.java
+++ b/src/test/java/org/apache/bcel/generic/InstructionFactoryTestCase.java
@@ -62,6 +62,12 @@ public void testArrayStore() throws Exception {
assertEquals(InstructionConst.AASTORE, createArrayStore(Type.getType("[I")));
}
+ @Test
+ public void testCreateInvokeNullArgTypes() throws Exception {
+ final InstructionFactory factory = new InstructionFactory(new ClassGen(Repository.lookupClass(Object.class)));
+ factory.createInvoke("", "", Type.VOID, null, Const.INVOKESPECIAL, false); // Mustn't throw an NPE
+ }
+
@Test
public void testExceptions() throws Exception {
final InstructionFactory factory = new InstructionFactory(new ClassGen(Repository.lookupClass(Object.class)));
diff --git a/src/test/java/org/apache/bcel/generic/TypeTestCase.java b/src/test/java/org/apache/bcel/generic/TypeTestCase.java
index 303a75ba4c..043ed2d692 100644
--- a/src/test/java/org/apache/bcel/generic/TypeTestCase.java
+++ b/src/test/java/org/apache/bcel/generic/TypeTestCase.java
@@ -18,6 +18,7 @@
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertNull;
import org.apache.bcel.Repository;
import org.apache.bcel.classfile.Code;
@@ -41,7 +42,7 @@ public void testBCEL243() {
@Test
public void testInternalTypeNametoSignature() {
- assertEquals(null, Type.internalTypeNameToSignature(null));
+ assertNull(Type.internalTypeNameToSignature(null));
assertEquals("", Type.internalTypeNameToSignature(""));
assertEquals("TT;", Type.internalTypeNameToSignature("TT;"));
assertEquals("Ljava/lang/String;", Type.internalTypeNameToSignature("Ljava/lang/String;"));
diff --git a/src/test/java/org/apache/bcel/util/BCELifierTestCase.java b/src/test/java/org/apache/bcel/util/BCELifierTestCase.java
index 8ab68d6c6d..9e66445464 100644
--- a/src/test/java/org/apache/bcel/util/BCELifierTestCase.java
+++ b/src/test/java/org/apache/bcel/util/BCELifierTestCase.java
@@ -48,8 +48,7 @@ public class BCELifierTestCase extends AbstractTestCase {
private String canonHashRef(String input) {
input = input.replaceAll("#\\d+", "#n"); // numbers may vary in length
input = input.replaceAll(" +", " "); // collapse spaces
- input = input.replaceAll("//.+", ""); // comments may vary
- return input;
+ return input.replaceAll("//.+", "");
}
private String exec(final File workDir, final String... args) throws Exception {
diff --git a/src/test/java/org/apache/bcel/util/ClassPathTestCase.java b/src/test/java/org/apache/bcel/util/ClassPathTestCase.java
index 5a05bbc442..1ce94bdd9a 100644
--- a/src/test/java/org/apache/bcel/util/ClassPathTestCase.java
+++ b/src/test/java/org/apache/bcel/util/ClassPathTestCase.java
@@ -1,46 +1,46 @@
-/*
- * 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.util;
-
-import static org.junit.jupiter.api.Assertions.assertNotNull;
-
-import java.io.IOException;
-import java.io.InputStream;
-
-import org.apache.bcel.AbstractTestCase;
-import org.junit.jupiter.api.Test;
-
-public class ClassPathTestCase extends AbstractTestCase {
-
- @Test
- public void testGetClassFile() throws IOException {
- assertNotNull(ClassPath.SYSTEM_CLASS_PATH.getClassFile("java.lang.String"));
- }
-
- @Test
- public void testGetResource() {
- assertNotNull(ClassPath.SYSTEM_CLASS_PATH.getResource("java/lang/String.class"));
- }
-
- @Test
- public void testGetResourceAsStream() throws IOException {
- try (final InputStream inputStream = ClassPath.SYSTEM_CLASS_PATH.getResourceAsStream("java/lang/String.class")) {
- assertNotNull(inputStream);
- }
- }
-}
+/*
+ * 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.util;
+
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+
+import java.io.IOException;
+import java.io.InputStream;
+
+import org.apache.bcel.AbstractTestCase;
+import org.junit.jupiter.api.Test;
+
+public class ClassPathTestCase extends AbstractTestCase {
+
+ @Test
+ public void testGetClassFile() throws IOException {
+ assertNotNull(ClassPath.SYSTEM_CLASS_PATH.getClassFile("java.lang.String"));
+ }
+
+ @Test
+ public void testGetResource() {
+ assertNotNull(ClassPath.SYSTEM_CLASS_PATH.getResource("java/lang/String.class"));
+ }
+
+ @Test
+ public void testGetResourceAsStream() throws IOException {
+ try (final InputStream inputStream = ClassPath.SYSTEM_CLASS_PATH.getResourceAsStream("java/lang/String.class")) {
+ assertNotNull(inputStream);
+ }
+ }
+}
diff --git a/src/test/java/org/apache/bcel/util/ModularRuntimeImageTestCase.java b/src/test/java/org/apache/bcel/util/ModularRuntimeImageTestCase.java
index 3c986974cb..561bdb4ca8 100644
--- a/src/test/java/org/apache/bcel/util/ModularRuntimeImageTestCase.java
+++ b/src/test/java/org/apache/bcel/util/ModularRuntimeImageTestCase.java
@@ -1,75 +1,75 @@
-/*
- * 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.util;
-
-import static org.junit.jupiter.api.Assertions.assertFalse;
-import static org.junit.jupiter.api.Assertions.assertTrue;
-import static org.junit.jupiter.api.Assumptions.assumeTrue;
-
-import java.io.IOException;
-import java.nio.file.Path;
-import java.util.List;
-
-import org.apache.commons.lang3.JavaVersion;
-import org.apache.commons.lang3.SystemUtils;
-import org.junit.jupiter.api.BeforeAll;
-import org.junit.jupiter.params.ParameterizedTest;
-import org.junit.jupiter.params.provider.MethodSource;
-
-/**
- * Tests {@link ModularRuntimeImage}.
- */
-public class ModularRuntimeImageTestCase {
-
- @BeforeAll
- public static void before() {
- assumeTrue(SystemUtils.isJavaVersionAtLeast(JavaVersion.JAVA_9));
- }
-
- @ParameterizedTest
- @MethodSource("org.apache.bcel.generic.JavaHome#streamModularRuntimeImage")
- public void testListJreModule(final ModularRuntimeImage modularRuntimeImage) throws IOException {
- final List listEntries = modularRuntimeImage.list(ModularRuntimeImage.MODULES_PATH + "/java.base");
- assertFalse(listEntries.isEmpty());
- assertTrue(listEntries.toString().indexOf("/java.base") > -1);
- }
-
- @ParameterizedTest
- @MethodSource("org.apache.bcel.generic.JavaHome#streamModularRuntimeImage")
- public void testListJreModulePackageDir(final ModularRuntimeImage modularRuntimeImage) throws IOException {
- final List listEntries = modularRuntimeImage.list(ModularRuntimeImage.MODULES_PATH + "/java.base/java/lang");
- assertFalse(listEntries.isEmpty());
- assertTrue(listEntries.toString().indexOf("/java.base/java/lang/String.class") > -1);
- }
-
- @ParameterizedTest
- @MethodSource("org.apache.bcel.generic.JavaHome#streamModularRuntimeImage")
- public void testListJreModules(final ModularRuntimeImage modularRuntimeImage) throws IOException {
- final List listEntries = modularRuntimeImage.list(ModularRuntimeImage.MODULES_PATH);
- assertFalse(listEntries.isEmpty());
- assertTrue(listEntries.toString().indexOf("/java.base") > -1);
- }
-
- @ParameterizedTest
- @MethodSource("org.apache.bcel.generic.JavaHome#streamModularRuntimeImage")
- public void testListJrePackages(final ModularRuntimeImage modularRuntimeImage) throws IOException {
- final List listEntries = modularRuntimeImage.list(ModularRuntimeImage.PACKAGES_PATH);
- assertFalse(listEntries.isEmpty());
- assertTrue(listEntries.toString().indexOf("java.lang") > -1);
- }
-}
+/*
+ * 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.util;
+
+import static org.junit.jupiter.api.Assertions.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+import static org.junit.jupiter.api.Assumptions.assumeTrue;
+
+import java.io.IOException;
+import java.nio.file.Path;
+import java.util.List;
+
+import org.apache.commons.lang3.JavaVersion;
+import org.apache.commons.lang3.SystemUtils;
+import org.junit.jupiter.api.BeforeAll;
+import org.junit.jupiter.params.ParameterizedTest;
+import org.junit.jupiter.params.provider.MethodSource;
+
+/**
+ * Tests {@link ModularRuntimeImage}.
+ */
+public class ModularRuntimeImageTestCase {
+
+ @BeforeAll
+ public static void before() {
+ assumeTrue(SystemUtils.isJavaVersionAtLeast(JavaVersion.JAVA_9));
+ }
+
+ @ParameterizedTest
+ @MethodSource("org.apache.bcel.generic.JavaHome#streamModularRuntimeImage")
+ public void testListJreModule(final ModularRuntimeImage modularRuntimeImage) throws IOException {
+ final List listEntries = modularRuntimeImage.list(ModularRuntimeImage.MODULES_PATH + "/java.base");
+ assertFalse(listEntries.isEmpty());
+ assertTrue(listEntries.toString().indexOf("/java.base") > -1);
+ }
+
+ @ParameterizedTest
+ @MethodSource("org.apache.bcel.generic.JavaHome#streamModularRuntimeImage")
+ public void testListJreModulePackageDir(final ModularRuntimeImage modularRuntimeImage) throws IOException {
+ final List listEntries = modularRuntimeImage.list(ModularRuntimeImage.MODULES_PATH + "/java.base/java/lang");
+ assertFalse(listEntries.isEmpty());
+ assertTrue(listEntries.toString().indexOf("/java.base/java/lang/String.class") > -1);
+ }
+
+ @ParameterizedTest
+ @MethodSource("org.apache.bcel.generic.JavaHome#streamModularRuntimeImage")
+ public void testListJreModules(final ModularRuntimeImage modularRuntimeImage) throws IOException {
+ final List listEntries = modularRuntimeImage.list(ModularRuntimeImage.MODULES_PATH);
+ assertFalse(listEntries.isEmpty());
+ assertTrue(listEntries.toString().indexOf("/java.base") > -1);
+ }
+
+ @ParameterizedTest
+ @MethodSource("org.apache.bcel.generic.JavaHome#streamModularRuntimeImage")
+ public void testListJrePackages(final ModularRuntimeImage modularRuntimeImage) throws IOException {
+ final List listEntries = modularRuntimeImage.list(ModularRuntimeImage.PACKAGES_PATH);
+ assertFalse(listEntries.isEmpty());
+ assertTrue(listEntries.toString().indexOf("java.lang") > -1);
+ }
+}
diff --git a/src/test/java/org/apache/bcel/verifier/JiraBcel369TestCase.java b/src/test/java/org/apache/bcel/verifier/JiraBcel369TestCase.java
index 5a8502d173..489481994c 100644
--- a/src/test/java/org/apache/bcel/verifier/JiraBcel369TestCase.java
+++ b/src/test/java/org/apache/bcel/verifier/JiraBcel369TestCase.java
@@ -34,7 +34,9 @@ public void testCompileAndVerify() throws ClassNotFoundException {
/**
* 3.7.0 fails with
* {@code
- * org.apache.bcel.verifier.exc.AssertionViolatedException: INTERNAL ERROR: Some RuntimeException occurred while verify()ing class 'issue369.Test', method 'public void (int arg1)'. Original RuntimeException's stack trace:
+ * org.apache.bcel.verifier.exc.AssertionViolatedException:
+ * INTERNAL ERROR: Some RuntimeException occurred while verify()ing class 'issue369.Test', method 'public void (int arg1)'.
+ * Original RuntimeException's stack trace:
---
org.apache.bcel.verifier.exc.AssertionViolatedException: INTERNAL ERROR: outFrame not set! This:
24: return [InstructionContext]
diff --git a/src/test/java/org/apache/bcel/verifier/VerifierTestCase.java b/src/test/java/org/apache/bcel/verifier/VerifierTestCase.java
index 951c0c8a47..314fb6b6d6 100644
--- a/src/test/java/org/apache/bcel/verifier/VerifierTestCase.java
+++ b/src/test/java/org/apache/bcel/verifier/VerifierTestCase.java
@@ -133,7 +133,7 @@ public void testDefinitionImpl() throws ClassNotFoundException {
@Test
public void testJvmOpCodes() throws ClassNotFoundException {
- testDefaultMethodValidation("org.apache.bcel.verifier.tests.JvmOpCodes");
+ testDefaultMethodValidation("org.apache.bcel.verifier.tests.JvmOpCodes");
}
@Test
@@ -160,6 +160,6 @@ public void testPackagePrivateStaticField() throws ClassNotFoundException {
@Test
public void testWSDL() throws IOException, URISyntaxException, ClassNotFoundException {
- testJarFile(getJarFile(javax.wsdl.Port.class), "WSDLReaderImpl", "DefinitionImpl");
+ testJarFile(getJarFile(javax.wsdl.Port.class), "WSDLReaderImpl", "DefinitionImpl");
}
}
diff --git a/src/test/java/org/apache/bcel/verifier/tests/JvmOpCodes.java b/src/test/java/org/apache/bcel/verifier/tests/JvmOpCodes.java
index b9b94e2ffc..1a6b99fc7c 100644
--- a/src/test/java/org/apache/bcel/verifier/tests/JvmOpCodes.java
+++ b/src/test/java/org/apache/bcel/verifier/tests/JvmOpCodes.java
@@ -41,7 +41,8 @@
*/
public class JvmOpCodes {
- long l1, l2;
+ long l1;
+ long l2;
/**
* Tests {@link DNEG}.
@@ -61,7 +62,7 @@ public class JvmOpCodes {
* Tests {@link DUP2}.
*/
long dup2(long a) {
- return a = a + 1;
+ return a++;
}
/**
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 097f859eb5..878709d3b8 100644
--- a/src/test/java/org/apache/bcel/verifier/tests/TestReturn03Creator.java
+++ b/src/test/java/org/apache/bcel/verifier/tests/TestReturn03Creator.java
@@ -39,7 +39,8 @@ public abstract class TestReturn03Creator extends TestCreator {
private final String genClassSuffix;
protected TestReturn03Creator(final Type returnType, final String genClassSuffix) {
- classGen = new ClassGen(TEST_PACKAGE + ".TestReturn03" + genClassSuffix, "java.lang.Object", "TestReturn03.java", Const.ACC_PUBLIC | Const.ACC_SUPER, new String[] {});
+ classGen = new ClassGen(TEST_PACKAGE + ".TestReturn03" + genClassSuffix, "java.lang.Object", "TestReturn03.java", Const.ACC_PUBLIC | Const.ACC_SUPER,
+ new String[] {});
constantPoolGen = classGen.getConstantPool();
instructionFactory = new InstructionFactory(classGen, constantPoolGen);
@@ -56,7 +57,8 @@ public void create(final OutputStream out) throws IOException {
private void createMethod_0() {
final InstructionList il = new InstructionList();
- final MethodGen method = new MethodGen(Const.ACC_PUBLIC, Type.VOID, Type.NO_ARGS, new String[] {}, "", TEST_PACKAGE + ".TestReturn03", il, constantPoolGen);
+ final MethodGen method = new MethodGen(Const.ACC_PUBLIC, Type.VOID, Type.NO_ARGS, new String[] {}, "", TEST_PACKAGE + ".TestReturn03", il,
+ constantPoolGen);
final InstructionHandle ih_0 = il.append(InstructionFactory.createLoad(Type.OBJECT, 0));
assertNotNull(ih_0); // TODO why is this not used
@@ -72,7 +74,7 @@ private void createMethod_0() {
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" + genClassSuffix, il, constantPoolGen);
+ TEST_PACKAGE + ".TestReturn03" + genClassSuffix, il, constantPoolGen);
final InstructionHandle ih_0 = il.append(InstructionConst.ACONST_NULL);
assertNotNull(ih_0); // TODO why is this not used
diff --git a/src/test/java/org/apache/bcel/visitors/CountingVisitor.java b/src/test/java/org/apache/bcel/visitors/CountingVisitor.java
index 3522df260f..1b95a9f926 100644
--- a/src/test/java/org/apache/bcel/visitors/CountingVisitor.java
+++ b/src/test/java/org/apache/bcel/visitors/CountingVisitor.java
@@ -68,6 +68,8 @@
import org.apache.bcel.classfile.NestMembers;
import org.apache.bcel.classfile.ParameterAnnotationEntry;
import org.apache.bcel.classfile.ParameterAnnotations;
+import org.apache.bcel.classfile.Record;
+import org.apache.bcel.classfile.RecordComponentInfo;
import org.apache.bcel.classfile.Signature;
import org.apache.bcel.classfile.SourceFile;
import org.apache.bcel.classfile.StackMap;
@@ -204,6 +206,13 @@ public class CountingVisitor implements Visitor {
/** @since 6.4.0 */
public int nestMembersCount;
+
+ /** @since 6.9.0 */
+ public int recordCount;
+
+ /** @since 6.9.0 */
+ public int recordComponentCount;
+
// CHECKSTYLE:ON
@Override
@@ -480,6 +489,16 @@ public void visitParameterAnnotationEntry(final ParameterAnnotationEntry paramet
// TODO Auto-generated method stub
}
+ @Override
+ public void visitRecord(final Record v) {
+ recordCount++;
+ }
+
+ @Override
+ public void visitRecordComponent(final RecordComponentInfo v) {
+ recordComponentCount++;
+ }
+
@Override
public void visitSignature(final Signature obj) {
signatureAnnotationCount++;
diff --git a/src/test/resources/StackMapExample2.java b/src/test/resources/StackMapExample2.java
index 441f678e4b..24598d3cee 100644
--- a/src/test/resources/StackMapExample2.java
+++ b/src/test/resources/StackMapExample2.java
@@ -1,12 +1,12 @@
-/*
- * Another version of StackMapExample using 2 types of locals String and int
- * instead of just String.
- */
-public class StackMapExample2 {
-
- public static void main(String[] args) {
- if (args.length == 1 && "Hello".equals(args[0])) {
- System.out.println("Hello World");
- }
- }
-}
+/*
+ * Another version of StackMapExample using 2 types of locals String and int
+ * instead of just String.
+ */
+public class StackMapExample2 {
+
+ public static void main(String[] args) {
+ if (args.length == 1 && "Hello".equals(args[0])) {
+ System.out.println("Hello World");
+ }
+ }
+}
diff --git a/src/test/resources/record/SimpleRecord.class b/src/test/resources/record/SimpleRecord.class
new file mode 100644
index 0000000000000000000000000000000000000000..bf6b81196e5121e296b4e17c517f70235719c1f9
GIT binary patch
literal 1506
zcmaJ>TT|0O6#ll9rY(`uT2L+m0+qBN@qR1fD2^jD1s!1epikR&hX&GYO;SexlMgZ@
z;|ve}0DqL@*(N|}k%!$qdvd<>o!jQm-;>_}UgDL87=ylJwc57W7Io=1G{hN3_W2<<
zZSL%uftEqzTb))-xD0GV-FAG}a`qT?ByYPNXoIMV07B^{4p
zq6_$H@-wBmB^{?@+XPIkT8`zfF^m}-{f>)OhPjKbKXRA1gfH9+9PxG85NQlxM8^=a
z3J8oUPvs87m(E_Zf-cu3YNa=gN
z%iBRUyfjvDPlL%Yb3PqzFcW4FNoc9#J{~ZnYNs9;j-p{(&Y?UIW?=oEI}KZS3l%93
zI_+{K+HmqBnh?1Atu5XPukKoHU%FAqy3IW=stA32?spPpFGrgb7B!Q=-6S5O%ts=y|E3)5pI`Lcp6?X6wWJiMUom;8K$o`rIrU3At89KR8*QnYIF=aHSi?m
z)VPy2MRJ19ba)OyC(CPeOT}mlJ`9tzNnqt7Q~E_~@))_&@-gy9q>5pTcI5?Ra)b8S
zz!WzzPB#K|S=IMUmp6t9l8IrE4viKgX_9uuRG?Ft4wil*_nm}(|3PRPrs!KVgI;+4
z$A95jdTUc5<083Hj9Tdg(?BnXb#qdjS$bxtVMal7KyRQ?Pyu&BCWDxiqhx961dCUp
r;wW`vU&1n-!-Ri`IPH({1W)mdbZNRhN16WH<5;8n1bGgc+t=EEvSvb$
literal 0
HcmV?d00001
diff --git a/src/test/resources/record/SimpleRecord.java b/src/test/resources/record/SimpleRecord.java
new file mode 100644
index 0000000000..10316b07f8
--- /dev/null
+++ b/src/test/resources/record/SimpleRecord.java
@@ -0,0 +1,5 @@
+import javax.annotation.Nonnull;
+
+public record SimpleRecord(int aNumber,@Nonnull String aString) {
+
+}