@@ -133,6 +133,7 @@ public final class WhitelistLoader {
133
133
*/
134
134
public static Whitelist loadFromResourceFiles (Class <?> resource , String ... filepaths ) {
135
135
List <WhitelistClass > whitelistClasses = new ArrayList <>();
136
+ List <WhitelistMethod > whitelistStatics = new ArrayList <>();
136
137
List <WhitelistBinding > whitelistBindings = new ArrayList <>();
137
138
138
139
// Execute a single pass through the whitelist text files. This will gather all the
@@ -192,18 +193,18 @@ public static Whitelist loadFromResourceFiles(Class<?> resource, String... filep
192
193
whitelistConstructors = new ArrayList <>();
193
194
whitelistMethods = new ArrayList <>();
194
195
whitelistFields = new ArrayList <>();
195
- } else if (line .startsWith ("static " )) {
196
+ } else if (line .startsWith ("static_import " )) {
196
197
// Ensure the final token of the line is '{'.
197
198
if (line .endsWith ("{" ) == false ) {
198
199
throw new IllegalArgumentException (
199
- "invalid static definition: failed to parse static opening bracket [" + line + "]" );
200
+ "invalid static import definition: failed to parse static import opening bracket [" + line + "]" );
200
201
}
201
202
202
203
if (parseType != null ) {
203
- throw new IllegalArgumentException ("invalid definition: cannot embed static definition [" + line + "]" );
204
+ throw new IllegalArgumentException ("invalid definition: cannot embed static import definition [" + line + "]" );
204
205
}
205
206
206
- parseType = "static " ;
207
+ parseType = "static_import " ;
207
208
208
209
// Handle the end of a definition and reset all previously gathered values.
209
210
// Expects the following format: '}' '\n'
@@ -229,9 +230,9 @@ public static Whitelist loadFromResourceFiles(Class<?> resource, String... filep
229
230
// Reset the parseType.
230
231
parseType = null ;
231
232
232
- // Handle static definition types.
233
- // Expects the following format: ID ID '(' ( ID ( ',' ID )* )? ')' ' bound_to' ID '\n'
234
- } else if ("static " .equals (parseType )) {
233
+ // Handle static import definition types.
234
+ // Expects the following format: ID ID '(' ( ID ( ',' ID )* )? ')' ( 'from_class' | ' bound_to' ) ID '\n'
235
+ } else if ("static_import " .equals (parseType )) {
235
236
// Mark the origin of this parsable object.
236
237
String origin = "[" + filepath + "]:[" + number + "]" ;
237
238
@@ -240,7 +241,7 @@ public static Whitelist loadFromResourceFiles(Class<?> resource, String... filep
240
241
241
242
if (parameterStartIndex == -1 ) {
242
243
throw new IllegalArgumentException (
243
- "illegal static definition: start of method parameters not found [" + line + "]" );
244
+ "illegal static import definition: start of method parameters not found [" + line + "]" );
244
245
}
245
246
246
247
String [] tokens = line .substring (0 , parameterStartIndex ).trim ().split ("\\ s+" );
@@ -261,7 +262,7 @@ public static Whitelist loadFromResourceFiles(Class<?> resource, String... filep
261
262
262
263
if (parameterEndIndex == -1 ) {
263
264
throw new IllegalArgumentException (
264
- "illegal static definition: end of method parameters not found [" + line + "]" );
265
+ "illegal static import definition: end of method parameters not found [" + line + "]" );
265
266
}
266
267
267
268
String [] canonicalTypeNameParameters =
@@ -272,39 +273,37 @@ public static Whitelist loadFromResourceFiles(Class<?> resource, String... filep
272
273
canonicalTypeNameParameters = new String [0 ];
273
274
}
274
275
275
- // Parse the static type and class.
276
+ // Parse the static import type and class.
276
277
tokens = line .substring (parameterEndIndex + 1 ).trim ().split ("\\ s+" );
277
278
278
- String staticType ;
279
+ String staticImportType ;
279
280
String targetJavaClassName ;
280
281
281
282
// Based on the number of tokens, look up the type and class.
282
283
if (tokens .length == 2 ) {
283
- staticType = tokens [0 ];
284
+ staticImportType = tokens [0 ];
284
285
targetJavaClassName = tokens [1 ];
285
286
} else {
286
- throw new IllegalArgumentException ("invalid static definition: unexpected format [" + line + "]" );
287
+ throw new IllegalArgumentException ("invalid static import definition: unexpected format [" + line + "]" );
287
288
}
288
289
289
- // Check the static type is valid.
290
- if ("bound_to" .equals (staticType ) == false ) {
291
- throw new IllegalArgumentException (
292
- "invalid static definition: unexpected static type [" + staticType + "] [" + line + "]" );
290
+ // Add a static import method or binding depending on the static import type.
291
+ if ("from_class" .equals (staticImportType )) {
292
+ whitelistStatics .add (new WhitelistMethod (origin , targetJavaClassName ,
293
+ methodName , returnCanonicalTypeName , Arrays .asList (canonicalTypeNameParameters )));
294
+ } else if ("bound_to" .equals (staticImportType )) {
295
+ whitelistBindings .add (new WhitelistBinding (origin , targetJavaClassName ,
296
+ methodName , returnCanonicalTypeName , Arrays .asList (canonicalTypeNameParameters )));
297
+ } else {
298
+ throw new IllegalArgumentException ("invalid static import definition: " +
299
+ "unexpected static import type [" + staticImportType + "] [" + line + "]" );
293
300
}
294
301
295
- whitelistBindings .add (new WhitelistBinding (origin , targetJavaClassName ,
296
- methodName , returnCanonicalTypeName , Arrays .asList (canonicalTypeNameParameters )));
297
-
298
302
// Handle class definition types.
299
303
} else if ("class" .equals (parseType )) {
300
304
// Mark the origin of this parsable object.
301
305
String origin = "[" + filepath + "]:[" + number + "]" ;
302
306
303
- // Ensure we have a defined class before adding any constructors, methods, augmented methods, or fields.
304
- if (parseType == null ) {
305
- throw new IllegalArgumentException ("invalid definition: expected one of ['class', 'static'] [" + line + "]" );
306
- }
307
-
308
307
// Handle the case for a constructor definition.
309
308
// Expects the following format: '(' ( ID ( ',' ID )* )? ')' '\n'
310
309
if (line .startsWith ("(" )) {
@@ -393,7 +392,7 @@ public static Whitelist loadFromResourceFiles(Class<?> resource, String... filep
393
392
394
393
ClassLoader loader = AccessController .doPrivileged ((PrivilegedAction <ClassLoader >)resource ::getClassLoader );
395
394
396
- return new Whitelist (loader , whitelistClasses , whitelistBindings );
395
+ return new Whitelist (loader , whitelistClasses , whitelistStatics , whitelistBindings );
397
396
}
398
397
399
398
private WhitelistLoader () {}
0 commit comments