Skip to content

Commit 2dafe83

Browse files
committed
Update, review
1 parent d3f4c05 commit 2dafe83

2 files changed

Lines changed: 10 additions & 6 deletions

File tree

src/java.base/share/classes/java/lang/NullPointerException.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ public class NullPointerException extends RuntimeException {
5656
* Constructs a {@code NullPointerException} with no detail message.
5757
*/
5858
public NullPointerException() {
59+
extendedMessageState = 0;
5960
super();
6061
extendedMessageState |= CONSTRUCTOR_FINISHED;
6162
}
@@ -67,15 +68,18 @@ public NullPointerException() {
6768
* @param s the detail message.
6869
*/
6970
public NullPointerException(String s) {
71+
extendedMessageState = 0;
7072
super(s);
7173
extendedMessageState |= CONSTRUCTOR_FINISHED;
7274
}
7375

76+
7477
// Creates an NPE with a custom backtrace configuration.
7578
// The exception has no message if detailed NPE is not enabled.
7679
NullPointerException(int stackOffset, int searchSlot) {
7780
extendedMessageState = setupCustomBackTrace(stackOffset, searchSlot);
78-
this();
81+
super();
82+
extendedMessageState |= CONSTRUCTOR_FINISHED;
7983
}
8084

8185
private static int setupCustomBackTrace(int stackOffset, int searchSlot) {

test/hotspot/jtreg/runtime/exceptionMsgs/NullPointerException/NullCheckAPITest.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -54,15 +54,15 @@ static void nullCheck(Object arg) {
5454
if (arg == null) {
5555
if (NESTED_THROW) {
5656
// 2 offset: nullCheck, throwNpe;
57-
throwNpe();
57+
throwNullPointerException();
5858
} else {
5959
// 1 offset: nullCheck
6060
throw JLA.extendedNullPointerException(1, 0);
6161
}
6262
}
6363
}
6464

65-
static void throwNpe() {
65+
static void throwNullPointerException() {
6666
throw JLA.extendedNullPointerException(2, 0);
6767
}
6868

@@ -90,8 +90,8 @@ class Dummy { Object field; }
9090

9191
@Test
9292
void test() {
93-
checkSimpleMessage(() -> generateVariableNpe(null), "myA");
94-
checkSimpleMessage(() -> generateVariableNpe(new Dummy()), "myA.field");
93+
checkSimpleMessage(() -> generateVariableNullPointerException(null), "myA");
94+
checkSimpleMessage(() -> generateVariableNullPointerException(new Dummy()), "myA.field");
9595

9696
checkInvocationMessage(() -> nullCheck(int.class.getSuperclass()), "java.lang.Class.getSuperclass()");
9797
}
@@ -130,7 +130,7 @@ void testRequireNonNull() {
130130
}
131131

132132
// A method that generate NPE from variables
133-
static void generateVariableNpe(Dummy myA) {
133+
static void generateVariableNullPointerException(Dummy myA) {
134134
nullCheck(myA);
135135
nullCheck(myA.field);
136136
}

0 commit comments

Comments
 (0)