eclipse-jdt / eclipse-jdt/eclipse.jdt.core
JDT confused by Java version mismatch in compiler settings
- Dominant language
- Java
- Stars
- 237
- Forks
- 195
- Avg merge
- 1d 10h
- Merged PRs (30d)
- 49
Description
I've stumbled over it while looking on https://github.com/eclipse-platform/eclipse.platform.swt/pull/571 where SWT JDK version was bumped to 17 in .settings/org.eclipse.jdt.core.prefs, but manifest.mf and .classpath were still at 11.
JDT notices the problem **during build** and reports confusing and not a very user friendly error to the Problems view **on every build**: `The project was not built due to "release 17 is not found in the system". Fix the problem, then try refreshing this project and building it since it may be inconsistent`.
See attached project [11vs17.zip](https://github.com/eclipse-jdt/eclipse.jdt.core/files/10922070/11vs17.zip)

Error reported to log is:
```
eclipse.buildId=4.28.0.I20230307-1800
java.version=17.0.4-internal
java.vendor=N/A
BootLoader constants: OS=linux, ARCH=x86_64, WS=gtk, NL=en_US
Command-line arguments: -data file:/data/4x_platform_workspace/ -os linux -ws gtk -arch x86_64
org.eclipse.jdt.core
Error
Wed Mar 08 16:08:27 CET 2023
JavaBuilder handling CoreException while building: 11vs17
org.eclipse.core.runtime.CoreException: release 17 is not found in the system
at org.eclipse.jdt.internal.core.builder.ClasspathJrtWithReleaseOption.initialize(ClasspathJrtWithReleaseOption.java:124)
at org.eclipse.jdt.internal.core.builder.ClasspathJrtWithReleaseOption.(ClasspathJrtWithReleaseOption.java:82)
at org.eclipse.jdt.internal.core.builder.ClasspathLocation.forJrtSystem(ClasspathLocation.java:169)
at org.eclipse.jdt.internal.core.builder.NameEnvironment.computeClasspathLocations(NameEnvironment.java:333)
at org.eclipse.jdt.internal.core.builder.NameEnvironment.(NameEnvironment.java:63)
at org.eclipse.jdt.internal.core.builder.JavaBuilder.initializeBuilder(JavaBuilder.java:644)
at org.eclipse.jdt.internal.core.builder.JavaBuilder.build(JavaBuilder.java:182)
at org.eclipse.core.internal.events.BuildManager$2.run(BuildManager.java:1020)
at org.eclipse.core.runtime.SafeRunner.run(SafeRunner.java:45)
at org.eclipse.core.internal.events.BuildManager.basicBuild(BuildManager.java:247)
at org.eclipse.core.internal.events.BuildManager.basicBuild(BuildManager.java:303)
at org.eclipse.core.internal.events.BuildManager$1.run(BuildManager.java:392)
at org.eclipse.core.runtime.SafeRunner.run(SafeRunner.java:45)
at org.eclipse.core.internal.events.BuildManager.basicBuild(BuildManager.java:395)
at org.eclipse.core.internal.events.BuildManager.basicBuildLoop(BuildManager.java:506)
at org.eclipse.core.internal.events.BuildManager.basicBuildLoop(BuildManager.java:454)
at org.eclipse.core.internal.events.BuildManager.build(BuildManager.java:536)
at org.eclipse.core.internal.events.AutoBuildJob.doBuild(AutoBuildJob.java:196)
at org.eclipse.core.internal.events.AutoBuildJob.run(AutoBuildJob.java:289)
at org.eclipse.core.internal.jobs.Worker.run(Worker.java:63)
Caused by: java.lang.IllegalArgumentException: release 17 is not found in the system
at org.eclipse.jdt.internal.core.builder.ClasspathJrtWithReleaseOption.initialize(ClasspathJrtWithReleaseOption.java:123)
... 19 more
```
It would make sense to detect & report this error in some more elegant way, not sure what would be the right solution here.
- we could forcibly reset compiler settings to 11 (the version specified in .classpath) on build
- improve error message and try to explain the problem in a human way
- any other alternative?
Contributor guide
Assessment
This issue has not been assessed yet.