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

(ann) unspecified behavior of Package.isAnnotationPresent(null)

    XMLWordPrintable

Details

    • generic
    • generic

    Description



      Name: viR10068 Date: 04/29/2004


      The spec for the Package.isAnnotationPresent(Class<? extends Annotation>) says:
      "Description copied from interface: AnnotatedElement"

      But the "Throws" statement was not copy and behavior for the null parameter
      is undefined (spec for AnnotatedElement.isAnnotationPresent requires the
      NullPointerException in this case). So the spec should be clarified.

      The RI behavior also should be unified. Now, the RI (jdk15-b49) throws the
      NullPointerException for the default package and does not throw it for any
      other.

      The new JCK test fails due to this bug:
      api/java_lang/Package/index.html#isAnnotPresent[isAnnotPresent0002]

      The sources:
      ---------------------B.java---------------------------
      package B;
      import java.io.PrintStream;

      class B {

          public static void main(String argv[]) {
              try {
                  B.class.getPackage().isAnnotationPresent(null);
                  System.out.println("Ups NullPointerException expected");
              } catch (NullPointerException npe) {
                  System.out.println("OKAY");
              }
          }
      }
      ---------------------Bb.java--------------------------
      import java.io.PrintStream;

      class Bb {

          public static void main(String argv[]) {
              try {
                  Bb.class.getPackage().isAnnotationPresent(null);
                  System.out.println("Ups NullPointerException expected");
              } catch (NullPointerException npe) {
                  System.out.println("OKAY");
              }
          }
      }
      ------------------------------------------------------
      The execution log:
      % jdk1.5.0-b49/solaris-sparc/bin/javac -d . B.java && jdk1.5.0-b49/solaris-sparc/bin/java
      -showversion B.B
      java version "1.5.0-beta2"
      Java(TM) 2 Runtime Environment, Standard Edition (build 1.5.0-beta2-b49)
      Java HotSpot(TM) Client VM (build 1.5.0-beta2-b49, mixed mode)

      java.lang.ClassNotFoundException: B.package-info
              at java.net.URLClassLoader$1.run(URLClassLoader.java:200)
              at java.security.AccessController.doPrivileged(Native Method)
              at java.net.URLClassLoader.findClass(URLClassLoader.java:188)
              at java.lang.ClassLoader.loadClass(ClassLoader.java:290)
              at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:279)
              at java.lang.ClassLoader.loadClass(ClassLoader.java:236)
              at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:303)
              at java.lang.Class.forName0(Native Method)
              at java.lang.Class.forName(Class.java:237)
              at java.lang.Package.getPackageInfo(Package.java:350)
              at java.lang.Package.isAnnotationPresent(Package.java:372)
              at B.B.main(B.java:8)
      Ups NullPointerException expected
      % jdk1.5.0-b49/solaris-sparc/bin/javac -d . Bb.java && jdk1.5.0-b49/solaris-sparc/bin/java
      -showversion Bb
      java version "1.5.0-beta2"
      Java(TM) 2 Runtime Environment, Standard Edition (build 1.5.0-beta2-b49)
      Java HotSpot(TM) Client VM (build 1.5.0-beta2-b49, mixed mode)

      OKAY
      %


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

      Attachments

        Activity

          People

            darcy Joe Darcy
            vivsunw Viv Viv (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: