@@ -283,30 +283,39 @@ public GraalError(Throwable cause, String msg, Object... args) {
283283 }
284284
285285 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 ]);
292301 if (potentialBetterString != null ) {
293302 betterContext .add (potentialBetterString );
294303 }
295304 }
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 ()));
301308 }
302309 }
303- if (!betterContext .isEmpty ()) {
304- addContext (Arrays .toString (betterContext .toArray ()));
305- }
310+ } catch (Throwable t ) {
311+ addContext ("Intercepted error in potentiallyAddContext: " + t );
306312 }
307313 }
308314
309315 private static String potentialBetterString (Object o ) {
316+ if (o == null ) {
317+ return null ;
318+ }
310319 Object potentialBetterString = Assertions .decorateObjectErrorContext (o );
311320 if (!potentialBetterString .toString ().equals (o .toString ())) {
312321 return potentialBetterString .toString ();
0 commit comments