@@ -88,20 +88,20 @@ public abstract class AsmTest {
88
88
* MethodSource name to be used in parameterized tests that must be instantiated for all possible
89
89
* (precompiled class, api) pairs.
90
90
*/
91
- public final String ALL_CLASSES_AND_ALL_APIS = "allClassesAndAllApis" ;
91
+ public static final String ALL_CLASSES_AND_ALL_APIS = "allClassesAndAllApis" ;
92
92
93
93
/**
94
94
* MethodSource name to be used in parameterized tests that must be instantiated for all
95
95
* precompiled classes, with the latest api.
96
96
*/
97
- public final String ALL_CLASSES_AND_LATEST_API = "allClassesAndLatestApi" ;
97
+ public static final String ALL_CLASSES_AND_LATEST_API = "allClassesAndLatestApi" ;
98
98
99
99
/**
100
100
* A precompiled class, hand-crafted to contain some set of class file structures. These classes
101
101
* are not compiled as part of the build. Instead, they have been compiled beforehand, with the
102
102
* appropriate JDKs (including some now very hard to download and install).
103
103
*/
104
- public static enum PrecompiledClass {
104
+ public enum PrecompiledClass {
105
105
DEFAULT_PACKAGE ("DefaultPackage" ),
106
106
JDK3_ALL_INSTRUCTIONS ("jdk3.AllInstructions" ),
107
107
JDK3_ALL_STRUCTURES ("jdk3.AllStructures" ),
@@ -150,10 +150,7 @@ public boolean isMoreRecentThan(Api api) {
150
150
if (name .startsWith ("jdk8" ) && api .value () < Api .ASM5 .value ()) {
151
151
return true ;
152
152
}
153
- if (name .startsWith ("jdk9" ) && api .value () < Api .ASM6 .value ()) {
154
- return true ;
155
- }
156
- return false ;
153
+ return name .startsWith ("jdk9" ) && api .value () < Api .ASM6 .value ();
157
154
}
158
155
159
156
/**
@@ -165,18 +162,17 @@ public boolean isMoreRecentThan(Api api) {
165
162
*/
166
163
public boolean isMoreRecentThanCurrentJdk () {
167
164
if (name .startsWith ("jdk9" )) {
168
- final String V9 = "1.9" ;
165
+ final String v9 = "1.9" ;
169
166
String javaVersion = System .getProperty ("java.version" );
170
- return javaVersion .substring (V9 .length ()).compareTo (V9 ) < 0 ;
167
+ return javaVersion .substring (v9 .length ()).compareTo (v9 ) < 0 ;
171
168
}
172
169
return false ;
173
170
}
174
171
175
172
/** @return the content of this class. */
176
173
public byte [] getBytes () {
177
- InputStream inputStream = null ;
178
- try {
179
- inputStream = ClassLoader .getSystemResourceAsStream (name .replace ('.' , '/' ) + ".class" );
174
+ String resourceName = name .replace ('.' , '/' ) + ".class" ;
175
+ try (InputStream inputStream = ClassLoader .getSystemResourceAsStream (resourceName )) {
180
176
assertNotNull (inputStream , "Class not found " + name );
181
177
ByteArrayOutputStream outputStream = new ByteArrayOutputStream ();
182
178
byte [] data = new byte [inputStream .available ()];
@@ -188,14 +184,7 @@ public byte[] getBytes() {
188
184
return outputStream .toByteArray ();
189
185
} catch (IOException e ) {
190
186
fail ("Can't read " + name );
191
- return null ;
192
- } finally {
193
- if (inputStream != null ) {
194
- try {
195
- inputStream .close ();
196
- } catch (IOException ignored ) {
197
- }
198
- }
187
+ return new byte [0 ];
199
188
}
200
189
}
201
190
@@ -206,7 +195,7 @@ public String toString() {
206
195
}
207
196
208
197
/** An ASM API version. */
209
- public static enum Api {
198
+ public enum Api {
210
199
ASM4 ("ASM4" , 4 << 16 ),
211
200
ASM5 ("ASM5" , 5 << 16 ),
212
201
ASM6 ("ASM6" , 6 << 16 );
@@ -354,7 +343,7 @@ static boolean doLoadAndInstantiate(String className, byte[] classContent) {
354
343
Class <?> clazz = byteClassLoader .loadClass (className );
355
344
if (!clazz .isEnum () && (clazz .getModifiers () & Modifier .ABSTRACT ) == 0 ) {
356
345
Constructor <?> constructor = clazz .getDeclaredConstructors ()[0 ];
357
- ArrayList <Object > arguments = new ArrayList <Object >();
346
+ ArrayList <Object > arguments = new ArrayList <>();
358
347
for (Class <?> parameterType : constructor .getParameterTypes ()) {
359
348
arguments .add (Array .get (Array .newInstance (parameterType , 1 ), 0 ));
360
349
}
@@ -364,20 +353,14 @@ static boolean doLoadAndInstantiate(String className, byte[] classContent) {
364
353
} catch (ClassNotFoundException e ) {
365
354
// Should never happen given the ByteClassLoader implementation.
366
355
fail ("Can't find class " + className );
367
- } catch (InstantiationException e ) {
368
- // Should never happen since we don't try to instantiate classes
369
- // that can't be instantiated (abstract and enum classes).
370
- fail ("Can't instantiate class " + className );
371
- } catch (IllegalAccessException e ) {
372
- // Should never happen since we use setAccessible(true).
373
- fail ("Can't instantiate class " + className );
374
- } catch (IllegalArgumentException e ) {
375
- // Should never happen since we create the appropriate constructor
376
- // arguments for the expected constructor parameters.
356
+ } catch (InstantiationException | IllegalAccessException | IllegalArgumentException e ) {
357
+ // Should never happen since we don't try to instantiate classes that can't be instantiated
358
+ // (abstract and enum classes), we use setAccessible(true), and we create the appropriate
359
+ // constructor arguments for the expected constructor parameters.
377
360
fail ("Can't instantiate class " + className );
378
361
} catch (InvocationTargetException e ) {
379
- // If an exception occurs in the invoked constructor, it means the
380
- // class was successfully verified first.
362
+ // If an exception occurs in the invoked constructor, it means the class was successfully
363
+ // verified first.
381
364
}
382
365
return byteClassLoader .classLoaded ();
383
366
}
0 commit comments