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

package-info handling in RoundEnvironment.getElementsAnnotatedWith

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Resolved
    • Priority: P3
    • Resolution: Fixed
    • Affects Version/s: 9
    • Fix Version/s: 12
    • Component/s: tools
    • Labels:
      None
    • Subcomponent:
    • Resolved In Build:
      b05

      Description

      My colleague Ron Shapiro noticed an issue with the implementation of RoundEnvironment.getElementsAnnotatedWith. The javadoc for that method specifies:

      > Elements in a package are not considered included simply because a package-info file for that package was created.

      However that doesn't match the behaviour we're seeing. Instead, getElementsAnnotatedWith is returning annotated members in a compilation with a package-info on the class path.

      Reproduced using javac 9.0.1+11:

      === ./foo/A.java ===
      package foo;
      class A {
        B b;
      }
      === ./foo/B.java ===
      package foo;
      @Deprecated
      class B {}
      === ./foo/package-info.java ===
      @Deprecated
      package foo;
      === ./P.java ===
      import java.util.Set;
      import javax.annotation.processing.AbstractProcessor;
      import javax.annotation.processing.RoundEnvironment;
      import javax.annotation.processing.SupportedAnnotationTypes;
      import javax.lang.model.element.TypeElement;

      @SupportedAnnotationTypes("*")
      public class P extends AbstractProcessor {
        @Override
        public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) {
          System.err.println(">>> " + roundEnv.getElementsAnnotatedWith(Deprecated.class));
          return false;
        }
      }
      ===

      $ javac P.java foo/B.java
      $ javac -processor P -cp . -sourcepath : foo/A.java foo/package-info.java
      ...
      >>> [foo, foo.B]

      Note that getElementsAnnotatedWith returns foo.B, which is a member of the package foo, but which is not part of the current compilation.

        Attachments

          Issue Links

            Activity

              People

              • Assignee:
                darcy Joe Darcy
                Reporter:
                cushon Liam Miller-Cushon
              • Votes:
                0 Vote for this issue
                Watchers:
                2 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved: