Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ECJ batch compiler does not load multi-release module declaration when -target is used #2774

Open
Marcono1234 opened this issue Jul 29, 2024 · 2 comments
Labels
compiler Eclipse Java Compiler (ecj) related issues

Comments

@Marcono1234
Copy link

Marcono1234 commented Jul 29, 2024

Version

ecj-3.38.0.jar from Maven Central

Description

When using the ECJ batch compiler and using -target respectively one of the shorthand variants such as -9 it does not load the module descriptor of a multi-release JAR (which contains the module descriptor for example as META-INF/versions/9/module-info.class).

It only loads the module descriptor when --release instead of -target is used. And due to https://bugs.eclipse.org/bugs/show_bug.cgi?id=577790 / #2778 the version for --release must match exactly, but that is tracked in that issue.

This differs from javac which seems to load the module descriptor when for example -target 9 is used.

(This might affect not only the module descriptor but any class under the versions directory, but not sure if that matters since the JAR specification says those classes must have the same API as the classes in the top-level directory.)

Reproduction steps

  1. Download the attached multi-release-test.zip and unzip it
  2. Download ECJ, for example from https://search.maven.org/artifact/org.eclipse.jdt/ecj
  3. Run ECJ with -target 10 (or alternatively -10)
    java -jar ./ecj.jar -source 10 -target 10 --module-path ./multi-release.jar ./module-info.java
    
    ❌ Bug: It cannot find the referenced module
  4. Run ECJ with --release 10
    java -jar ./ecj.jar --release 10 --module-path ./multi-release.jar ./module-info.java
    
    ℹ️ As expected: Compilation succeeds

Now compare with javac behavior:

  1. Run with -target 10
    javac -source 9 -target 10 --module-path ./multi-release.jar ./module-info.java
    
    ℹ️ As expected: Compilation succeeds
  2. Run with javac -target 9
    javac -source 9 -target 10 --module-path ./multi-release.jar ./module-info.java
    
    ℹ️ As expected: Compilation fails because it cannot find the referenced module (because it is under META-INF/versions/10)
    This proves that the -target option seems to determine which versions directories are checked in the JAR

(Tested with JDK 17)

@iloveeclipse
Copy link
Member

Would you please provide all the data in one project / zip file so that one could have an easy to use reproducer without extra tedious manual steps?

@iloveeclipse iloveeclipse added the compiler Eclipse Java Compiler (ecj) related issues label Jul 29, 2024
@Marcono1234
Copy link
Author

Sorry, have added a single ZIP file now and updated the steps above.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
compiler Eclipse Java Compiler (ecj) related issues
Projects
None yet
Development

No branches or pull requests

2 participants