@@ -329,6 +329,10 @@ public static CallSite makeConcatWithConstants(MethodHandles.Lookup lookup,
329
329
Objects .requireNonNull (concatType , "Concat type is null" );
330
330
Objects .requireNonNull (constants , "Constants are null" );
331
331
332
+ for (Object o : constants ) {
333
+ Objects .requireNonNull (o , "Cannot accept null constants" );
334
+ }
335
+
332
336
if ((lookup .lookupModes () & MethodHandles .Lookup .PRIVATE ) == 0 ) {
333
337
throw new StringConcatException ("Invalid caller: " +
334
338
lookup .lookupClass ().getName ());
@@ -382,11 +386,11 @@ private static List<String> parseRecipe(MethodType concatType,
382
386
if (c == TAG_CONST ) {
383
387
if (cCount == constants .length ) {
384
388
// Not enough constants
385
- throw constantMismatch (concatType , oCount );
389
+ throw constantMismatch (constants , cCount );
386
390
}
387
391
// Accumulate constant args along with any constants encoded
388
392
// into the recipe
389
- acc .append (Objects . requireNonNull ( constants [cCount ++], "Cannot accept null constants" ) );
393
+ acc .append (constants [cCount ++]);
390
394
} else if (c == TAG_ARG ) {
391
395
// Flush any accumulated characters into a constant
392
396
if (acc .length () > 0 ) {
@@ -406,28 +410,32 @@ private static List<String> parseRecipe(MethodType concatType,
406
410
if (acc .length () > 0 ) {
407
411
elements .add (acc .toString ());
408
412
}
409
-
410
413
if (oCount != concatType .parameterCount ()) {
411
- throw constantMismatch (concatType , oCount );
414
+ throw argumentMismatch (concatType , oCount );
412
415
}
413
- if (cCount != constants .length ) {
414
- throw new StringConcatException (
415
- "Mismatched number of concat constants: recipe wants " +
416
- cCount +
417
- " constants, but only " +
418
- constants .length +
419
- " are passed" );
416
+ if (cCount < constants .length ) {
417
+ throw constantMismatch (constants , cCount );
420
418
}
421
419
return elements ;
422
420
}
423
421
424
- private static StringConcatException constantMismatch (MethodType concatType ,
422
+ private static StringConcatException argumentMismatch (MethodType concatType ,
425
423
int oCount ) {
426
424
return new StringConcatException (
427
425
"Mismatched number of concat arguments: recipe wants " +
428
- oCount +
429
- " arguments, but signature provides " +
430
- concatType .parameterCount ());
426
+ oCount +
427
+ " arguments, but signature provides " +
428
+ concatType .parameterCount ());
429
+ }
430
+
431
+ private static StringConcatException constantMismatch (Object [] constants ,
432
+ int cCount ) {
433
+ return new StringConcatException (
434
+ "Mismatched number of concat constants: recipe wants " +
435
+ cCount +
436
+ " constants, but only " +
437
+ constants .length +
438
+ " are passed" );
431
439
}
432
440
433
441
/**
0 commit comments