Skip to content

Commit 30be617

Browse files
committed
[GR-65573] Graal error: be pessimistic about exceptions.
PullRequest: graal/21010
2 parents 09a1552 + 3e5a347 commit 30be617

File tree

2 files changed

+34
-14
lines changed

2 files changed

+34
-14
lines changed

compiler/src/jdk.graal.compiler.test/src/jdk/graal/compiler/debug/test/GraalErrorTest.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,4 +131,15 @@ public void testErrorExampels() {
131131
}
132132

133133
}
134+
135+
@Test
136+
public void testNull() {
137+
try {
138+
throw new GraalError("I have a null arg %s %s", "abc", null);
139+
} catch (Throwable t) {
140+
if (LOG_TTY) {
141+
t.printStackTrace();
142+
}
143+
}
144+
}
134145
}

compiler/src/jdk.graal.compiler/src/jdk/graal/compiler/debug/GraalError.java

Lines changed: 23 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)