JDK-8209865 : Incorrect 'multiple elements' notes with Elements#getTypeElement and --release
  • Type: Bug
  • Component: tools
  • Sub-Component: javac
  • Affected Version: 10,11
  • Priority: P2
  • Status: Closed
  • Resolution: Fixed
  • Submitted: 2018-08-23
  • Updated: 2018-09-29
  • Resolved: 2018-09-21
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
JDK 12
12 b13Fixed
Related Reports
Relates :  
Description
In the following example `getTypeElement("javax.annotation.processing.Generated")` incorrectly returns null and results in a spurious 'multiple elements' warning when using --release < 11.

javax.annotation.processing.Generated is a member of java.compiler and none of the other named modules, so `getTypeElement("javax.annotation.processing.Generated")` is not ambiguous.

The same issue affects JDK 10 and --release 9.

=== 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.SourceVersion;
import javax.lang.model.element.TypeElement;

@SupportedAnnotationTypes("*")
public class P extends AbstractProcessor {

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

  @Override
  public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) {
    System.err.println(
        processingEnv.getElementUtils().getTypeElement("javax.annotation.processing.Generated"));
    return false;
  }
}
=== T.java
@Deprecated
class T {
}
===

$ javac -fullversion -processor P --release 9 T.java 
javac full version "11+27"
null
Note: Multiple elements named 'javax.annotation.processing.Generated' in modules 'java.base, java.compiler, jdk.management, java.management, jdk.sctp, jdk.jconsole, jdk.management.agent, java.management.rmi, java.naming, java.security.sasl, java.logging, java.rmi, jdk.attach, java.desktop, java.datatransfer, java.xml, java.prefs, jdk.jdi, jdk.jdwp.agent, jdk.httpserver, jdk.unsupported, jdk.scripting.nashorn, java.scripting, jdk.dynalink, jdk.jartool, jdk.security.auth, java.security.jgss, jdk.accessibility, jdk.security.jgss, jdk.xml.dom, jdk.jsobject, jdk.net, java.sql.rowset, java.sql, java.instrument, java.xml.crypto' were found by javax.lang.model.util.Elements.getTypeElement.
null
Comments
As a workaround, it may be possible to explicitly request the module the type belongs to. Including a note from the review thread of JDK-8190886: "On the testing sides, as discussed in JEP 200 when the compiler is running in single-module mode (which includes when compiling a module-info file), all the files being compiled are assumed to be in that module even if they would not be in the module by virtue of their file system locations. This necessitates some of the testing conditions being conditionally excluded."
23-08-2018