Skip to content

Commit

Permalink
8282776: Bad NullPointerException message when invoking an interface …
Browse files Browse the repository at this point in the history
…MethodHandle on a null receiver

Reviewed-by: psandoz
  • Loading branch information
Mandy Chung committed Mar 29, 2022
1 parent 072f2c4 commit 489b27d
Showing 1 changed file with 16 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -416,9 +416,14 @@ MethodHandle viewAsType(MethodType newType, boolean strict) {
}
Object checkReceiver(Object recv) {
if (!caller.isInstance(recv)) {
String msg = String.format("Receiver class %s is not a subclass of caller class %s",
recv.getClass().getName(), caller.getName());
throw new IncompatibleClassChangeError(msg);
if (recv != null) {
String msg = String.format("Receiver class %s is not a subclass of caller class %s",
recv.getClass().getName(), caller.getName());
throw new IncompatibleClassChangeError(msg);
} else {
String msg = String.format("Cannot invoke %s with null receiver", member);
throw new NullPointerException(msg);
}
}
return recv;
}
Expand All @@ -444,9 +449,14 @@ MethodHandle viewAsType(MethodType newType, boolean strict) {
@Override
Object checkReceiver(Object recv) {
if (!refc.isInstance(recv)) {
String msg = String.format("Receiver class %s does not implement the requested interface %s",
recv.getClass().getName(), refc.getName());
throw new IncompatibleClassChangeError(msg);
if (recv != null) {
String msg = String.format("Receiver class %s does not implement the requested interface %s",
recv.getClass().getName(), refc.getName());
throw new IncompatibleClassChangeError(msg);
} else {
String msg = String.format("Cannot invoke %s with null receiver", member);
throw new NullPointerException(msg);
}
}
return recv;
}
Expand Down

0 comments on commit 489b27d

Please sign in to comment.