"Was unable to read source file" warning when extending interface in different module and using sibling concrete generated class
See original GitHub issueHi, I ran into some odd compiler warning with immutables (2.8.8). The title is… the best way I could manage to put it…
To start off, this warning is produced when running mvn compile
from a clean workspace:
[WARNING] Was unable to read source file for moe.tristan.ibv.common.immutables.SomeInterface[com.sun.tools.javac.code.Symbol$ClassSymbol.class]: java.io.FileNotFoundException: moe/tristan/ibv/common/immutables/SomeInterface.java
Doesn’t happen on JDK 11, happens on JDK 16. I made what I believe to be the most minimal reproduction case here: https://github.com/Tristan971/immutables-odd-warning-repro
Here’s a short explainer. Say you have 2 modules, with the following classes in each:
Module A:
public interface SomeInterface {}
Module B (depends on A):
@Immutables
public interface ClassA extends SomeInterface {
ImmutableClassB getB();
}
@Immutables
public interface ClassB {}
Then this warning will be triggered during compilation of module B.
Just in case, this also happens if you remove ClassB
altogether and set the property type in ClassA
to ImmutableClassA
. I just went this route to clarify that it’s not due to some handling of the cycle in the type.
From here on out, I’m really not sure exactly how to investigate further… Hopefully the test repo helps
Full output: (reproduced on maven 3.8.1 on ubuntu, and with adoptopenjdk 16 in a CI environment)
$ mvn --show-version compile
Apache Maven 3.6.3 (Red Hat 3.6.3-8)
Maven home: /usr/share/maven
Java version: 16.0.2, vendor: Red Hat, Inc., runtime: /usr/lib/jvm/java-16-openjdk-16.0.2.0.7-1.rolling.fc34.x86_64
Default locale: en_US, platform encoding: UTF-8
OS name: "linux", version: "4.19.128-microsoft-standard", arch: "amd64", family: "unix"
[INFO] Scanning for projects...
[INFO] ------------------------------------------------------------------------
[INFO] Reactor Build Order:
[INFO]
[INFO] ibv [pom]
[INFO] common [jar]
[INFO] dependency [jar]
[INFO]
[INFO] --------------------------< moe.tristan:ibv >---------------------------
[INFO] Building ibv 0.0.1-SNAPSHOT [1/3]
[INFO] --------------------------------[ pom ]---------------------------------
[INFO]
[INFO] -------------------------< moe.tristan:common >-------------------------
[INFO] Building common 0.0.1-SNAPSHOT [2/3]
[INFO] --------------------------------[ jar ]---------------------------------
[INFO]
[INFO] --- maven-resources-plugin:2.6:resources (default-resources) @ common ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] skip non existing resourceDirectory /home/tristan/perso/immutables-beanvalidation/common/src/main/resources
[INFO]
[INFO] --- maven-compiler-plugin:3.8.1:compile (default-compile) @ common ---
[INFO] Changes detected - recompiling the module!
[INFO] Compiling 1 source file to /home/tristan/perso/immutables-beanvalidation/common/target/classes
[INFO]
[INFO] -----------------------< moe.tristan:dependency >-----------------------
[INFO] Building dependency 0.0.1-SNAPSHOT [3/3]
[INFO] --------------------------------[ jar ]---------------------------------
[INFO]
[INFO] --- maven-resources-plugin:2.6:resources (default-resources) @ dependency ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] skip non existing resourceDirectory /home/tristan/perso/immutables-beanvalidation/dependency/src/main/resources
[INFO]
[INFO] --- maven-compiler-plugin:3.8.1:compile (default-compile) @ dependency ---
[INFO] Changes detected - recompiling the module!
[INFO] Compiling 2 source files to /home/tristan/perso/immutables-beanvalidation/dependency/target/classes
[INFO] -------------------------------------------------------------
[WARNING] COMPILATION WARNING :
[INFO] -------------------------------------------------------------
[WARNING] Was unable to read source file for moe.tristan.ibv.common.immutables.SomeInterface[com.sun.tools.javac.code.Symbol$ClassSymbol.class]: java.io.FileNotFoundException: moe/tristan/ibv/common/immutables/SomeInterface.java
[INFO] 1 warning
[INFO] -------------------------------------------------------------
[INFO] -------------------------------------------------------------
[ERROR] COMPILATION ERROR :
[INFO] -------------------------------------------------------------
[ERROR] warnings found and -Werror specified
[INFO] 1 error
[INFO] -------------------------------------------------------------
[INFO] ------------------------------------------------------------------------
[INFO] Reactor Summary for ibv 0.0.1-SNAPSHOT:
[INFO]
[INFO] ibv ................................................ SUCCESS [ 0.002 s]
[INFO] common ............................................. SUCCESS [ 0.560 s]
[INFO] dependency ......................................... FAILURE [ 0.315 s]
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 0.928 s
[INFO] Finished at: 2021-08-03T03:14:18+01:00
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.8.1:compile (default-compile) on project dependency: Compilation failure
[ERROR] warnings found and -Werror specified
[ERROR]
[ERROR] -> [Help 1]
[ERROR]
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR]
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoFailureException
[ERROR]
[ERROR] After correcting the problems, you can resume the build with the command
[ERROR] mvn <args> -rf :dependency
Issue Analytics
- State:
- Created 2 years ago
- Reactions:1
- Comments:8 (4 by maintainers)
This may not apply to the OP, as you’re already using Maven. However, in a large project with a lot of references to Immutable value types in signatures, I was able to fix it for myself. I noticed that in Java 17, it failed for me in Gradle (with about 10 of these warnings, ultimately leading to other errors), but Maven had no problem building the same project. In comparing the debug outputs of both Maven (“mvn compile”) and Gradle (“gradle compileJava”), I isolated Maven’s inclusion of a real “-sourcepath” javac argument as the important difference (as Gradle defaults it to NULL internally). I therefore added the following to my build.gradle, and all is now working well for me:
I still have the following lingering warning, and I certainly reference Serializable a fair amount in signatures, but I diff’d the Java 11 and Java 17 generated sources, and they’re identical, even with it, so I imagine it’s not a big problem:
warning: Was unable to read source file for java.io.Serializable[com.sun.tools.javac.code.Symbol$ClassSymbol.class]: java.io.FileNotFoundException: java/io/Serializable.java
thank you for some more info, I hope to address it soon, either by removing it or suppressing when it wouldn’t apply