summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRemi Forax <forax@univ-mlv.fr>2023-12-11 07:21:01 +0000
committerRemi Forax <forax@univ-mlv.fr>2023-12-11 07:21:01 +0000
commit3d282865e96723dd3d0bffec27cb5727d66c23c7 (patch)
tree2f604342625114e038e449c8de7a7010750fa7cb
parent4d580087b20d651fe34ddc7395cc7a6668e380b0 (diff)
parent90e3ded4e0abb546f308617625b4fedc9622778e (diff)
downloadow2-asm-3d282865e96723dd3d0bffec27cb5727d66c23c7.tar.gz
Merge branch 'test-code-can-use-java-11-features' into 'master'
Use Java 11 features when it makes the code better See merge request asm/asm!385
-rw-r--r--asm-analysis/src/test/java/org/objectweb/asm/tree/analysis/AnalyzerWithBasicInterpreterTest.java6
-rw-r--r--asm-analysis/src/test/java/org/objectweb/asm/tree/analysis/SimpleVerifierTest.java4
-rw-r--r--asm-analysis/src/test/java/org/objectweb/asm/tree/analysis/SmallSetTest.java15
-rw-r--r--asm-commons/src/test/java/org/objectweb/asm/commons/ClassRemapperTest.java1
-rw-r--r--asm-commons/src/test/java/org/objectweb/asm/commons/GeneratorAdapterTest.java6
-rw-r--r--asm-commons/src/test/java/org/objectweb/asm/commons/ModuleHashesAttributeTest.java6
-rw-r--r--asm-commons/src/test/java/org/objectweb/asm/commons/SimpleRemapperTest.java15
-rw-r--r--asm-test/src/test/java/org/objectweb/asm/test/AsmTestTest.java11
-rw-r--r--asm-tree/src/test/java/org/objectweb/asm/tree/AnnotationNodeTest.java18
-rw-r--r--asm-tree/src/test/java/org/objectweb/asm/tree/FrameNodeTest.java6
-rw-r--r--asm-tree/src/test/java/org/objectweb/asm/tree/LookupSwitchInsnNodeTest.java6
-rw-r--r--asm-tree/src/test/java/org/objectweb/asm/tree/MethodNodeTest.java4
-rw-r--r--asm-tree/src/test/java/org/objectweb/asm/tree/TableSwitchInsnNodeTest.java4
-rw-r--r--asm-util/src/test/java/org/objectweb/asm/util/CheckMethodAdapterTest.java13
-rw-r--r--asm-util/src/test/java/org/objectweb/asm/util/TextifierTest.java6
-rw-r--r--asm/src/test/java/org/objectweb/asm/ClassReaderTest.java6
-rw-r--r--asm/src/test/java/org/objectweb/asm/ClassWriterTest.java73
-rw-r--r--asm/src/test/java/org/objectweb/asm/ConstantsTest.java2
-rw-r--r--asm/src/test/java/org/objectweb/asm/MethodWriterTest.java66
-rw-r--r--benchmarks/src/jmh/java/org/objectweb/asm/benchmarks/JClassLibGenerator.java6
20 files changed, 127 insertions, 147 deletions
diff --git a/asm-analysis/src/test/java/org/objectweb/asm/tree/analysis/AnalyzerWithBasicInterpreterTest.java b/asm-analysis/src/test/java/org/objectweb/asm/tree/analysis/AnalyzerWithBasicInterpreterTest.java
index 4afdbd23..3719d7fa 100644
--- a/asm-analysis/src/test/java/org/objectweb/asm/tree/analysis/AnalyzerWithBasicInterpreterTest.java
+++ b/asm-analysis/src/test/java/org/objectweb/asm/tree/analysis/AnalyzerWithBasicInterpreterTest.java
@@ -102,13 +102,13 @@ class AnalyzerWithBasicInterpreterTest extends AsmTest {
}
};
- ArrayList<Frame<? extends BasicValue>[]> methodFrames = new ArrayList<>();
+ ArrayList<Frame<BasicValue>[]> methodFrames = new ArrayList<>();
for (MethodNode methodNode : classNode.methods) {
methodFrames.add(analyzer.analyze(classNode.name, methodNode));
}
- for (Frame<? extends BasicValue>[] frames : methodFrames) {
- for (Frame<? extends BasicValue> frame : frames) {
+ for (Frame<BasicValue>[] frames : methodFrames) {
+ for (Frame<BasicValue> frame : frames) {
assertTrue(frame == null || frame instanceof CustomFrame);
}
}
diff --git a/asm-analysis/src/test/java/org/objectweb/asm/tree/analysis/SimpleVerifierTest.java b/asm-analysis/src/test/java/org/objectweb/asm/tree/analysis/SimpleVerifierTest.java
index 4faa857e..034ade19 100644
--- a/asm-analysis/src/test/java/org/objectweb/asm/tree/analysis/SimpleVerifierTest.java
+++ b/asm-analysis/src/test/java/org/objectweb/asm/tree/analysis/SimpleVerifierTest.java
@@ -33,7 +33,7 @@ import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.junit.jupiter.api.Assertions.assertTrue;
-import java.util.Arrays;
+import java.util.List;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.CsvSource;
@@ -85,7 +85,7 @@ class SimpleVerifierTest {
/* latest */ Opcodes.ASM10_EXPERIMENTAL,
baseType,
superType,
- Arrays.asList(interfaceType),
+ List.of(interfaceType),
false) {
@Override
diff --git a/asm-analysis/src/test/java/org/objectweb/asm/tree/analysis/SmallSetTest.java b/asm-analysis/src/test/java/org/objectweb/asm/tree/analysis/SmallSetTest.java
index 12691fbf..818b0040 100644
--- a/asm-analysis/src/test/java/org/objectweb/asm/tree/analysis/SmallSetTest.java
+++ b/asm-analysis/src/test/java/org/objectweb/asm/tree/analysis/SmallSetTest.java
@@ -32,8 +32,6 @@ import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.junit.jupiter.api.Assertions.assertTrue;
-import java.util.Arrays;
-import java.util.HashSet;
import java.util.Iterator;
import java.util.NoSuchElementException;
import java.util.Set;
@@ -73,7 +71,7 @@ class SmallSetTest {
Set<Object> union2 = set2.union(set1);
assertEquals(union1, union2);
- assertEquals(union1, new HashSet<Object>(Arrays.asList(ELEMENT1)));
+ assertEquals(union1, Set.of(ELEMENT1));
}
@Test
@@ -85,7 +83,7 @@ class SmallSetTest {
Set<Object> union2 = set2.union(set1);
assertEquals(union1, union2);
- assertEquals(union1, new HashSet<Object>(Arrays.asList(ELEMENT1, ELEMENT2)));
+ assertEquals(union1, Set.of(ELEMENT1, ELEMENT2));
}
@Test
@@ -97,7 +95,7 @@ class SmallSetTest {
Set<Object> union2 = set2.union(set1);
assertEquals(union1, union2);
- assertEquals(union1, new HashSet<Object>(Arrays.asList(ELEMENT1, ELEMENT2)));
+ assertEquals(union1, Set.of(ELEMENT1, ELEMENT2));
}
@Test
@@ -109,7 +107,7 @@ class SmallSetTest {
Set<Object> union2 = set2.union(set1);
assertEquals(union1, union2);
- assertEquals(union1, new HashSet<Object>(Arrays.asList(ELEMENT1, ELEMENT2, ELEMENT3)));
+ assertEquals(union1, Set.of(ELEMENT1, ELEMENT2, ELEMENT3));
}
@Test
@@ -121,8 +119,7 @@ class SmallSetTest {
Set<Object> union2 = set2.union(set1);
assertEquals(union1, union2);
- assertEquals(
- union1, new HashSet<Object>(Arrays.asList(ELEMENT1, ELEMENT2, ELEMENT3, ELEMENT4)));
+ assertEquals(union1, Set.of(ELEMENT1, ELEMENT2, ELEMENT3, ELEMENT4));
}
@Test
@@ -166,6 +163,6 @@ class SmallSetTest {
}
private static SmallSet<Object> newSmallSet(final Object element1, final Object element2) {
- return (SmallSet<Object>) new SmallSet<Object>(element1).union(new SmallSet<Object>(element2));
+ return (SmallSet<Object>) new SmallSet<>(element1).union(new SmallSet<>(element2));
}
}
diff --git a/asm-commons/src/test/java/org/objectweb/asm/commons/ClassRemapperTest.java b/asm-commons/src/test/java/org/objectweb/asm/commons/ClassRemapperTest.java
index 697125f3..58c171d4 100644
--- a/asm-commons/src/test/java/org/objectweb/asm/commons/ClassRemapperTest.java
+++ b/asm-commons/src/test/java/org/objectweb/asm/commons/ClassRemapperTest.java
@@ -189,6 +189,7 @@ class ClassRemapperTest extends AsmTest {
});
classRemapper.visit(Opcodes.V1_5, Opcodes.ACC_PUBLIC, "C", null, "java/lang/Object", null);
+ // The ClassRemapper change the modules and the hashes so the lists have to be mutable.
classRemapper.visitAttribute(
new ModuleHashesAttribute("algorithm", Arrays.asList("pkg.C"), Arrays.asList(new byte[0])));
diff --git a/asm-commons/src/test/java/org/objectweb/asm/commons/GeneratorAdapterTest.java b/asm-commons/src/test/java/org/objectweb/asm/commons/GeneratorAdapterTest.java
index c5ca9134..45989961 100644
--- a/asm-commons/src/test/java/org/objectweb/asm/commons/GeneratorAdapterTest.java
+++ b/asm-commons/src/test/java/org/objectweb/asm/commons/GeneratorAdapterTest.java
@@ -37,7 +37,7 @@ import static org.objectweb.asm.commons.GeneratorAdapter.LE;
import static org.objectweb.asm.commons.GeneratorAdapter.LT;
import static org.objectweb.asm.commons.GeneratorAdapter.NE;
-import java.util.Arrays;
+import java.util.List;
import java.util.stream.Collectors;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.function.Executable;
@@ -109,7 +109,7 @@ class GeneratorAdapterTest {
assertEquals(Opcodes.ACC_PUBLIC, methodNode.access);
assertEquals("name", methodNode.name);
assertEquals("()V", methodNode.desc);
- assertEquals(Arrays.asList("java/lang/Exception"), methodNode.exceptions);
+ assertEquals(List.of("java/lang/Exception"), methodNode.exceptions);
}
@Test
@@ -127,7 +127,7 @@ class GeneratorAdapterTest {
assertEquals(Opcodes.ACC_PUBLIC, methodNode.access);
assertEquals("name", methodNode.name);
assertEquals("()V", methodNode.desc);
- assertEquals(Arrays.asList(), methodNode.exceptions);
+ assertEquals(List.of(), methodNode.exceptions);
}
@Test
diff --git a/asm-commons/src/test/java/org/objectweb/asm/commons/ModuleHashesAttributeTest.java b/asm-commons/src/test/java/org/objectweb/asm/commons/ModuleHashesAttributeTest.java
index 40a45c06..5e5f0e65 100644
--- a/asm-commons/src/test/java/org/objectweb/asm/commons/ModuleHashesAttributeTest.java
+++ b/asm-commons/src/test/java/org/objectweb/asm/commons/ModuleHashesAttributeTest.java
@@ -30,7 +30,7 @@ package org.objectweb.asm.commons;
import static org.junit.jupiter.api.Assertions.assertArrayEquals;
import static org.junit.jupiter.api.Assertions.assertEquals;
-import java.util.Arrays;
+import java.util.List;
import org.junit.jupiter.api.Test;
import org.objectweb.asm.Attribute;
import org.objectweb.asm.ClassReader;
@@ -53,9 +53,7 @@ class ModuleHashesAttributeTest {
ClassWriter classWriter = new ClassWriter(0);
classWriter.visitAttribute(
new ModuleHashesAttribute(
- "algorithm",
- Arrays.asList(new String[] {"module1", "module2"}),
- Arrays.asList(new byte[][] {HASH1, HASH2})));
+ "algorithm", List.of("module1", "module2"), List.of(HASH1, HASH2)));
ModuleHashesAttribute moduleHashesAttribute = new ModuleHashesAttribute();
new ClassReader(classWriter.toByteArray())
diff --git a/asm-commons/src/test/java/org/objectweb/asm/commons/SimpleRemapperTest.java b/asm-commons/src/test/java/org/objectweb/asm/commons/SimpleRemapperTest.java
index edba97c8..50497e13 100644
--- a/asm-commons/src/test/java/org/objectweb/asm/commons/SimpleRemapperTest.java
+++ b/asm-commons/src/test/java/org/objectweb/asm/commons/SimpleRemapperTest.java
@@ -29,8 +29,6 @@ package org.objectweb.asm.commons;
import static org.junit.jupiter.api.Assertions.assertEquals;
-import java.util.Collections;
-import java.util.HashMap;
import java.util.Map;
import org.junit.jupiter.api.Test;
@@ -44,7 +42,7 @@ class SimpleRemapperTest {
@Test
void testMapSignature_remapParentOnly_nestedClassExtends() {
String inputSignature = "LOuter<Ljava/lang/Object;>.Inner;";
- Remapper remapper = new SimpleRemapper(Collections.singletonMap("Outer", "RenamedOuter"));
+ Remapper remapper = new SimpleRemapper(Map.of("Outer", "RenamedOuter"));
String remappedSignature = remapper.mapSignature(inputSignature, false);
@@ -54,8 +52,7 @@ class SimpleRemapperTest {
@Test
void testMapSignature_remapChildOnly_nestedClassExtends() {
String inputSignature = "LOuter<Ljava/lang/Object;>.Inner;";
- Remapper remapper =
- new SimpleRemapper(Collections.singletonMap("Outer$Inner", "Outer$RenamedInner"));
+ Remapper remapper = new SimpleRemapper(Map.of("Outer$Inner", "Outer$RenamedInner"));
String remappedSignature = remapper.mapSignature(inputSignature, false);
@@ -65,8 +62,7 @@ class SimpleRemapperTest {
@Test
void testMapSignature_remapChildOnly_nestedClassExtends_identifiersWithDollarSign() {
String inputSignature = "LOuter<Ljava/lang/Object;>.Inner$1;";
- Remapper remapper =
- new SimpleRemapper(Collections.singletonMap("Outer$Inner$1", "Outer$RenamedInner$1"));
+ Remapper remapper = new SimpleRemapper(Map.of("Outer$Inner$1", "Outer$RenamedInner$1"));
String remappedSignature = remapper.mapSignature(inputSignature, false);
@@ -76,9 +72,8 @@ class SimpleRemapperTest {
@Test
void testMapSignature_remapBothParentAndChild_nestedClassExtends() {
String inputSignature = "LOuter<Ljava/lang/Object;>.Inner;";
- Map<String, String> mapping = new HashMap<>();
- mapping.put("Outer", "RenamedOuter");
- mapping.put("Outer$Inner", "RenamedOuter$RenamedInner");
+ Map<String, String> mapping =
+ Map.of("Outer", "RenamedOuter", "Outer$Inner", "RenamedOuter$RenamedInner");
Remapper remapper = new SimpleRemapper(mapping);
String remappedSignature = remapper.mapSignature(inputSignature, false);
diff --git a/asm-test/src/test/java/org/objectweb/asm/test/AsmTestTest.java b/asm-test/src/test/java/org/objectweb/asm/test/AsmTestTest.java
index d8645487..89f59e19 100644
--- a/asm-test/src/test/java/org/objectweb/asm/test/AsmTestTest.java
+++ b/asm-test/src/test/java/org/objectweb/asm/test/AsmTestTest.java
@@ -32,9 +32,8 @@ 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.util.Arrays;
-import java.util.HashSet;
import java.util.List;
+import java.util.Set;
import java.util.stream.Collectors;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.params.provider.Arguments;
@@ -89,10 +88,10 @@ class AsmTestTest extends AsmTest {
List<Arguments> allArguments = allClassesAndAllApis().collect(Collectors.toList());
assertEquals(
- new HashSet<Object>(Arrays.asList(PrecompiledClass.values())),
+ Set.of(PrecompiledClass.values()),
allArguments.stream().map(arg -> arg.get()[0]).collect(Collectors.toSet()));
assertEquals(
- new HashSet<Object>(Arrays.asList(Api.values())),
+ Set.of(Api.values()),
allArguments.stream().map(arg -> arg.get()[1]).collect(Collectors.toSet()));
}
@@ -101,10 +100,10 @@ class AsmTestTest extends AsmTest {
List<Arguments> allArguments = allClassesAndLatestApi().collect(Collectors.toList());
assertEquals(
- new HashSet<Object>(Arrays.asList(PrecompiledClass.values())),
+ Set.of(PrecompiledClass.values()),
allArguments.stream().map(arg -> arg.get()[0]).collect(Collectors.toSet()));
assertEquals(
- new HashSet<Object>(Arrays.asList(Api.ASM9)),
+ Set.of(Api.ASM9),
allArguments.stream().map(arg -> arg.get()[1]).collect(Collectors.toSet()));
}
}
diff --git a/asm-tree/src/test/java/org/objectweb/asm/tree/AnnotationNodeTest.java b/asm-tree/src/test/java/org/objectweb/asm/tree/AnnotationNodeTest.java
index e926dbcc..20b0bae0 100644
--- a/asm-tree/src/test/java/org/objectweb/asm/tree/AnnotationNodeTest.java
+++ b/asm-tree/src/test/java/org/objectweb/asm/tree/AnnotationNodeTest.java
@@ -31,7 +31,7 @@ import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNull;
import static org.junit.jupiter.api.Assertions.assertThrows;
-import java.util.Arrays;
+import java.util.List;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.function.Executable;
import org.objectweb.asm.AnnotationVisitor;
@@ -75,21 +75,21 @@ class AnnotationNodeTest extends AsmTest {
annotationNode.visitAnnotation("annotation", "Lpkg/Annotation;");
assertEquals("bytes", annotationNode.values.get(0));
- assertEquals(Arrays.asList(new Byte[] {0, 1}), annotationNode.values.get(1));
+ assertEquals(List.of((byte) 0, (byte) 1), annotationNode.values.get(1));
assertEquals("booleans", annotationNode.values.get(2));
- assertEquals(Arrays.asList(new Boolean[] {false, true}), annotationNode.values.get(3));
+ assertEquals(List.of(false, true), annotationNode.values.get(3));
assertEquals("shorts", annotationNode.values.get(4));
- assertEquals(Arrays.asList(new Short[] {0, 1}), annotationNode.values.get(5));
+ assertEquals(List.of((short) 0, (short) 1), annotationNode.values.get(5));
assertEquals("chars", annotationNode.values.get(6));
- assertEquals(Arrays.asList(new Character[] {'0', '1'}), annotationNode.values.get(7));
+ assertEquals(List.of('0', '1'), annotationNode.values.get(7));
assertEquals("ints", annotationNode.values.get(8));
- assertEquals(Arrays.asList(new Integer[] {0, 1}), annotationNode.values.get(9));
+ assertEquals(List.of(0, 1), annotationNode.values.get(9));
assertEquals("longs", annotationNode.values.get(10));
- assertEquals(Arrays.asList(new Long[] {0L, 1L}), annotationNode.values.get(11));
+ assertEquals(List.of(0L, 1L), annotationNode.values.get(11));
assertEquals("floats", annotationNode.values.get(12));
- assertEquals(Arrays.asList(new Float[] {0.0f, 1.0f}), annotationNode.values.get(13));
+ assertEquals(List.of(0.0f, 1.0f), annotationNode.values.get(13));
assertEquals("doubles", annotationNode.values.get(14));
- assertEquals(Arrays.asList(new Double[] {0.0, 1.0}), annotationNode.values.get(15));
+ assertEquals(List.of(0.0, 1.0), annotationNode.values.get(15));
assertEquals("string", annotationNode.values.get(16));
assertEquals("value", annotationNode.values.get(17));
assertEquals("annotation", annotationNode.values.get(18));
diff --git a/asm-tree/src/test/java/org/objectweb/asm/tree/FrameNodeTest.java b/asm-tree/src/test/java/org/objectweb/asm/tree/FrameNodeTest.java
index b00024cf..1a158776 100644
--- a/asm-tree/src/test/java/org/objectweb/asm/tree/FrameNodeTest.java
+++ b/asm-tree/src/test/java/org/objectweb/asm/tree/FrameNodeTest.java
@@ -30,7 +30,7 @@ package org.objectweb.asm.tree;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertThrows;
-import java.util.Arrays;
+import java.util.List;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.function.Executable;
import org.objectweb.asm.Opcodes;
@@ -52,8 +52,8 @@ class FrameNodeTest extends AsmTest {
assertEquals(AbstractInsnNode.FRAME, frameNode.getType());
assertEquals(Opcodes.F_FULL, frameNode.type);
- assertEquals(Arrays.asList(locals), frameNode.local);
- assertEquals(Arrays.asList(stack), frameNode.stack);
+ assertEquals(List.of(locals), frameNode.local);
+ assertEquals(List.of(stack), frameNode.stack);
}
@Test
diff --git a/asm-tree/src/test/java/org/objectweb/asm/tree/LookupSwitchInsnNodeTest.java b/asm-tree/src/test/java/org/objectweb/asm/tree/LookupSwitchInsnNodeTest.java
index 4313ea56..9e933031 100644
--- a/asm-tree/src/test/java/org/objectweb/asm/tree/LookupSwitchInsnNodeTest.java
+++ b/asm-tree/src/test/java/org/objectweb/asm/tree/LookupSwitchInsnNodeTest.java
@@ -29,7 +29,7 @@ package org.objectweb.asm.tree;
import static org.junit.jupiter.api.Assertions.assertEquals;
-import java.util.Arrays;
+import java.util.List;
import org.junit.jupiter.api.Test;
import org.objectweb.asm.test.AsmTest;
@@ -50,7 +50,7 @@ class LookupSwitchInsnNodeTest extends AsmTest {
assertEquals(AbstractInsnNode.LOOKUPSWITCH_INSN, lookupSwitchInsnNode.getType());
assertEquals(dflt, lookupSwitchInsnNode.dflt);
- assertEquals(Arrays.asList(new Integer[] {1}), lookupSwitchInsnNode.keys);
- assertEquals(Arrays.asList(labels), lookupSwitchInsnNode.labels);
+ assertEquals(List.of(1), lookupSwitchInsnNode.keys);
+ assertEquals(List.of(labels), lookupSwitchInsnNode.labels);
}
}
diff --git a/asm-tree/src/test/java/org/objectweb/asm/tree/MethodNodeTest.java b/asm-tree/src/test/java/org/objectweb/asm/tree/MethodNodeTest.java
index d59e5875..7aff0a02 100644
--- a/asm-tree/src/test/java/org/objectweb/asm/tree/MethodNodeTest.java
+++ b/asm-tree/src/test/java/org/objectweb/asm/tree/MethodNodeTest.java
@@ -30,7 +30,7 @@ package org.objectweb.asm.tree;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertThrows;
-import java.util.Arrays;
+import java.util.List;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.function.Executable;
import org.junit.jupiter.params.ParameterizedTest;
@@ -89,7 +89,7 @@ class MethodNodeTest extends AsmTest {
method.name = name;
method.desc = descriptor;
method.signature = signature;
- method.exceptions = exceptions == null ? null : Arrays.asList(exceptions);
+ method.exceptions = exceptions == null ? null : List.of(exceptions);
methods.add(method);
return method;
}
diff --git a/asm-tree/src/test/java/org/objectweb/asm/tree/TableSwitchInsnNodeTest.java b/asm-tree/src/test/java/org/objectweb/asm/tree/TableSwitchInsnNodeTest.java
index 54e659de..cd83ef48 100644
--- a/asm-tree/src/test/java/org/objectweb/asm/tree/TableSwitchInsnNodeTest.java
+++ b/asm-tree/src/test/java/org/objectweb/asm/tree/TableSwitchInsnNodeTest.java
@@ -29,7 +29,7 @@ package org.objectweb.asm.tree;
import static org.junit.jupiter.api.Assertions.assertEquals;
-import java.util.Arrays;
+import java.util.List;
import org.junit.jupiter.api.Test;
import org.objectweb.asm.test.AsmTest;
@@ -51,6 +51,6 @@ class TableSwitchInsnNodeTest extends AsmTest {
assertEquals(0, tableSwitchInsnNode.min);
assertEquals(1, tableSwitchInsnNode.max);
assertEquals(dflt, tableSwitchInsnNode.dflt);
- assertEquals(Arrays.asList(labels), tableSwitchInsnNode.labels);
+ assertEquals(List.of(labels), tableSwitchInsnNode.labels);
}
}
diff --git a/asm-util/src/test/java/org/objectweb/asm/util/CheckMethodAdapterTest.java b/asm-util/src/test/java/org/objectweb/asm/util/CheckMethodAdapterTest.java
index efb6cf41..b0970220 100644
--- a/asm-util/src/test/java/org/objectweb/asm/util/CheckMethodAdapterTest.java
+++ b/asm-util/src/test/java/org/objectweb/asm/util/CheckMethodAdapterTest.java
@@ -33,6 +33,7 @@ import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.junit.jupiter.api.Assertions.assertTrue;
import java.util.HashMap;
+import java.util.Map;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.function.Executable;
import org.objectweb.asm.ClassWriter;
@@ -122,7 +123,7 @@ class CheckMethodAdapterTest extends AsmTest implements Opcodes {
@Test
void testVisitCode_abstractMethod() {
CheckMethodAdapter checkAbstractMethodAdapter =
- new CheckMethodAdapter(Opcodes.ACC_ABSTRACT, "m", "()V", null, new HashMap<>());
+ new CheckMethodAdapter(Opcodes.ACC_ABSTRACT, "m", "()V", null, Map.of());
Executable visitCode = () -> checkAbstractMethodAdapter.visitCode();
@@ -1086,7 +1087,7 @@ class CheckMethodAdapterTest extends AsmTest implements Opcodes {
@Test
void testVisitEnd_invalidDataFlow() {
MethodVisitor dataFlowCheckMethodAdapter =
- new CheckMethodAdapter(ACC_PUBLIC, "m", "(I)I", null, new HashMap<>());
+ new CheckMethodAdapter(ACC_PUBLIC, "m", "(I)I", null, Map.of());
dataFlowCheckMethodAdapter.visitCode();
dataFlowCheckMethodAdapter.visitVarInsn(ILOAD, 1);
dataFlowCheckMethodAdapter.visitVarInsn(ASTORE, 0);
@@ -1114,7 +1115,7 @@ class CheckMethodAdapterTest extends AsmTest implements Opcodes {
classWriter,
new MethodVisitor(/* latest api = */ Opcodes.ASM9) {});
MethodVisitor dataFlowCheckMethodAdapter =
- new CheckMethodAdapter(ACC_PUBLIC, "m", "(I)I", methodVisitor, new HashMap<>());
+ new CheckMethodAdapter(ACC_PUBLIC, "m", "(I)I", methodVisitor, Map.of());
dataFlowCheckMethodAdapter.visitCode();
dataFlowCheckMethodAdapter.visitVarInsn(ILOAD, 1);
dataFlowCheckMethodAdapter.visitInsn(IRETURN);
@@ -1135,7 +1136,7 @@ class CheckMethodAdapterTest extends AsmTest implements Opcodes {
classWriter,
new MethodVisitor(/* latest api = */ Opcodes.ASM9) {});
MethodVisitor dataFlowCheckMethodAdapter =
- new CheckMethodAdapter(ACC_PUBLIC, "m", "(I)I", methodVisitor, new HashMap<>());
+ new CheckMethodAdapter(ACC_PUBLIC, "m", "(I)I", methodVisitor, Map.of());
dataFlowCheckMethodAdapter.visitCode();
dataFlowCheckMethodAdapter.visitVarInsn(ILOAD, 1);
dataFlowCheckMethodAdapter.visitInsn(IRETURN);
@@ -1156,7 +1157,7 @@ class CheckMethodAdapterTest extends AsmTest implements Opcodes {
classWriter,
new MethodVisitor(/* latest api = */ Opcodes.ASM9) {});
MethodVisitor dataFlowCheckMethodAdapter =
- new CheckMethodAdapter(ACC_PUBLIC, "m", "(I)I", methodVisitor, new HashMap<>());
+ new CheckMethodAdapter(ACC_PUBLIC, "m", "(I)I", methodVisitor, Map.of());
dataFlowCheckMethodAdapter.visitCode();
dataFlowCheckMethodAdapter.visitVarInsn(ILOAD, 1);
dataFlowCheckMethodAdapter.visitInsn(IRETURN);
@@ -1228,7 +1229,7 @@ class CheckMethodAdapterTest extends AsmTest implements Opcodes {
@Test
void testVisitEnd_invalidReturnType() {
MethodVisitor dataFlowCheckMethodAdapter =
- new CheckMethodAdapter(ACC_PUBLIC, "m", "(I)V", null, new HashMap<>());
+ new CheckMethodAdapter(ACC_PUBLIC, "m", "(I)V", null, Map.of());
dataFlowCheckMethodAdapter.visitCode();
dataFlowCheckMethodAdapter.visitVarInsn(ILOAD, 1);
dataFlowCheckMethodAdapter.visitInsn(IRETURN);
diff --git a/asm-util/src/test/java/org/objectweb/asm/util/TextifierTest.java b/asm-util/src/test/java/org/objectweb/asm/util/TextifierTest.java
index bfbfb92e..1c72d7cd 100644
--- a/asm-util/src/test/java/org/objectweb/asm/util/TextifierTest.java
+++ b/asm-util/src/test/java/org/objectweb/asm/util/TextifierTest.java
@@ -37,7 +37,6 @@ import static org.junit.jupiter.api.Assumptions.assumeTrue;
import java.io.IOException;
import java.io.PrintWriter;
import java.io.StringWriter;
-import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.Paths;
import org.junit.jupiter.api.Test;
@@ -85,10 +84,7 @@ class TextifierTest extends AsmTest {
0);
String expectedText =
- new String(
- Files.readAllBytes(
- Paths.get("src/test/resources/" + classParameter.getName() + ".txt")),
- StandardCharsets.UTF_8)
+ Files.readString(Paths.get("src/test/resources/" + classParameter.getName() + ".txt"))
.replace("\r", "");
assertEquals(expectedText, output.toString());
diff --git a/asm/src/test/java/org/objectweb/asm/ClassReaderTest.java b/asm/src/test/java/org/objectweb/asm/ClassReaderTest.java
index 95a968f8..10d39b4c 100644
--- a/asm/src/test/java/org/objectweb/asm/ClassReaderTest.java
+++ b/asm/src/test/java/org/objectweb/asm/ClassReaderTest.java
@@ -216,8 +216,6 @@ class ClassReaderTest extends AsmTest implements Opcodes {
ClassLoader.getSystemResourceAsStream(
classParameter.getName().replace('.', '/') + ".class")) {
classReader = new ClassReader(inputStream);
- } catch (IOException ioe) {
- throw ioe;
}
assertNotEquals(0, classReader.getAccess());
@@ -259,8 +257,6 @@ class ClassReaderTest extends AsmTest implements Opcodes {
assertTimeoutPreemptively(
Duration.ofMillis(100),
() -> assertThrows(ArrayIndexOutOfBoundsException.class, streamConstructor));
- } catch (IOException ioe) {
- throw ioe;
}
}
@@ -452,7 +448,7 @@ class ClassReaderTest extends AsmTest implements Opcodes {
|| invalidClass == InvalidClass.INVALID_BYTECODE_OFFSET) {
Exception exception = assertThrows(ArrayIndexOutOfBoundsException.class, accept);
Matcher matcher = Pattern.compile("\\d+").matcher(exception.getMessage());
- assertTrue(matcher.find() && Integer.valueOf(matcher.group()) > 0);
+ assertTrue(matcher.find() && Integer.parseInt(matcher.group()) > 0);
} else {
assertThrows(IllegalArgumentException.class, accept);
}
diff --git a/asm/src/test/java/org/objectweb/asm/ClassWriterTest.java b/asm/src/test/java/org/objectweb/asm/ClassWriterTest.java
index df146d3c..e0abde8e 100644
--- a/asm/src/test/java/org/objectweb/asm/ClassWriterTest.java
+++ b/asm/src/test/java/org/objectweb/asm/ClassWriterTest.java
@@ -66,8 +66,8 @@ class ClassWriterTest extends AsmTest {
/**
* Tests that the non-static fields of ClassWriter are the expected ones. This test is designed to
* fail each time new fields are added to ClassWriter, and serves as a reminder to update the
- * field reset logic in {@link ClassWriter#replaceAsmInstructions()}, if needed, each time a new
- * field is added.
+ * field reset logic in {@link ClassWriter#replaceAsmInstructions(byte[], boolean)}, if needed,
+ * each time a new field is added.
*/
@Test
void testInstanceFields() {
@@ -78,41 +78,40 @@ class ClassWriterTest extends AsmTest {
.collect(toSet());
Set<String> expectedFields =
- new HashSet<String>(
- Arrays.asList(
- "flags",
- "version",
- "symbolTable",
- "accessFlags",
- "thisClass",
- "superClass",
- "interfaceCount",
- "interfaces",
- "firstField",
- "lastField",
- "firstMethod",
- "lastMethod",
- "numberOfInnerClasses",
- "innerClasses",
- "enclosingClassIndex",
- "enclosingMethodIndex",
- "signatureIndex",
- "sourceFileIndex",
- "debugExtension",
- "lastRuntimeVisibleAnnotation",
- "lastRuntimeInvisibleAnnotation",
- "lastRuntimeVisibleTypeAnnotation",
- "lastRuntimeInvisibleTypeAnnotation",
- "moduleWriter",
- "nestHostClassIndex",
- "numberOfNestMemberClasses",
- "nestMemberClasses",
- "numberOfPermittedSubclasses",
- "permittedSubclasses",
- "firstRecordComponent",
- "lastRecordComponent",
- "firstAttribute",
- "compute"));
+ Set.of(
+ "flags",
+ "version",
+ "symbolTable",
+ "accessFlags",
+ "thisClass",
+ "superClass",
+ "interfaceCount",
+ "interfaces",
+ "firstField",
+ "lastField",
+ "firstMethod",
+ "lastMethod",
+ "numberOfInnerClasses",
+ "innerClasses",
+ "enclosingClassIndex",
+ "enclosingMethodIndex",
+ "signatureIndex",
+ "sourceFileIndex",
+ "debugExtension",
+ "lastRuntimeVisibleAnnotation",
+ "lastRuntimeInvisibleAnnotation",
+ "lastRuntimeVisibleTypeAnnotation",
+ "lastRuntimeInvisibleTypeAnnotation",
+ "moduleWriter",
+ "nestHostClassIndex",
+ "numberOfNestMemberClasses",
+ "nestMemberClasses",
+ "numberOfPermittedSubclasses",
+ "permittedSubclasses",
+ "firstRecordComponent",
+ "lastRecordComponent",
+ "firstAttribute",
+ "compute");
// IMPORTANT: if this fails, update the string list AND update the logic that resets the
// ClassWriter fields in ClassWriter.toByteArray(), if needed (this logic is used to do a
// ClassReader->ClassWriter round trip to remove the ASM specific instructions due to large
diff --git a/asm/src/test/java/org/objectweb/asm/ConstantsTest.java b/asm/src/test/java/org/objectweb/asm/ConstantsTest.java
index 0c6a7860..3d208a3b 100644
--- a/asm/src/test/java/org/objectweb/asm/ConstantsTest.java
+++ b/asm/src/test/java/org/objectweb/asm/ConstantsTest.java
@@ -564,7 +564,7 @@ class ConstantsTest {
private static int getIntegerValue(final Field field) {
try {
- return ((Integer) field.get(null)).intValue();
+ return (int) field.get(null);
} catch (IllegalAccessException e) {
throw new IllegalArgumentException(e);
}
diff --git a/asm/src/test/java/org/objectweb/asm/MethodWriterTest.java b/asm/src/test/java/org/objectweb/asm/MethodWriterTest.java
index 60ead10a..b45bc763 100644
--- a/asm/src/test/java/org/objectweb/asm/MethodWriterTest.java
+++ b/asm/src/test/java/org/objectweb/asm/MethodWriterTest.java
@@ -33,7 +33,6 @@ import static org.junit.jupiter.api.Assertions.assertTimeoutPreemptively;
import java.time.Duration;
import java.util.Arrays;
-import java.util.HashSet;
import java.util.Set;
import org.junit.jupiter.api.Test;
@@ -64,39 +63,38 @@ class MethodWriterTest {
})
.collect(toSet());
- HashSet<String> expectedAttributes =
- new HashSet<String>(
- Arrays.asList(
- Constants.CONSTANT_VALUE,
- Constants.CODE,
- Constants.STACK_MAP_TABLE,
- Constants.EXCEPTIONS,
- Constants.INNER_CLASSES,
- Constants.ENCLOSING_METHOD,
- Constants.SYNTHETIC,
- Constants.SIGNATURE,
- Constants.SOURCE_FILE,
- Constants.SOURCE_DEBUG_EXTENSION,
- Constants.LINE_NUMBER_TABLE,
- Constants.LOCAL_VARIABLE_TABLE,
- Constants.LOCAL_VARIABLE_TYPE_TABLE,
- Constants.DEPRECATED,
- Constants.RUNTIME_VISIBLE_ANNOTATIONS,
- Constants.RUNTIME_INVISIBLE_ANNOTATIONS,
- Constants.RUNTIME_VISIBLE_PARAMETER_ANNOTATIONS,
- Constants.RUNTIME_INVISIBLE_PARAMETER_ANNOTATIONS,
- Constants.RUNTIME_VISIBLE_TYPE_ANNOTATIONS,
- Constants.RUNTIME_INVISIBLE_TYPE_ANNOTATIONS,
- Constants.ANNOTATION_DEFAULT,
- Constants.BOOTSTRAP_METHODS,
- Constants.METHOD_PARAMETERS,
- Constants.MODULE,
- Constants.MODULE_PACKAGES,
- Constants.MODULE_MAIN_CLASS,
- Constants.NEST_HOST,
- Constants.NEST_MEMBERS,
- Constants.PERMITTED_SUBCLASSES,
- Constants.RECORD));
+ Set<String> expectedAttributes =
+ Set.of(
+ Constants.CONSTANT_VALUE,
+ Constants.CODE,
+ Constants.STACK_MAP_TABLE,
+ Constants.EXCEPTIONS,
+ Constants.INNER_CLASSES,
+ Constants.ENCLOSING_METHOD,
+ Constants.SYNTHETIC,
+ Constants.SIGNATURE,
+ Constants.SOURCE_FILE,
+ Constants.SOURCE_DEBUG_EXTENSION,
+ Constants.LINE_NUMBER_TABLE,
+ Constants.LOCAL_VARIABLE_TABLE,
+ Constants.LOCAL_VARIABLE_TYPE_TABLE,
+ Constants.DEPRECATED,
+ Constants.RUNTIME_VISIBLE_ANNOTATIONS,
+ Constants.RUNTIME_INVISIBLE_ANNOTATIONS,
+ Constants.RUNTIME_VISIBLE_PARAMETER_ANNOTATIONS,
+ Constants.RUNTIME_INVISIBLE_PARAMETER_ANNOTATIONS,
+ Constants.RUNTIME_VISIBLE_TYPE_ANNOTATIONS,
+ Constants.RUNTIME_INVISIBLE_TYPE_ANNOTATIONS,
+ Constants.ANNOTATION_DEFAULT,
+ Constants.BOOTSTRAP_METHODS,
+ Constants.METHOD_PARAMETERS,
+ Constants.MODULE,
+ Constants.MODULE_PACKAGES,
+ Constants.MODULE_MAIN_CLASS,
+ Constants.NEST_HOST,
+ Constants.NEST_MEMBERS,
+ Constants.PERMITTED_SUBCLASSES,
+ Constants.RECORD);
// IMPORTANT: if this fails, update the list AND update MethodWriter.canCopyMethodAttributes(),
// if needed.
assertEquals(expectedAttributes, actualAttributes);
diff --git a/benchmarks/src/jmh/java/org/objectweb/asm/benchmarks/JClassLibGenerator.java b/benchmarks/src/jmh/java/org/objectweb/asm/benchmarks/JClassLibGenerator.java
index fc2b0a73..1ecc06d5 100644
--- a/benchmarks/src/jmh/java/org/objectweb/asm/benchmarks/JClassLibGenerator.java
+++ b/benchmarks/src/jmh/java/org/objectweb/asm/benchmarks/JClassLibGenerator.java
@@ -30,7 +30,7 @@ package org.objectweb.asm.benchmarks;
import java.io.ByteArrayOutputStream;
import java.io.DataOutputStream;
import java.io.IOException;
-import java.util.Arrays;
+import java.util.List;
import org.gjt.jclasslib.bytecode.ImmediateByteInstruction;
import org.gjt.jclasslib.bytecode.ImmediateShortInstruction;
import org.gjt.jclasslib.bytecode.Opcodes;
@@ -82,7 +82,7 @@ public class JClassLibGenerator extends Generator {
ConstantPoolUtil.addConstantUTF8Info(classFile, CodeAttribute.ATTRIBUTE_NAME, 0));
codeAttribute1.setCode(
ByteCodeWriter.writeByteCode(
- Arrays.asList(
+ List.of(
new SimpleInstruction(Opcodes.OPCODE_ALOAD_0),
new ImmediateShortInstruction(
Opcodes.OPCODE_INVOKESPECIAL,
@@ -107,7 +107,7 @@ public class JClassLibGenerator extends Generator {
ConstantPoolUtil.addConstantUTF8Info(classFile, CodeAttribute.ATTRIBUTE_NAME, 0));
codeAttribute2.setCode(
ByteCodeWriter.writeByteCode(
- Arrays.asList(
+ List.of(
new ImmediateShortInstruction(
Opcodes.OPCODE_GETSTATIC,
ConstantPoolUtil.addConstantFieldrefInfo(