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

Compiler allows illegal options passed via "-properties"

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

Description

Currently compiler validates and rejects illegal command line options, but it does not validates (or not properly validates) options set via compiler `-properties` option file or elsewhere if executed via API.

See https://github.com/eclipse-jdt/eclipse.jdt.ui/pull/2140 as a "typical" example in JDT own code that uses Java 1.3 compliance to make the test pass (it shouldn't because we shouldn't compile to Java 1.3 level anymore).

Another example is the use of the preview flag and (illegal) target option. The code below uses FFM API that was finalized only in Java 22, but compiler allows to compile it with target 21, even if the spec says it shouldn't (and it was fixed recently for command line via https://github.com/eclipse-jdt/eclipse.jdt.core/issues/3614).

```
public class UseFFM {
public static void main(String[] args) {
System.out.println(java.lang.foreign.MemorySegment.NULL); // preview before 22
}
}
```

That code compiles fine (bug!) with latest ecj with following illegal option combinations and JDK 21 used in the project:

```
eclipse.preferences.version=1
org.eclipse.jdt.core.compiler.codegen.targetPlatform=21
org.eclipse.jdt.core.compiler.compliance=21
org.eclipse.jdt.core.compiler.problem.enablePreviewFeatures=enabled
org.eclipse.jdt.core.compiler.source=24
org.eclipse.jdt.core.compiler.release=21
org.eclipse.jdt.core.compiler.target=21
```

```
eclipse.preferences.version=1
org.eclipse.jdt.core.compiler.codegen.targetPlatform=21
org.eclipse.jdt.core.compiler.compliance=21
org.eclipse.jdt.core.compiler.problem.enablePreviewFeatures=enabled
org.eclipse.jdt.core.compiler.source=24
org.eclipse.jdt.core.compiler.target=21
```

```
eclipse.preferences.version=1
org.eclipse.jdt.core.compiler.codegen.targetPlatform=21
org.eclipse.jdt.core.compiler.compliance=21
org.eclipse.jdt.core.compiler.problem.enablePreviewFeatures=enabled
org.eclipse.jdt.core.compiler.source=24
org.eclipse.jdt.core.compiler.release=21
```

We should see that we prevent illegal options combination passed via preferences file ASAP at the beginning of the compilation, **before** we start to compile something that shouldn't be compilable at all or run into unexpected errors down in compiler code because the preconditions are unexpected / illegal.

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.