Repository navigation
Fix NPEs from Jython server - #302
Merged
Merged
Conversation
Should surface the NPEs
gselzer
marked this pull request as ready for review
December 2, 2026 17:36
The stubs of the Java packages a script imports are written in the background, as the script is opened or changed; requests were sent to the Python server at once, so on a first run (e.g. on CI, with no stubs written yet) it could answer before knowing them (e.g. "(...) -> Unknown" as the signature of Math.max). Now completion, signature help and hover wait for those stubs first (at most STUB_TIMEOUT, ten seconds). JavaStubs.ensure's future now completes only once each package's stub is written: a package counted as done once its writing began, so a script asking for one being written was told it was done. Each package is a task of its own on the writer thread, whose future is the package's. Also drop MAX_PACKAGES: DEPTH already bounds how far stubs are written. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
gselzer
force-pushed
the
scijava-lsp-jython/fix-npe
branch
from
December 2, 2026 21:15
893bde7 to
edbb106
Compare
Stubs written in the background (e.g. those of the packages an import refers to) tell ty its files changed; a request it is answering then fails with ContentModified. As we cause the change ourselves, ask again (up to 5 times, 100 ms apart) rather than failing the client's request. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Contributor
There was a problem hiding this comment.
🟡 Changes recommended
If a document changes while the Jython language server waits for stubs or retries, it sends the original request position against the updated text. Deleting lines can leave that position out of bounds, and completion can combine results from different document revisions.
1 open issue
What changed in this PR
This PR improves Jython language-server error handling so backend failures propagate instead of being masked as null results.
Changes:
- Waits for imported Java stubs before completion, hover, and signature-help requests.
- Adds bounded retries for
ContentModifiederrors. - Tracks per-package stub futures, including work already underway.
| File | Description |
|---|---|
| scijava-lsp-jython/src/main/java/org/scijava/lsp/jython/JythonLanguageServer.java | Adds stub waits and retries; removes exception masking. |
| scijava-lsp-jython/src/main/java/org/scijava/lsp/jython/JavaStubs.java | Tracks stub-writing futures and schedules referenced packages. |
Review effort: Balanced
Requests now wait for stubs (and retries) before asking ty, which reads the script's text only then: a change meanwhile would pair the request's position with the newer text. So fail with ContentModified instead, before asking or asking again; retries are then only for invalidations from elsewhere (e.g. stubs written meanwhile). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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.

This PR aims to fix exceptions arising from the Jython language server. Previously, the language server was masking these exceptions, giving out
NPEs