Skip to content

Commit

Permalink
NullPointerException(null).getMessage() returns null
Browse files Browse the repository at this point in the history
NullPointerException(null).getMessage() should return null;
Added a test.

Signed-off-by: Jason Feng <fengj@ca.ibm.com>
  • Loading branch information
JasonFengJ9 committed Nov 15, 2020
1 parent 0e8f48a commit dfec1a1
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
8 changes: 3 additions & 5 deletions runtime/vm/extendedMessageNPE.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -532,11 +532,9 @@ getCompleteNPEMessage(J9VMThread *vmThread, U_8 *bcCurrentPtr, J9ROMClass *romCl

if (J9UTF8_LITERAL_EQUALS(J9UTF8_DATA(definingClassFullQualifiedName), J9UTF8_LENGTH(definingClassFullQualifiedName), "java/lang/NullPointerException")) {
if (J9UTF8_LITERAL_EQUALS(J9UTF8_DATA(methodName), J9UTF8_LENGTH(methodName), "<init>")) {
if (J9UTF8_LITERAL_EQUALS(J9UTF8_DATA(methodSig), J9UTF8_LENGTH(methodSig), "()V")) {
/* No message generated for new NullPointerException().getMessage() */
npeMsgRequired = false;
Trc_VM_GetCompleteNPEMessage_Not_Required(vmThread);
}
/* No message generated for new NullPointerException().getMessage() or new NullPointerException(null).getMessage() */
npeMsgRequired = false;
Trc_VM_GetCompleteNPEMessage_Not_Required(vmThread);
}

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1015,6 +1015,8 @@ public void test_parameters_4() {
public void test_creation() throws Exception {
Assert.assertNull(new NullPointerException().getMessage(),
"new NullPointerException().getMessage() is not null!");
Assert.assertNull(new NullPointerException(null).getMessage(),
"new NullPointerException(null).getMessage() is not null!");
String npeMsg = new String("NPE creation messsage");
Assert.assertEquals(new NullPointerException(npeMsg).getMessage(), npeMsg);
Exception exception = NullPointerException.class.getDeclaredConstructor().newInstance();
Expand Down

0 comments on commit dfec1a1

Please sign in to comment.