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

The behavior of UnsupportedFlavorException constructor is incorrect

XMLWordPrintable

    • beta
    • sparc
    • solaris_2.6



      Name: dsR10051 Date: 11/16/2000


      The constructor
      java.awt.datatransfer.UnsupportedFlavorException(DataFlavor flavor)
      throws NullPointerException if flavor parameter is null.
      Thare are three resons to consider this behavior as incorrect:
      1. It seems to be poor behavior for exception to fail
         an initialization time.
      2. The NullPointerException is subclass of java.lang.RuntimeException,
         but UnsupportedFlavorException is not. So, if method foo () declares the throwing
         of UnsupportedFlavorException, exception should be handled and processed by user.
         It may be not done for NullPointerException. NPE in this case may be cause
         abnormal execution of program.
      3. It is inconsistent behavior for full exception hierarchy. I could not find
         other Exception subclass that documents the throwing of another exception
         in constructor.

      Here is a minimized test:

      import java.awt.datatransfer.UnsupportedFlavorException;
      import java.awt.datatransfer.DataFlavor;

      public class UnsupportedFlavorExceptionTest01 {
          public static void main(String[] args) {
              try {
                  foo();
              } catch (UnsupportedFlavorException ufe) {
              }
              System.out.println("OKAY");
              System.exit(0);
          }

          public static void foo() throws UnsupportedFlavorException{
              throw new UnsupportedFlavorException((DataFlavor) null);
          }
      }

      --- Output ---
      %java -version
      java version "1.4.0beta"
      Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.0beta-b40)
      Java HotSpot(TM) Client VM (build 1.4beta-B40, mixed mode)
      %java UnsupportedFlavorExceptionTest01
      Exception in thread "main" java.lang.NullPointerException
              at java.awt.datatransfer.UnsupportedFlavorException.<init>(UnsupportedFlavorException.java:36)
              at UnsupportedFlavorExceptionTest01.foo(UnsupportedFlavorExceptionTest01.java:15)
              at UnsupportedFlavorExceptionTest01.main(UnsupportedFlavorExceptionTest01.java:7)

      ======================================================================

            dmendenhsunw David Mendenhall (Inactive)
            sdasunw Sda Sda (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: