eclipse-jdt / eclipse-jdt/eclipse.jdt.core
Batch compiler can’t resolve JAXB packages if --release 8 with Java 11+ is used
- Dominant language
- Java
- Stars
- 237
- Forks
- 195
- Avg merge
- 1d 12h
- Merged PRs (30d)
- 47
Description
I have a simple java file `JAXB.java` with following content:
```java
import javax.xml.bind.annotation.XmlRootElement;
@XmlRootElement
public class JAXB {
public String name;
}
```
If I compile it on Java 11 with `--release 8` option, I receive error that `javax.xml.bind` cannot be resoved:
```
$ $JDK11/bin/java -jar ecj-3.31.0.jar JAXB.java --release 8
----------
1. ERROR in /my/path/JAXB.java (at line 1)
import javax.xml.bind.annotation.XmlRootElement;
^^^^^^^^^^^^^^
The import javax.xml.bind cannot be resolved
----------
2. ERROR in /my/path/JAXB.java (at line 3)
@XmlRootElement
^^^^^^^^^^^^^^
XmlRootElement cannot be resolved to a type
----------
2 problems (2 errors)
```
If I compile it without `--release` option but with `-bootclasspath`, it is compiled without errors:
```
$ $JDK11/bin/java -jar ecj-3.31.0.jar JAXB.java -source 1.8 -target 1.8 -bootclasspath $JDK8/jre/lib/rt.jar
```
If I use `-bootclasspath` together with `--release 8`, the bootclasspath is ignored.
The javac compiler compiles this class successfully also with `--release 8` option:
```
$ $JDK11/bin/javac JAXB.java --release 8
```
As I can see batch compiler tries to find modules declaring package `javax.xml.bind` while resolving the import, but can’t find such modules. See [ClasspathJep247.java#L72](https://github.com/eclipse-jdt/eclipse.jdt.core/blob/R4_25/org.eclipse.jdt.core/batch/org/eclipse/jdt/internal/compiler/batch/ClasspathJep247.java#L72) and [ClasspathLocation.java#L184](https://github.com/eclipse-jdt/eclipse.jdt.core/blob/R4_25/org.eclipse.jdt.core/batch/org/eclipse/jdt/internal/compiler/batch/ClasspathLocation.java#L184).
Contributor guide
Assessment
This issue has not been assessed yet.