@@ -283,30 +283,39 @@ public GraalError(Throwable cause, String msg, Object... args) {
283
283
}
284
284
285
285
private void potentiallyAddContext (Object [] args ) {
286
- if (args != null ) {
287
- List <String > betterContext = new ArrayList <>();
288
- for (int i = 0 ; i < args .length ; i ++) {
289
- if (args [i ] instanceof Iterable <?>) {
290
- for (Object o : (Iterable <?>) args [i ]) {
291
- String potentialBetterString = potentialBetterString (o );
286
+ // be pessimistic here and ensure better reporting never causes a follow up error that is
287
+ // unhandled
288
+ try {
289
+ if (args != null ) {
290
+ List <String > betterContext = new ArrayList <>();
291
+ for (int i = 0 ; i < args .length ; i ++) {
292
+ if (args [i ] instanceof Iterable <?>) {
293
+ for (Object o : (Iterable <?>) args [i ]) {
294
+ String potentialBetterString = potentialBetterString (o );
295
+ if (potentialBetterString != null ) {
296
+ betterContext .add (potentialBetterString );
297
+ }
298
+ }
299
+ } else {
300
+ String potentialBetterString = potentialBetterString (args [i ]);
292
301
if (potentialBetterString != null ) {
293
302
betterContext .add (potentialBetterString );
294
303
}
295
304
}
296
- } else {
297
- String potentialBetterString = potentialBetterString (args [i ]);
298
- if (potentialBetterString != null ) {
299
- betterContext .add (potentialBetterString );
300
- }
305
+ }
306
+ if (!betterContext .isEmpty ()) {
307
+ addContext (Arrays .toString (betterContext .toArray ()));
301
308
}
302
309
}
303
- if (!betterContext .isEmpty ()) {
304
- addContext (Arrays .toString (betterContext .toArray ()));
305
- }
310
+ } catch (Throwable t ) {
311
+ addContext ("Intercepted error in potentiallyAddContext: " + t );
306
312
}
307
313
}
308
314
309
315
private static String potentialBetterString (Object o ) {
316
+ if (o == null ) {
317
+ return null ;
318
+ }
310
319
Object potentialBetterString = Assertions .decorateObjectErrorContext (o );
311
320
if (!potentialBetterString .toString ().equals (o .toString ())) {
312
321
return potentialBetterString .toString ();
0 commit comments