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

javac tries to compile a file twice via PackageElement.getEnclosedElements

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Fixed
    • Icon: P3 P3
    • 18
    • 18
    • tools
    • None
    • b31

        I'm using the Language Model API to walk the element tree, using a mixture of system classes (i.e. in the system modules), patched with source files for public API.

        javac gives a "duplicate class" error for a number of classes.

        Debugging the first failure, the class symbol is being completed exactly once in the JavaCompiler source completer (good), but it's still being parsed twice.

        The following output shows stack traces for when the class is completed, and when the file is parsed. Note the two calls from adjacent lines in ClassFinder:

        at jdk.compiler/com.sun.tools.javac.code.ClassFinder.complete(ClassFinder.java:297)

        at jdk.compiler/com.sun.tools.javac.code.ClassFinder.complete(ClassFinder.java:298)

        Here's the full output from this part of the log:
        COMPLETING java.io.ExpiringCache$Entry
        COMPLETING java.io.ExpiringCache
        [loading /var/folders/5z/hmz538nn07v_lj4gmdn8r8sw0000gn/T/sinceChecker1808173566600546027/java.base/java/io/ExpiringCache.java]
        java.lang.Exception: Stack trace
        at java.base/java.lang.Thread.dumpStack(Thread.java:1380)
        at jdk.compiler/com.sun.tools.javac.main.JavaCompiler.readSourceFile(JavaCompiler.java:789)
        at jdk.compiler/com.sun.tools.javac.main.JavaCompiler.readSourceFile(JavaCompiler.java:779)
        at jdk.compiler/com.sun.tools.javac.main.JavaCompiler.lambda$new$0(JavaCompiler.java:341)
        at jdk.compiler/com.sun.tools.javac.code.ClassFinder.fillIn(ClassFinder.java:372)
        at jdk.compiler/com.sun.tools.javac.code.ClassFinder.complete(ClassFinder.java:298)
        at jdk.compiler/com.sun.tools.javac.code.Symbol.complete(Symbol.java:683)
        at jdk.compiler/com.sun.tools.javac.code.Symbol$ClassSymbol.complete(Symbol.java:1411)
        at jdk.compiler/com.sun.tools.javac.code.ClassFinder.completeEnclosing(ClassFinder.java:340)
        at jdk.compiler/com.sun.tools.javac.code.ClassFinder.complete(ClassFinder.java:297)
        at jdk.compiler/com.sun.tools.javac.code.Symbol.complete(Symbol.java:683)
        at jdk.compiler/com.sun.tools.javac.code.Symbol$ClassSymbol.complete(Symbol.java:1411)
        at jdk.compiler/com.sun.tools.javac.code.Symbol.apiComplete(Symbol.java:689)
        at jdk.compiler/com.sun.tools.javac.code.Symbol$TypeSymbol.getEnclosedElements(Symbol.java:860)
        at jdk.compiler/com.sun.tools.javac.code.Symbol$TypeSymbol.getEnclosedElements(Symbol.java:798)
        at Main.checkPackage(Main.java:134)
        at Main.checkModule(Main.java:128)
        at Main.checkModules(Main.java:119)
        at Main.run(Main.java:108)
        at Main.main(Main.java:72)
        at java.base/jdk.internal.reflect.DirectMethodHandleAccessor.invoke(DirectMethodHandleAccessor.java:104)
        at java.base/java.lang.reflect.Method.invoke(Method.java:577)
        at jdk.compiler/com.sun.tools.javac.launcher.Main.execute(Main.java:421)
        at jdk.compiler/com.sun.tools.javac.launcher.Main.run(Main.java:192)
        at jdk.compiler/com.sun.tools.javac.launcher.Main.main(Main.java:132)
        java.lang.Exception: Stack trace
        at java.base/java.lang.Thread.dumpStack(Thread.java:1380)
        at jdk.compiler/com.sun.tools.javac.main.JavaCompiler.parse(JavaCompiler.java:610)
        at jdk.compiler/com.sun.tools.javac.main.JavaCompiler.readSourceFile(JavaCompiler.java:800)
        at jdk.compiler/com.sun.tools.javac.main.JavaCompiler.readSourceFile(JavaCompiler.java:779)
        at jdk.compiler/com.sun.tools.javac.main.JavaCompiler.lambda$new$0(JavaCompiler.java:341)
        at jdk.compiler/com.sun.tools.javac.code.ClassFinder.fillIn(ClassFinder.java:372)
        at jdk.compiler/com.sun.tools.javac.code.ClassFinder.complete(ClassFinder.java:298)
        at jdk.compiler/com.sun.tools.javac.code.Symbol.complete(Symbol.java:683)
        at jdk.compiler/com.sun.tools.javac.code.Symbol$ClassSymbol.complete(Symbol.java:1411)
        at jdk.compiler/com.sun.tools.javac.code.ClassFinder.completeEnclosing(ClassFinder.java:340)
        at jdk.compiler/com.sun.tools.javac.code.ClassFinder.complete(ClassFinder.java:297)
        at jdk.compiler/com.sun.tools.javac.code.Symbol.complete(Symbol.java:683)
        at jdk.compiler/com.sun.tools.javac.code.Symbol$ClassSymbol.complete(Symbol.java:1411)
        at jdk.compiler/com.sun.tools.javac.code.Symbol.apiComplete(Symbol.java:689)
        at jdk.compiler/com.sun.tools.javac.code.Symbol$TypeSymbol.getEnclosedElements(Symbol.java:860)
        at jdk.compiler/com.sun.tools.javac.code.Symbol$TypeSymbol.getEnclosedElements(Symbol.java:798)
        at Main.checkPackage(Main.java:134)
        at Main.checkModule(Main.java:128)
        at Main.checkModules(Main.java:119)
        at Main.run(Main.java:108)
        at Main.main(Main.java:72)
        at java.base/jdk.internal.reflect.DirectMethodHandleAccessor.invoke(DirectMethodHandleAccessor.java:104)
        at java.base/java.lang.reflect.Method.invoke(Method.java:577)
        at jdk.compiler/com.sun.tools.javac.launcher.Main.execute(Main.java:421)
        at jdk.compiler/com.sun.tools.javac.launcher.Main.run(Main.java:192)
        at jdk.compiler/com.sun.tools.javac.launcher.Main.main(Main.java:132)
        [parsing started DirectoryFileObject[/var/folders/5z/hmz538nn07v_lj4gmdn8r8sw0000gn/T/sinceChecker1808173566600546027/java.base:java/io/ExpiringCache.java]]
        [parsing completed 1ms]
        COMPLETING java.io.ExpiringCache
        COMPLETING java.io.ExpiringCache
        [loading /var/folders/5z/hmz538nn07v_lj4gmdn8r8sw0000gn/T/sinceChecker1808173566600546027/java.base/java/io/ExpiringCache.java]
        java.lang.Exception: Stack trace
        at java.base/java.lang.Thread.dumpStack(Thread.java:1380)
        at jdk.compiler/com.sun.tools.javac.main.JavaCompiler.parse(JavaCompiler.java:610)
        at jdk.compiler/com.sun.tools.javac.main.JavaCompiler.readSourceFile(JavaCompiler.java:800)
        at jdk.compiler/com.sun.tools.javac.main.JavaCompiler.readSourceFile(JavaCompiler.java:779)
        at jdk.compiler/com.sun.tools.javac.main.JavaCompiler.lambda$new$0(JavaCompiler.java:341)
        at jdk.compiler/com.sun.tools.javac.code.ClassFinder.fillIn(ClassFinder.java:372)
        at jdk.compiler/com.sun.tools.javac.code.ClassFinder.complete(ClassFinder.java:298)
        at jdk.compiler/com.sun.tools.javac.code.Symbol.complete(Symbol.java:683)
        at jdk.compiler/com.sun.tools.javac.code.Symbol$ClassSymbol.complete(Symbol.java:1411)
        at jdk.compiler/com.sun.tools.javac.code.Symbol.apiComplete(Symbol.java:689)
        at jdk.compiler/com.sun.tools.javac.code.Symbol$TypeSymbol.getEnclosedElements(Symbol.java:860)
        at jdk.compiler/com.sun.tools.javac.code.Symbol$TypeSymbol.getEnclosedElements(Symbol.java:798)
        at Main.checkPackage(Main.java:134)
        at Main.checkModule(Main.java:128)
        at Main.checkModules(Main.java:119)
        at Main.run(Main.java:108)
        at Main.main(Main.java:72)
        at java.base/jdk.internal.reflect.DirectMethodHandleAccessor.invoke(DirectMethodHandleAccessor.java:104)
        at java.base/java.lang.reflect.Method.invoke(Method.java:577)
        at jdk.compiler/com.sun.tools.javac.launcher.Main.execute(Main.java:421)
        at jdk.compiler/com.sun.tools.javac.launcher.Main.run(Main.java:192)
        at jdk.compiler/com.sun.tools.javac.launcher.Main.main(Main.java:132)
        [parsing started DirectoryFileObject[/var/folders/5z/hmz538nn07v_lj4gmdn8r8sw0000gn/T/sinceChecker1808173566600546027/java.base:java/io/ExpiringCache.java]]
        [parsing completed 0ms]
        /var/folders/5z/hmz538nn07v_lj4gmdn8r8sw0000gn/T/sinceChecker1808173566600546027/java.base/java/io/ExpiringCache.java:36: error: duplicate class: java.io.ExpiringCache
        class ExpiringCache {
        ^
        COMPLETING java.io.ExpiringCache$1
        [loading /modules/java.base/java/io/ExpiringCache$1.class]


        Bottom line: it looks like javac is having trouble reading the files in a package when that involves a source file and nested class files. it may be significant that the code first encounters a nested class file, that triggers completeEnclosingClass, and then subsequently tries to complete that enclosing class again.

              jlahoda Jan Lahoda
              jjg Jonathan Gibbons
              Votes:
              0 Vote for this issue
              Watchers:
              3 Start watching this issue

                Created:
                Updated:
                Resolved: