Reconcile stale auto-enabled preview features for invisible projects - #3833
Reconcile stale auto-enabled preview features for invisible projects#3833wenytang-ms wants to merge 1 commit into
Conversation
a24272f to
bcd2bc2
Compare
How to reproduce & verifyThe stale flag only needs a below-latest compliance with preview still enabled. This can be reproduced deterministically in a plug-in test: @Test
public void reproStalePreviewBreaksBuild() throws Exception {
IProject invisibleProject = copyAndImportFolder("singlefile/lesson1", "src/org/samples/HelloWorld.java");
IJavaProject javaProject = JavaCore.create(invisibleProject);
// State left behind after the bundled compiler advanced past the version
// jdt.ls originally auto-enabled preview at:
String olderThanLatest = JavaCore.getAllVersions().get(JavaCore.getAllVersions().size() - 2);
javaProject.setOption(JavaCore.COMPILER_COMPLIANCE, olderThanLatest);
javaProject.setOption(JavaCore.COMPILER_SOURCE, olderThanLatest);
javaProject.setOption(JavaCore.COMPILER_CODEGEN_TARGET_PLATFORM, olderThanLatest);
javaProject.setOption(JavaCore.COMPILER_PB_ENABLE_PREVIEW_FEATURES, JavaCore.ENABLED);
javaProject.setOption(JavaCore.COMPILER_PB_REPORT_PREVIEW_FEATURES, JavaCore.IGNORE);
invisibleProject.build(IncrementalProjectBuilder.FULL_BUILD, new NullProgressMonitor());
waitForBackgroundJobs();
for (IMarker m : invisibleProject.findMarkers(IJavaModelMarker.JAVA_MODEL_PROBLEM_MARKER, true, IResource.DEPTH_INFINITE)) {
System.out.println(m.getAttribute(IMarker.SEVERITY) + " : " + m.getAttribute(IMarker.MESSAGE));
}
}Before the fix the build fails with an unsuppressible, error-severity problem (note That empty With the fix, calling |
|
@jjohnstn please help review this PR, and the CI seems flaky, so can you rerun this pipeline? |
131cf7c to
e8194ff
Compare
jdt.ls auto-enables preview features (and silences the report) for an invisible project when its Java version equals the latest supported version, then persists that. After a compiler bump the latest version moves forward, leaving preview enabled at a non-latest compliance, which fails the whole build. Reset those options to their defaults on import when they look auto-enabled (enabled + report severity ignore) and the compliance is below the latest supported version.
e8194ff to
b4cba2d
Compare
|
From my testing this seems unrelated to what you did. |
datho7561
left a comment
There was a problem hiding this comment.
Okay, it took me a while to figure out how to test this, but I managed to make a Java 25 invisible project with preview features enabled. When I open this project without this PR, I don't seem to get notified anywhere that the build is failing due to preview features being enabled on an incompatible compiler version (!!!), but the Java > Run and Java Debug CodeLens commands fail stating that the build failed, and the output folder is empty. I think it would be helpful to figure out why a diagnostic or popup doesn't appear when the build fails due to enabling preview features on an older release; I'll make a separate issue for that.
When I open the Java 25 invisible project with preview features enabled with this PR instead, it automatically disables the preview features. The spot where I use https://openjdk.org/jeps/530 in the code is marked as an error as a result. It's kind of clunky to disable preview support, since if the user was using preview features, suddenly the project doesn't build. Maybe it's better to upgrade to the latest supported version and keep preview support on to address this? What do you think?
|
See #3846 |

Fixes #3832
jdt.ls auto-enables preview features (and sets the preview-report severity to
ignore) for an invisible project when its Java version equalslatestSupportedJavaVersion(), and persists that. After a compiler bump the "latest" moves forward, so the project ends up with preview enabled at a non-latest compliance and the build fails withPreview features enabled at an invalid source release level.configureJVMSettingsisn't re-run for an existing invisible project on reload, so it never self-heals — only renaming the folder (a fresh import) works around it.This adds
JVMConfigurator.reconcilePreviewFeatureSettings, called fromInvisibleProjectImporter, which resets the preview options to their defaults only when:enablePreview=enabledand report severityignore),latestSupportedJavaVersion().Managed projects (Maven/Gradle), deliberate user settings (which keep the default
warningseverity) and projects legitimately on the latest JDK are left untouched. This complements #3131/#3137, which only notifies the client but doesn't reconcile the value jdt.ls set itself.Downstream report: redhat-developer/vscode-java#4420.
Tests: added coverage in
InvisibleProjectImporterTestfor reset when below latest, kept when on the latest JDK, and not reset when the user set preview explicitly.