eclipse-jdt / eclipse-jdt/eclipse.jdt.core

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

Open
#2,774 2 comments 0 reactions 0 assignees View on GitHub
compiler
Dominant language
Java
Stars
237
Forks
195
Avg merge
1d 12h
Merged PRs (30d)
47

Description

## 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](https://docs.oracle.com/en/java/javase/21/docs/specs/jar/jar.html#multi-release-jar-files) 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](https://github.com/user-attachments/files/16418820/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)

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.