[jdk18] RFR: 8278930: javac tries to compile a file twice via PackageElement.getEnclosedElements

Jonathan Gibbons jjg at openjdk.java.net
Fri Jan 7 00:04:30 UTC 2022


On Thu, 6 Jan 2022 13:48:40 GMT, Jan Lahoda <jlahoda at openjdk.org> wrote:

> When using the Elements API, it may happen that an inner class is being completed before its enclosing class. The code is generally prepared for that, and will complete the enclosing class before filling in the content of the inner class.
> 
> An issue happens if the enclosing class is completed from source. Then, since [JDK-8224922](https://bugs.openjdk.java.net/browse/JDK-8224922), the innerclass' `ClassSymbol.classfile` will be set to the source file as well, and then javac will try to fill the innerclass from the source code again, leading to duplicate class error. (Before JDK-8224922, the innerclass was, as far as I can tell, completed from the classfile, which didn't lead to this specific problem, but is unlikely to be completely correct either.)
> 
> The proposal in this fix is to detect the situation where the nested class was already filled after the enclosing class has been completed, and skip further processing.

The change to the code looks plausible, but I'm not expert enough to approve it.

Check copyright years on modified files.

test/langtools/tools/javac/processing/model/element/TestListPackageFromAPI.java line 2:

> 1: /*
> 2:  * Copyright (c) 2017, Oracle and/or its affiliates. All rights reserved.

Copyright year?

test/langtools/tools/javac/processing/model/element/TestListPackageFromAPI.java line 70:

> 68:         Files.newOutputStream(classes.resolve("Test.class")).close();
> 69: 
> 70:         Thread.sleep(2000);

Mild ugh

-------------

PR: https://git.openjdk.java.net/jdk18/pull/85


More information about the compiler-dev mailing list