src/java.base/share/classes/java/lang/NullPointerException.java
branchdatagramsocketimpl-branch
changeset 58678 9cf78a70fa4f
parent 47216 71c04702a3d5
child 58679 9c3209ff7550
--- a/src/java.base/share/classes/java/lang/NullPointerException.java	Thu Oct 17 20:27:44 2019 +0100
+++ b/src/java.base/share/classes/java/lang/NullPointerException.java	Thu Oct 17 20:53:35 2019 +0100
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 1994, 2011, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1994, 2019, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -51,6 +51,7 @@
  */
 public
 class NullPointerException extends RuntimeException {
+    @java.io.Serial
     private static final long serialVersionUID = 5162710183389028792L;
 
     /**
@@ -69,4 +70,35 @@
     public NullPointerException(String s) {
         super(s);
     }
+
+    /**
+     * Returns the detail message string of this throwable.
+     *
+     * <p> If a non-null message was supplied in a constructor it is
+     * returned. Otherwise, an implementation specific message or
+     * {@code null} is returned.
+     *
+     * @implNote
+     * If no explicit message was passed to the constructor, and as
+     * long as certain internal information is available, a verbose
+     * description of the null reference is returned.
+     * The internal information is not available in deserialized
+     * NullPointerExceptions.
+     *
+     * @return the detail message string, which may be {@code null}.
+     */
+    public String getMessage() {
+        String message = super.getMessage();
+        if (message == null) {
+            return getExtendedNPEMessage();
+        }
+        return message;
+    }
+
+    /**
+     * Get an extended exception message. This returns a string describing
+     * the location and cause of the exception. It returns null for
+     * exceptions where this is not applicable.
+     */
+    private native String getExtendedNPEMessage();
 }