3 Replies Latest reply: Nov 14, 2008 9:36 PM by 843793 RSS

    apt @Override annotation

    843793
      Hello!

      I am having the following problem with apt: if I run it against an input file which uses the @Override annotation, I get the following warning:
      warning: Annotation types without processors: [java.lang.Override]
      More specifically: I have the following input file:
      public class test {
          @Override
          public String toString() {
              return super.toString();
          }
      }
      and I run apt on it:
      bash-3.2$ apt -XListAnnotationTypes -XPrintFactoryInfo -XPrintAptRounds ~/work/test.java
      apt Round : 1
      filenames: [/user/fabratu/home/work/test.java]
      options: com.sun.tools.javac.util.Options@e5b723
      Set of annotations found:[java.lang.Override]
      Factory com.sun.istack.internal.ws.AnnotationProcessorFactoryImpl matches nothing.
      warning: Annotation types without processors: [java.lang.Override]
      1 warning
      My question is: how to get rid of the warning? This gets especially annoying when I develop my own annotations and annotation processors, and when I run apt against inputs that are valid from my processors' point of view, I still get a warning.

      One solution would be just to add @Override to the supportedAnnotations list of my factories (or directly add "*") but I don't want to do that.
      Initially I thought that there would be some AnnotationProcessorFactory that processes @Override somewhere inside the JDK jars. That's why I've tried:
      bash-3.2$ apt -XListAnnotationTypes -XPrintFactoryInfo -XPrintAptRounds -cp $CLASSPATH:$JAVA_HOME/lib/* ~/work/test.java
      apt Round : 1
      filenames: [/user/fabratu/home/work/test.java]
      options: com.sun.tools.javac.util.Options@15a8767
      Set of annotations found:[java.lang.Override]
      Factory com.sun.istack.internal.ws.AnnotationProcessorFactoryImpl matches nothing.
      warning: Annotation types without processors: [java.lang.Override]
      1 warning
      As you can see, no luck here.
      Any clues?
      I use JDK 1.6.0_02

      Cheers,
      Florin.
        • 1. Re: apt @Override annotation
          608410
          Unless you are stuck on java 5, then use the javax.annotation.processing and javax.lang.model packages (the newer JSR269 replacement for APT) in JDK6+

          If you must use the APT ? Mirror API combination, then you could write a dummy processor that claims all the standard annotations and does nothing. This would be better (IMHO) than bundling that functionality in with your actual processor. (Keep the worker part separate from the bit that works around the annoying warnings.

          Bruce

          Edited by: brucechapman on 10/11/2008 09:28
          • 2. Re: apt @Override annotation
            843793
            Hello!
            Sorry for the late reply, I was on vacation for a while.
            If you must use the APT ? Mirror API combination,
            Unfortunately, I must also support Java 5, so I must have a solution using APT and the Mirror API
            then you could write a dummy processor that claims all the standard annotations and does nothing. This would be better (IMHO) than bundling that functionality in with your actual processor. (Keep the worker part separate >from the bit that works around the annoying warnings.
            Ok, that could work. Thanks for the idea.
            So, this is a known issue for apt and JDK 1.5?

            cheers,
            Florin.
            • 3. Re: apt @Override annotation
              843793
              >
              [snip]
              then you could write a dummy processor that claims all the standard annotations and does nothing. This would be better (IMHO) than bundling that functionality in with your actual processor. (Keep the worker part separate >from the bit that works around the annoying warnings.
              Ok, that could work. Thanks for the idea.
              So, this is a known issue for apt and JDK 1.5?
              Yes, apt has always behaved that way.

              In retrospect, at least the annotations that come with the platform, like @Override and @Deprecated, should have been excluded from that warning. The warning itself by default is overkill; javac only emits the analogous warning if an annotation processing lint option is used.