Skip to content

Commit d60e894

Browse files
[GR-55732] Better error messages for IncompatibleClassChangeError.
PullRequest: graal/18386
2 parents 6c5ee7f + 4aa5661 commit d60e894

File tree

2 files changed

+30
-18
lines changed

2 files changed

+30
-18
lines changed

espresso/src/com.oracle.truffle.espresso/src/com/oracle/truffle/espresso/classfile/constantpool/InterfaceMethodRefConstant.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ public ResolvedConstant resolve(RuntimeConstantPool pool, int thisIndex, ObjectK
120120
// 1. If C is not an interface, interface method resolution throws an
121121
// IncompatibleClassChangeError.
122122
if (!holderInterface.isInterface()) {
123-
throw meta.throwExceptionWithMessage(meta.java_lang_IncompatibleClassChangeError, meta.toGuestString(name));
123+
throw meta.throwExceptionWithMessage(meta.java_lang_IncompatibleClassChangeError, "Found class " + holderInterface.getExternalName() + ", but interface was expected");
124124
}
125125

126126
Symbol<Signature> signature = getSignature(pool);

espresso/src/com.oracle.truffle.espresso/src/com/oracle/truffle/espresso/nodes/BytecodeNode.java

Lines changed: 29 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -2408,7 +2408,10 @@ private InvokeQuickNode dispatchQuickened(int top, int curBCI, char cpi, int opc
24082408
// instruction throws an IncompatibleClassChangeError.
24092409
if (!resolved.isStatic()) {
24102410
enterLinkageExceptionProfile();
2411-
throw throwBoundary(getMethod().getMeta().java_lang_IncompatibleClassChangeError);
2411+
throw throwBoundary(getMethod().getMeta().java_lang_IncompatibleClassChangeError, "Expected static method '%s.%s%s'",
2412+
resolved.getDeclaringKlass().getName(),
2413+
resolved.getName(),
2414+
resolved.getRawSignature());
24122415
}
24132416
break;
24142417
case INVOKEINTERFACE:
@@ -2417,7 +2420,10 @@ private InvokeQuickNode dispatchQuickened(int top, int curBCI, char cpi, int opc
24172420
if (resolved.isStatic() ||
24182421
(getMethod().getContext().getJavaVersion().java8OrEarlier() && resolved.isPrivate())) {
24192422
enterLinkageExceptionProfile();
2420-
throw throwBoundary(getMethod().getMeta().java_lang_IncompatibleClassChangeError);
2423+
throw throwBoundary(getMethod().getMeta().java_lang_IncompatibleClassChangeError, "Expected instance method '%s.%s%s'",
2424+
resolved.getDeclaringKlass().getName(),
2425+
resolved.getName(),
2426+
resolved.getRawSignature());
24212427
}
24222428
if (resolved.getITableIndex() < 0) {
24232429
if (resolved.isPrivate()) {
@@ -2435,7 +2441,10 @@ private InvokeQuickNode dispatchQuickened(int top, int curBCI, char cpi, int opc
24352441
// instruction throws an IncompatibleClassChangeError.
24362442
if (resolved.isStatic()) {
24372443
enterLinkageExceptionProfile();
2438-
throw throwBoundary(getMethod().getMeta().java_lang_IncompatibleClassChangeError);
2444+
throw throwBoundary(getMethod().getMeta().java_lang_IncompatibleClassChangeError, "Expected instance not static method '%s.%s%s'",
2445+
resolved.getDeclaringKlass().getName(),
2446+
resolved.getName(),
2447+
resolved.getRawSignature());
24392448
}
24402449
if (resolved.isFinalFlagSet() || resolved.getDeclaringKlass().isFinalFlagSet() || resolved.isPrivate()) {
24412450
resolvedOpCode = INVOKESPECIAL;
@@ -2450,16 +2459,19 @@ private InvokeQuickNode dispatchQuickened(int top, int curBCI, char cpi, int opc
24502459
enterLinkageExceptionProfile();
24512460
throw throwBoundary(getMethod().getMeta().java_lang_NoSuchMethodError,
24522461
"%s.%s%s",
2453-
resolved.getDeclaringKlass().getNameAsString(),
2454-
resolved.getNameAsString(),
2455-
resolved.getSignatureAsString());
2462+
resolved.getDeclaringKlass().getName(),
2463+
resolved.getName(),
2464+
resolved.getRawSignature());
24562465
}
24572466
}
24582467
// Otherwise, if the resolved method is a class (static) method, the invokespecial
24592468
// instruction throws an IncompatibleClassChangeError.
24602469
if (resolved.isStatic()) {
24612470
enterLinkageExceptionProfile();
2462-
throw throwBoundary(getMethod().getMeta().java_lang_IncompatibleClassChangeError);
2471+
throw throwBoundary(getMethod().getMeta().java_lang_IncompatibleClassChangeError, "Expected instance not static method '%s.%s%s'",
2472+
resolved.getDeclaringKlass().getName(),
2473+
resolved.getName(),
2474+
resolved.getRawSignature());
24632475
}
24642476
// If all of the following are true, let C be the direct superclass of the current
24652477
// class:
@@ -2536,8 +2548,8 @@ private RuntimeException throwBoundary(ObjectKlass exceptionKlass, String messag
25362548
}
25372549

25382550
@TruffleBoundary
2539-
private RuntimeException throwBoundary(ObjectKlass exceptionKlass, String messageFormat, String... args) {
2540-
throw getMeta().throwExceptionWithMessage(exceptionKlass, String.format(Locale.ENGLISH, messageFormat, (Object[]) args));
2551+
private RuntimeException throwBoundary(ObjectKlass exceptionKlass, String messageFormat, Object... args) {
2552+
throw getMeta().throwExceptionWithMessage(exceptionKlass, String.format(Locale.ENGLISH, messageFormat, args));
25412553
}
25422554

25432555
private int quickenInvokeDynamic(final VirtualFrame frame, int top, int curBCI, int opcode) {
@@ -2794,8 +2806,8 @@ private int putField(VirtualFrame frame, int top, Field field, int curBCI, int o
27942806
throw throwBoundary(getMethod().getMeta().java_lang_IncompatibleClassChangeError,
27952807
"Expected %s field %s.%s",
27962808
(opcode == PUTSTATIC) ? "static" : "non-static",
2797-
field.getDeclaringKlass().getNameAsString(),
2798-
field.getNameAsString());
2809+
field.getDeclaringKlass().getName(),
2810+
field.getName());
27992811
}
28002812

28012813
/*
@@ -2813,9 +2825,9 @@ private int putField(VirtualFrame frame, int top, Field field, int curBCI, int o
28132825
throw throwBoundary(getMethod().getMeta().java_lang_IllegalAccessError,
28142826
"Update to %s final field %s.%s attempted from a different class (%s) than the field's declaring class",
28152827
(opcode == PUTSTATIC) ? "static" : "non-static",
2816-
field.getDeclaringKlass().getNameAsString(),
2817-
field.getNameAsString(),
2818-
getDeclaringKlass().getNameAsString());
2828+
field.getDeclaringKlass().getName(),
2829+
field.getName(),
2830+
getDeclaringKlass().getName());
28192831
}
28202832

28212833
boolean enforceInitializerCheck = (getLanguage().getSpecComplianceMode() == STRICT) ||
@@ -2829,9 +2841,9 @@ private int putField(VirtualFrame frame, int top, Field field, int curBCI, int o
28292841
throw throwBoundary(getMethod().getMeta().java_lang_IllegalAccessError,
28302842
"Update to %s final field %s.%s attempted from a different method (%s) than the initializer method %s ",
28312843
(opcode == PUTSTATIC) ? "static" : "non-static",
2832-
field.getDeclaringKlass().getNameAsString(),
2833-
field.getNameAsString(),
2834-
getMethod().getNameAsString(),
2844+
field.getDeclaringKlass().getName(),
2845+
field.getName(),
2846+
getMethod().getName(),
28352847
(opcode == PUTSTATIC) ? "<clinit>" : "<init>");
28362848
}
28372849
}

0 commit comments

Comments
 (0)