Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8358618

UnsupportedOperationException no-args constructor javadoc is not clear

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Unresolved
    • Icon: P4 P4
    • tbd
    • 8, 11, 17, 21, 25
    • core-libs

      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 "".

            nbenalla Nizar Benalla
            prr Philip Race
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated: