The no-args constructor for UnsupportedOperationException has this specification and implemention
/**
* Constructs an UnsupportedOperationException with no detail message.
*/
public UnsupportedOperationException() {
}
The parent class - RuntimeException is like this
/** Constructs a new runtime exception with {@code null} as its
* detail message. The cause is not initialized, and may subsequently be
* initialized by a call to {@link #initCause}.
*/
public RuntimeException() {
super();
}
So RuntimeException is clear that the detail message is null.
And the parents -> Exception -> Throwable are the same.
But UnsupportedOperationException is less clear - "no detail message" could mean null, or it could be interpreted as an empty string.
However it does behave as per its super-classes.
public class USOE {
public static void main(String[] args) {
UnsupportedOperationException e = new UnsupportedOperationException();
System.out.println(e.getMessage());
}
}
% java USOE.java
null
That vagueness could in part explain why a subclass of UnsupportedOperationException - java.awt.HeadlessException says
"Constructs new HeadlessException with empty message" - so that in some cases it will also report null, not "".
/**
* Constructs an UnsupportedOperationException with no detail message.
*/
public UnsupportedOperationException() {
}
The parent class - RuntimeException is like this
/** Constructs a new runtime exception with {@code null} as its
* detail message. The cause is not initialized, and may subsequently be
* initialized by a call to {@link #initCause}.
*/
public RuntimeException() {
super();
}
So RuntimeException is clear that the detail message is null.
And the parents -> Exception -> Throwable are the same.
But UnsupportedOperationException is less clear - "no detail message" could mean null, or it could be interpreted as an empty string.
However it does behave as per its super-classes.
public class USOE {
public static void main(String[] args) {
UnsupportedOperationException e = new UnsupportedOperationException();
System.out.println(e.getMessage());
}
}
% java USOE.java
null
That vagueness could in part explain why a subclass of UnsupportedOperationException - java.awt.HeadlessException says
"Constructs new HeadlessException with empty message" - so that in some cases it will also report null, not "".
- relates to
-
JDK-8358526 The OpenJDK implementation of no-args java.awt.HeadlessException class constructor doesn't follow the specification
-
- Open
-