eclipse-jdt / eclipse-jdt/eclipse.jdt.core
-annotationpath does not work with JSR199 EclipseCompiler
- Dominant language
- Java
- Stars
- 237
- Forks
- 195
- Avg merge
- 1d 12h
- Merged PRs (30d)
- 47
Description
ECJ allows to pass the path to external null annotation via the `-annotationpath` argument. This works perfectly when using the "batch" compiler (`org.eclipse.jdt.internal.compiler.batch.Main`). However, it does not work when using the JSR199 compiler (`org.eclipse.jdt.internal.compiler.tool.EclipseCompiler`). The latter is used by the `plexus-compiler-eclipse` Maven plug-in which allows using ECJ in Maven builds. This means you cannot use annotation-based null analysis in Maven right now (javac does not support it and ECJ ignores the external annotation).
A simple reproducer is [test.zip](https://github.com/eclipse-jdt/eclipse.jdt.core/files/11157640/test.zip)
The problem is in `org.eclipse.jdt.internal.compiler.tool.EclipseCompilerImpl.getCompilationUnits()` which overrides the same method from `Main` (the batch compiler). In [line 177](https://github.com/eclipse-jdt/eclipse.jdt.core/blob/457e2221c44b49b6f38fcdfe6d1d59467a04bf75/org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/internal/compiler/tool/EclipseCompilerImpl.java#L177) a `CompilationUnit` is created using a [constructor](https://github.com/eclipse-jdt/eclipse.jdt.core/blob/457e2221c44b49b6f38fcdfe6d1d59467a04bf75/org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/internal/compiler/batch/CompilationUnit.java#L58) that sets the _annotationPathProvider_ to `null` and hence disabling the external annotations.
Contributor guide
Assessment
This issue has not been assessed yet.