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

Annotation processing and "cannot find symbol" errors

    Details

    • Subcomponent:
    • CPU:
      x86
    • OS:
      linux_ubuntu

      Description

      FULL PRODUCT VERSION :
      1.7.0_147 and 1.6.0_22

      A DESCRIPTION OF THE PROBLEM :
      Invoking an annotation processor on a Java file that contains "symbol not found" errors results in multiple reports of the same error and a mismatch in the error number.

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      Create and compile the EmptyProcessor annotation processor from the source code in the "Source code for an executable test case" box.

      Now, let us write the erroneous class E1:

      class E1 {
       int f = "";
      }

      Processing this class results in:

      [emptyproc]$ javac -processor EmptyProcessor E1.java
      Empty Processor run!
      Empty Processor run!
      E1.java:2: incompatible types
      found : java.lang.String
      required: int
       int f = "";
               ^
      1 error

      This is the expected error and the same error is given without
      annotation processing.
      The same output is given for javac 1.6 and 1.7.


      Now, my problem arises when processing a class that contains "cannot
      find symbol" errors.
      Let's take the simple class E2:

      class E2 {
       UNKNOWN f;
      }

      When processing this with javac 1.6 I get:

      [emptyproc]$ javac -version
      javac 1.6.0_22
      [emptyproc]$ javac -processor EmptyProcessor E2.java
      E2.java:2: cannot find symbol
      symbol : class UNKNOWN
      location: class E2
       UNKNOWN f;
       ^
      Empty Processor run!
      Empty Processor run!
      E2.java:2: cannot find symbol
      symbol : class UNKNOWN
      location: class E2
       UNKNOWN f;
       ^
      1 error

      Note how the "cannot find symbol" error is output once before any call
      of process and then again after the two calls of process.
      Also note that the message is output twice, but there is "1 error".

      The output varies when using javac 1.7 (build 147):

      [emptyproc]$ javac -version
      javac 1.7.0
      [emptyproc]$ javac -processor EmptyProcessor E2.java
      Empty Processor run!
      Empty Processor run!
      E2.java:2: error: cannot find symbol
       UNKNOWN f;
       ^
       symbol: class UNKNOWN
       location: class E2
      E2.java:2: error: cannot find symbol
       UNKNOWN f;
       ^
       symbol: class UNKNOWN
       location: class E2
      1 error

      This time the processor is called twice and then afterwards the error
      is reported twice, but there is still only "1 error".


      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      Only a single error report for the "symbol not found" error or two reports and "2 errors" as output.
      The inconsistent and duplicate error reporting is confusing to the users of our annotation processor.

      REPRODUCIBILITY :
      This bug can be reproduced always.

      ---------- BEGIN SOURCE ----------
      import java.util.Set;
      import javax.annotation.processing.*;
      import javax.lang.model.SourceVersion;
      import javax.lang.model.element.TypeElement;

      @SupportedAnnotationTypes("*")
      public class EmptyProcessor extends AbstractProcessor {
          @Override
          public boolean process(Set<? extends TypeElement> annotations,
                  RoundEnvironment roundEnv) {
              System.out.println("Empty Processor run!");
              return false;
          }

          @Override
          public SourceVersion getSupportedSourceVersion() {
              return SourceVersion.latest();
          }
      }

      ---------- END SOURCE ----------

        Attachments

          Issue Links

            Activity

              People

              • Assignee:
                jlahoda Jan Lahoda
                Reporter:
                webbuggrp Webbug Group
              • Votes:
                0 Vote for this issue
                Watchers:
                3 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved:
                  Imported:
                  Indexed: