question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

"Was unable to read source file" warning when extending interface in different module and using sibling concrete generated class

See original GitHub issue

Hi, 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:closed
  • Created 2 years ago
  • Reactions:1
  • Comments:8 (4 by maintainers)

github_iconTop GitHub Comments

2reactions
Magotchicommented, Oct 22, 2021

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:

compileJava {
    options.sourcepath = files(sourceSets.findByName("main").allJava.srcDirs)
}

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

1reaction
elucashcommented, Dec 8, 2021

thank you for some more info, I hope to address it soon, either by removing it or suppressing when it wouldn’t apply

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to extend an interface declared in an external library d.ts?
I'm trying to migrate a <reference ... /> and namespace based huge TS application to use modules.
Read more >
Janino by janino-compiler - GitHub Pages
Janino is a super-small, super-fast Java compiler. Janino can not only compile a set of source files to a set of class files...
Read more >
The Compiler Frontend: Parsing and Type Checking
Each source file represents a compilation unit that is built separately. The compiler generates intermediate files with different filename extensions to use ......
Read more >
Navigation | Android Developers
Navigation Safe Args will no longer cause deprecation warnings in generated classes when using custom argument types that are saved in a ...
Read more >
Python import: Advanced Techniques and Tips
In this tutorial, you'll learn how to: Use modules, packages, and namespace packages; Handle resources and data files inside your packages; Import modules...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found