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

-annotationpath does not work with JSR199 EclipseCompiler

Open
#944 7 comments 0 reactions 0 assignees View on GitHub
bug null
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

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.