1 Reply Latest reply: Mar 5, 2010 7:36 AM by 843793 RSS

    Annotation is missing <clinit>

    843793
      Ok, I have seen a few topics on this but none of them have provided a satisfactory answer. Moreover, I have been able to reproduce this issue with a very simple example. Within Eclipse it compiles like a charm but with Sun Java compiler it fails with an unundestandable message. I don't understand why the code below does not work. Is there a nice solution for such pattern or are we forced to store the DEFAULT_CLASS somewhere else? I find it kind of nice to store this in the annotation (it would have even been better to be able to write Class<? extends List> list() default DEFAULT_CLASS; but this is not allowed)
      My config: Windows XP, JDK 1.5.0_22
      import java.util.Vector;
      import java.util.List;
      
      public @interface Test {
      
           public static final Class<? extends List> DEFAULT_CLASS = Vector.class;
      
           Class<? extends List> list() default Vector.class;
      }
      import java.util.Vector;
      
      public class Test1 {
           @Test
           public void hello() {}
      }
      To compile:
      javac Test.java Test1.java
      And the error it produces:
      Test1.java:4: annotation Test is missing <clinit>
              @Test
               ^
      1 error
      I know that this does not do anything and that it's poor code but this is just to have an example.

      Edited by: Guillaume.Polet on Mar 5, 2010 5:23 AM
        • 1. Re: Annotation is missing <clinit>
          843793
          That's a strange error message.

          Interestingly enough it seems to go away when you call javac with the Annotation and the annotated class at the same time ...

          I'd report a bug (and I can confirm that the issue is still existent with Java 6 Update 16). I'd report it against a current JDK, as Java 5 isn't really supported anyway.