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/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,8 +56,8 @@
}
/**
- * Constructs a new exception with the specified detail message and
- * cause.
+ * Constructs a new {@code UnsupportedOperationException} 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 exception's detail
@@ -73,8 +76,9 @@
}
/**
- * Constructs a new exception with the specified cause and a detail
- * message of {@code (cause==null ? null : cause.toString())} (which
+ * 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
* wrappers for other throwables (for example, {@link
- csr of
-
JDK-8358618 UnsupportedOperationException constructors javadoc is not clear
-
- Resolved
-