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

Annotations cannot contain member fields of type Class<?>

XMLWordPrintable

    • x86
    • windows_vista

      FULL PRODUCT VERSION :
      cygwin$ java -version
      java version "1.6.0_20"
      Java(TM) SE Runtime Environment (build 1.6.0_20-b02)
      Java HotSpot(TM) Client VM (build 16.3-b01, mixed mode, sharing)

      ADDITIONAL OS VERSION INFORMATION :
      Windows Vista 32bit, Mac OS X 10.6 64bit, Linux (unknown)

      EXTRA RELEVANT SYSTEM CONFIGURATION :
      Standard JDK

      A DESCRIPTION OF THE PROBLEM :
      It appears that annotations cannot contain member fields of type Class<?>. I have been able to successfully compile all applicable test code when commenting out these member fields. And when I uncomment them, the build fails.

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      Create an annotation that contains a member field of type Class<?> or Class<? extends SomeClass> and apply it to a field. Compile your code.

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      Code compiles.
      ACTUAL -
      Code fails with error like this:


      /build/data/bamboo/xml-data/build-dir/BUSINESSSERVICESLOCATIONGEOSPATIAL-GEOSPATIALMANAGEMENTTRUNK/geospatial-management-web/src/main/java/com/lmig/reuse/geospatial/management/model/Category.java:[33,0] annotation com.lmig.reuse.geospatial.management.promotion.Promotable is missing <clinit>

      /build/data/bamboo/xml-data/build-dir/BUSINESSSERVICESLOCATIONGEOSPATIAL-GEOSPATIALMANAGEMENTTRUNK/geospatial-management-web/src/main/java/com/lmig/reuse/geospatial/management/model/Feature.java:[42,0] annotation com.lmig.reuse.geospatial.management.promotion.Promotable is missing <clinit>

      ERROR MESSAGES/STACK TRACES THAT OCCUR :
      /build/data/bamboo/xml-data/build-dir/BUSINESSSERVICESLOCATIONGEOSPATIAL-GEOSPATIALMANAGEMENTTRUNK/geospatial-management-web/src/main/java/com/lmig/reuse/geospatial/management/model/Feature.java:[42,0] annotation com.lmig.reuse.geospatial.management.promotion.Promotable is missing <clinit>

      REPRODUCIBILITY :
      This bug can be reproduced always.

      ---------- BEGIN SOURCE ----------
      package name.redacted;

      import java.lang.annotation.Documented;
      import java.lang.annotation.ElementType;
      import java.lang.annotation.Retention;
      import java.lang.annotation.RetentionPolicy;
      import java.lang.annotation.Target;

      /**
       * [[redacted]]
       *
       * @author Ted Pennings
       */
      @Documented
      @Retention(RetentionPolicy.RUNTIME)
      @Target(ElementType.TYPE)
      public @interface Redacted{

          /**
           * [[redacted]]
           */
          public static final Class<? extends RedactedSuperClass> DEFAULT_IMPLEMENTATION = RedactedDefaultImplementation.class;

          /**
           * [[redacted]]
           */
          Class<? extends RedactedSuperClass> redactedMethod() default RedactedDefaultImplementation.class;

      }

      --- SEPARATE CLASS AND SEPARATE FILE --


      @Redacted
      public class SomeEntity {

       //do some stuff
      }
      ---------- END SOURCE ----------

      CUSTOMER SUBMITTED WORKAROUND :
      Remove the field Class<?>

      SUPPORT :
      YES

            mcimadamore Maurizio Cimadamore
            webbuggrp Webbug Group
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: