Java: make JDT-LS's null-analysis mode configurable - #1861
Open
Burgito wants to merge 1 commit into
Open
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Serena hardcodes
java.compile.nullAnalysis.modetoautomatic, so JDT-LS enables the compileroptions required for annotation-based null analysis on any project with nullability annotations on
the classpath, and there is no way to ask for anything else short of patching the source. This PR
exposes that one value as
ls_specific_settings.java.null_analysis_mode, keepingautomaticas thedefault.
Main reason to want it:
automaticis not inert. It changes the project's compiler options so that null analysis can run;on a project whose build owns those settings, having the language server adjust them is not always
wanted.
What changes
One new setting, accepting exactly the values JDT-LS accepts. Verified against the runtime Serena
downloads by default:
—
vscode-java-1.54.0-923/extension/package.json, i.e.DEFAULT_VSCODE_JAVA_VERSION.Why
automaticremains the defaultVscode-java's own default is
interactive, and Serena deliberately differs. That is worthstating, because it is the reason this is a new knob rather than a switch to upstream's default.
In
interactivemode JDT-LS enables nothing by itself: it asks the client overlanguage/actionableNotification, and the answer comes back as the client commandjava.compile.nullAnalysis.setMode. Serena registers nosuch command and discards that notification outright:
—
src/solidlsp/language_servers/eclipse_jdtls.py:1384So for Serena,
interactivemeans the prompt is dropped and null analysis never turns on;automaticis the only value that yields nullability diagnostics. Keeping it as the default means this PR changes no behaviour for anyone who does not setthe key.
interactiveis exposed for completeness rather than as a recommendation, and the docs sayas much.
Invalid values warn and fall back rather than raise
An unrecognized value logs a warning naming the valid values and falls back to
automatic. It seemed the most coherent regarding the existing settings likeon_stale_lock(Scala),project_roots,project_root_scan_depth,use_system_java_home...on_stale_lock(src/solidlsp/language_servers/scala_language_server.py:272-277) is the exactstructural analogue — an enum-valued
ls_specific_settingsstring parsed through anEnum— and itwarns, so
null_analysis_modefollows it, including theNullAnalysisModeenum shape. A typo in adiagnostics knob also seems a poor reason to keep the Java language server from starting at all.
Scope
Two things left out deliberately — happy to add either if you would prefer:
nonnull/nullableannotation lists stay hardcoded. They are JDT-LS settings too andcould be exposed the same way, but I have no need for it and it widens the configuration surface
for no demonstrated case.
_compute_workspace_hash. Thathash tracks import-affecting inputs (Maven/Gradle/JDK); null analysis is a compiler preference
re-sent on every start. One consequence worth knowing: on a project JDT-LS has already imported,
switching to
automaticmay only take full effect once it reprocesses the project.Verification
test/solidlsp/java/test_jdtls_path_resolution.py, next to the existingruntimestests and using the same harness (no JDTLS started, no Java required): the default whenunset; each of the three values reaching
initializationOptions.settings.java.compile.nullAnalysis.mode; five invalid inputs (unknownvalue, wrong case, empty string,
null, non-string) falling back with a warning; and theannotation lists unchanged under every mode.
pytest test/solidlsp/java/→ 94 passed, including the@pytest.mark.javaintegration teststhat do start JDT-LS.
poe lintandpoe type-check→ clean.The tests were written before the implementation and observed failing first.
They assert the mode Serena sends, not that JDT-LS then emits different diagnostics — that would
need an annotated fixture and a real import. It is the same boundary the
runtimesandlombok_show_generatedtests stop at.Risk
Low. The default is the value that was previously hardcoded, so the generated
initializeparams areidentical for anyone who does not set the key;
test_defaults_to_automatic_when_unsetpins that.Existing Java CI exercises exactly that unset-default population.
The diff also documents the setting in the
EclipseJDTLSdocstring and in the Java table ofdocs/02-usage/050_configuration.md, which enumerates these settings and would otherwise beincomplete.
Related
runtimes) and JDTLS: Problems with detecting some of the generated Lombok methods #1432 (lombok_show_generated) are the precedents for this shape of change:a single JDT-LS setting exposed through
ls_specific_settings.java, defaulting to existingbehaviour.
CONTRIBUTING.mdthis is an isolated addition that does not changeSerena's behaviour and extends it along existing lines. Glad to open one if you would rather
discuss it there.
Disclosure
Prepared with the assistance of Claude Code (Claude Opus 5). The values and defaults quoted above
were read out of the bundled vscode-java runtime and the vscode-java sources rather than recalled,
and every file and line reference was checked against the tree. I reviewed and edited the text and
will answer follow-ups personally.
I also tested it locally with the local installation as a tool, as suggested in contribution guidelines.
English is not my first language, so please excuse me if I'm making any mistakes.
Checklist
CONTRIBUTING.mdregarding the scope of PRs.CHANGELOG.md, which concisely describes the change.