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

Problem caused by imports in a module-info.java file

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Resolved
    • Priority: P3
    • Resolution: Fixed
    • Affects Version/s: 13
    • Fix Version/s: 14
    • Component/s: tools
    • Labels:
      None
    • Subcomponent:
    • Resolved In Build:
      b27

      Backports

        Description

        The presence of imports in a module-info causes issues for annotation processing.

        For full details, see the original email here:
        https://mail.openjdk.java.net/pipermail/compiler-dev/2019-December/014009.html

        Extract from email follows:

        > The second issue occurs when you want to use imports in a module-info.java
        > file, if you do so the file is simply ignored during annotation processing.
        > This issue also exists on all versions since JDK 9. Let's say we have the
        > following module descriptor:
        >
        > import com.example.SampleAnnotation;
        >
        > @SampleAnnotation
        > module sampleModule {
        >
        > }
        >
        > and a properly configured annotation processor to process the
        > @com.example.SampleAnnotation, the compiler simply doesn't take the module
        > into account when processing annotation.
        >
        > I've been able to track down the issue in
        > com.sun.tools.javac.processing.JavacProcessingEnvironment#getModuleInfoFiles()
        >
        > private List<ModuleSymbol> getModuleInfoFiles(List<? extends
        > JCCompilationUnit> units) {
        > List<ModuleSymbol> modules = List.nil();
        > for (JCCompilationUnit unit : units) {
        > if (isModuleInfo(unit.sourcefile, JavaFileObject.Kind.SOURCE) &&
        > unit.defs.nonEmpty() &&
        > unit.defs.head.hasTag(Tag.MODULEDEF)) {
        > modules = modules.prepend(unit.modle);
        > }
        > }
        > return modules.reverse();
        > }
        >
        > Here it is assumed that the first unit in a module descriptor has to be a
        > module statement however according to the java language specification, a
        > module descriptor can have import statements before (and this actually
        > compiles just fine) as a result the module is not added to the list of
        > modules candidates for annotation processing.
        >

          Attachments

            Issue Links

              Activity

                People

                Assignee:
                jjg Jonathan Gibbons
                Reporter:
                jjg Jonathan Gibbons
                Votes:
                0 Vote for this issue
                Watchers:
                1 Start watching this issue

                  Dates

                  Created:
                  Updated:
                  Resolved: