Summary
Improve UnsupportedOperationException docs by clarifying the behavior of the no-args constructor.
Problem
The existing Javadoc for the no-args constructor reads:
Constructs an UnsupportedOperationException with no detail message.
The phrase "no detail message" is ambiguous, it may be interpreted as an empty string rather than a null
value. This vagueness is odd, especially given that superclasses and subclasses like RuntimeException
and HeadlessException
are clear that the detail message is null.
Solution
Enhance the javadoc to explicitly state that the no-args constructor always sets the detail message to null
.
Specification
diff --git a/src/java.base/share/classes/java/lang/RuntimeException.java b/src/java.base/share/classes/java/lang/RuntimeException.java
--- a/src/java.base/share/classes/java/lang/RuntimeException.java
+++ b/src/java.base/share/classes/java/lang/RuntimeException.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 1995, 2019, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1995, 2025, 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
@@ -44,7 +44,7 @@
@java.io.Serial
static final long serialVersionUID = -7034897190745766939L;
- /** Constructs a new runtime exception with {@code null} as its
+ /** Constructs a new {@code RuntimeException} with {@code null} as its
* detail message. The cause is not initialized, and may subsequently be
* initialized by a call to {@link #initCause}.
*/
@@ -52,7 +52,7 @@
super();
}
- /** Constructs a new runtime exception with the specified detail message.
+ /** Constructs a new {@code RuntimeException} with the specified detail message.
* The cause is not initialized, and may subsequently be initialized by a
* call to {@link #initCause}.
*
@@ -64,7 +64,7 @@
}
/**
- * Constructs a new runtime exception with the specified detail message and
+ * Constructs a new {@code RuntimeException} with the specified detail message and
* cause. <p>Note that the detail message associated with
* {@code cause} is <i>not</i> automatically incorporated in
* this runtime exception's detail message.
@@ -81,7 +81,7 @@
super(message, cause);
}
- /** Constructs a new runtime exception with the specified cause and a
+ /** Constructs a new {@code RuntimeException} with the specified cause and a
* detail message of {@code (cause==null ? null : cause.toString())}
* (which typically contains the class and detail message of
* {@code cause}). This constructor is useful for runtime exceptions
@@ -98,7 +98,7 @@
}
/**
- * Constructs a new runtime exception with the specified detail
+ * Constructs a new {@code RuntimeException} with the specified detail
* message, cause, suppression enabled or disabled, and writable
* stack trace enabled or disabled.
*
Index: src/java.base/share/classes/java/lang/UnsupportedOperationException.java
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
===================================================================
diff --git a/src/java.base/share/classes/java/lang/UnsupportedOperationException.java b/src/java.base/share/classes/java/lang/UnsupportedOperationException.java
--- a/src/java.base/share/classes/java/lang/UnsupportedOperationException.java
+++ b/src/java.base/share/classes/java/lang/UnsupportedOperationException.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 1997, 2019, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1997, 2025, 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
@@ -37,14 +37,17 @@
*/
public class UnsupportedOperationException extends RuntimeException {
/**
- * Constructs an UnsupportedOperationException with no detail message.
+ * Constructs a new {@code UnsupportedOperationException} with {@code null} as its
+ * detail message. The cause is not initialized, and may subsequently be
+ * initialized by a call to {@link #initCause(Throwable)}.
*/
public UnsupportedOperationException() {
}
/**
- * Constructs an UnsupportedOperationException with the specified
- * detail message.
+ * Constructs a new {@code UnsupportedOperationException} with the specified
+ * detail message. The cause is not initialized, and may subsequently be
+ * initialized by a call to {@link #initCause(Throwable)}.
*
* @param message the detail message
*/
@@ -53,7 +56,7 @@
}
/**
- * Constructs a new exception with the specified detail message and
+ * Constructs a new {@code UnsupportedOperationException} with the specified detail message and
* cause.
*
* <p>Note that the detail message associated with {@code cause} is
@@ -73,7 +76,7 @@
}
/**
- * Constructs a new exception with the specified cause and a detail
+ * Constructs a new {@code UnsupportedOperationException} with the specified cause and a detail
* message of {@code (cause==null ? null : cause.toString())} (which
* typically contains the class and detail message of {@code cause}).
* This constructor is useful for exceptions that are little more than
- csr of
-
JDK-8358618 UnsupportedOperationException constructors javadoc is not clear
-
- In Progress
-