src/java.base/share/classes/java/lang/NullPointerException.java
changeset 58664 e3618c902d17
parent 57956 e0b8b019d2f5
child 58679 9c3209ff7550
child 59201 b24f4caa1411
--- a/src/java.base/share/classes/java/lang/NullPointerException.java	Thu Oct 17 10:35:18 2019 +0200
+++ b/src/java.base/share/classes/java/lang/NullPointerException.java	Mon Oct 14 11:36:17 2019 +0200
@@ -70,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();
 }