Skip to content

Fix NPEs from Jython server - #302

Merged
gselzer merged 6 commits into
mainfrom
scijava-lsp-jython/fix-npe
Dec 3, 2026
Merged

gselzer merged 6 commits into
mainfrom
scijava-lsp-jython/fix-npe

Conversation

@gselzer

@gselzer gselzer commented Dec 2, 2026

Copy link
Copy Markdown
Member

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

Should surface the NPEs
@gselzer
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
gselzer force-pushed the scijava-lsp-jython/fix-npe branch from 893bde7 to edbb106 Compare December 2, 2026 21:15
gselzer and others added 3 commits December 2, 2026 16:41
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>
@gselzer gselzer changed the title WIP: Fix NPEs from Jython server Fix NPEs from Jython server Dec 3, 2026
@gselzer
gselzer requested a balanced review from Copilot December 3, 2026 16:26

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 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 ContentModified errors.
  • 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>
@gselzer
gselzer merged commit 0e9e85a into main Dec 3, 2026
2 checks passed
@gselzer
gselzer deleted the scijava-lsp-jython/fix-npe branch December 3, 2026 17:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants