Skip to content

fix: the IDE restarts to install or update LSP4IJ, instead of loading a second version next to the one it unloads - #2391

Merged
lagergren merged 1 commit into
redhat-developer:mainfrom
lagergren:fix/plugin-requires-restart
Dec 1, 2026
Merged

lagergren merged 1 commit into
redhat-developer:mainfrom
lagergren:fix/plugin-requires-restart

Conversation

@lagergren

Copy link
Copy Markdown
Collaborator

Fixes #2382.

LSP4IJ 0.30.2, installed in a running IntelliJ 2026.3, failed with:

ClassCastException: class com.redhat.devtools.lsp4ij.LanguageServersRegistry cannot be cast to class com.redhat.devtools.lsp4ij.LanguageServersRegistry
(... is in unnamed module of loader PluginClassLoader @657ad3d6; ... is in unnamed module of loader PluginClassLoader @3f537bb3)
	at com.redhat.devtools.lsp4ij.LanguageServersRegistry.getInstance(LanguageServersRegistry.java:64)
	at com.redhat.devtools.lsp4ij.features.semanticTokens.viewProvider.LSPSemanticTokensFileViewProviderFactory.createFileViewProvider(...)

Cause

Two class loaders of LSP4IJ were alive at once. plugin.xml doesn't declare require-restart, so the IDE installs or updates LSP4IJ without a restart: it unloads the version it runs and loads the new one.

When something of the version it unloads survives, it meets the classes of the new one. In the trace, a FileViewProviderFactory is called, and the service container answers with an object whose class comes from the other version's class loader. The surviving part can be an extension that the platform cached, a file view provider, or a reference from a plugin that depends on LSP4IJ.

LSP4IJ has a large number of extensions, services and caches, and plugins that depend on it, as Quarkus and Qute do. It can't promise that nothing outlives an unload.

Fix

<idea-plugin require-restart="true">: the IDE restarts to install or update LSP4IJ, so only one version's classes are ever loaded.

This is a behaviour change for users: installing or updating LSP4IJ now asks for a restart. Angelo, this is your call: the other way would be to find and release everything that outlives an unload, which I can't reproduce.

Behaviour changes

Before After
LSP4IJ was installed and updated without a restart, which could fail with a ClassCastException between two of its class loaders The IDE restarts to install or update LSP4IJ

Tests

PluginRequiresRestartTest finds LSP4IJ's own META-INF/plugin.xml among the plugin descriptors of the class path, by its <id>, and checks that it declares require-restart="true". The bundled plugins have descriptors on the class path too.

… a second version next to the one it unloads

Without require-restart, the IDE installed and updated LSP4IJ in a
running IDE, and what it kept of the version it unloaded, as a
FileViewProviderFactory, met the services of the new version, which
failed with a ClassCastException between two class loaders of LSP4IJ.

Fixes redhat-developer#2382
@lagergren lagergren added this to the 0.30.3 milestone Dec 1, 2026
@lagergren lagergren added the bug Something isn't working label Dec 1, 2026
@lagergren
lagergren requested a review from angelozerr December 1, 2026 10:40
@coderabbitai

coderabbitai Bot commented Dec 1, 2026 •

Copy link
Copy Markdown

No actionable comments were generated in the recent review.

Summary

Summary by CodeRabbit

  • Bug Fixes
    • The IDE now restarts when installing or updating the plugin, helping ensure changes take effect correctly.

The plugin descriptor now requires an IDE restart for installation or updates. A new test locates the LSP4IJ plugin descriptor and checks that its require-restart attribute is set to true.

Changes: Plugin restart requirement

Layer / File(s) Summary
Set and verify the restart requirement
src/main/resources/META-INF/plugin.xml, src/test/java/com/redhat/devtools/lsp4ij/PluginRequiresRestartTest.java
The plugin descriptor sets require-restart to true and documents the class-loader conflict. The test finds the LSP4IJ descriptor and checks the attribute.

Estimated code review effort: 2 (Simple) | ~10 minutes

Change: Bug fix

Merge Risk: Minimal · up to 99c29

Installing or updating the plugin will now ask for an IDE restart, which avoids the reported class-loader conflict. No merge-blocking risk was identified.

Pre-merge checks: Passed 4

Check name Status Explanation
Title check Passed The title states the main change: adding require-restart so the IDE restarts when installing or updating LSP4IJ, which avoids loading a second version beside the unloaded one. The raw summary confirms…
Description check Passed The description explains the ClassCastException from issue #2382, the cause (no require-restart declared, so two class loaders coexist after update), the fix (require-restart="true"), the user-facing …
Linked Issues check Passed [#2382] The issue reports a ClassCastException in LanguageServersRegistry.getInstance() when two LSP4IJ class loaders are alive. The issue gives no reproduction steps and no explicit acceptance criter…
Out of Scope Changes check Passed The PR changes two files. plugin.xml adds the require-restart attribute and a comment that explains the reason. This directly implements the linked issue #2382. PluginRequiresRestartTest.java adds a t…
Full details: Title check

Explanation

The title states the main change: adding require-restart so the IDE restarts when installing or updating LSP4IJ, which avoids loading a second version beside the unloaded one. The raw summary confirms the plugin.xml change that sets require-restart="true" and the test that checks it. The title's stated fix matches the changeset.

Full details: Description check

Explanation

The description explains the ClassCastException from issue #2382, the cause (no require-restart declared, so two class loaders coexist after update), the fix (require-restart="true"), the user-facing behavior change, and the added PluginRequiresRestartTest. It matches the changeset.

Full details: Linked Issues check

Explanation

[#2382] The issue reports a ClassCastException in LanguageServersRegistry.getInstance() when two LSP4IJ class loaders are alive. The issue gives no reproduction steps and no explicit acceptance criteria. The PR changes src/main/resources/META-INF/plugin.xml to set require-restart="true" on the root <idea-plugin> element. The IDE then restarts before it installs or updates LSP4IJ, so only one version's classes load in a session. This targets the failure mode described in the PR and the issue. The PR adds PluginRequiresRestartTest, which checks that LSP4IJ's own plugin descriptor declares require-restart="true". The root cause (a surviving reference from the unloaded version) is not reproduced by the author. The fix is a mitigation based on the author's analysis, not a verified removal of the leak. Within the issue's scope, the coding change is present and tested.

Full details: Out of Scope Changes check

Explanation

The PR changes two files. plugin.xml adds the require-restart attribute and a comment that explains the reason. This directly implements the linked issue #2382. PluginRequiresRestartTest.java adds a test that verifies that attribute. The test supports the same objective. The summary shows no other file changes. No unrelated change is evident from the summary. The PR description states that the restart requirement is a user-visible behavior change, which is part of the chosen fix and not an unrelated change.

Recent review info

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Organization UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 5f74d6bf-0541-4b3e-8261-6c449da22dea
Commits

Reviewing files that changed from the base of the PR and between 89d31ea and 99c29d1.

Files selected for processing: 2

  • src/main/resources/META-INF/plugin.xml
  • src/test/java/com/redhat/devtools/lsp4ij/PluginRequiresRestartTest.java

Included review availability: This review used your included allowance. Your plan provides up to 2 included reviews per hour; 0 remain after this review.

@codecov

codecov Bot commented Dec 1, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 59.82%. Comparing base (89d31ea) to head (99c29d1).

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #2391      +/-   ##
==========================================
+ Coverage   59.80%   59.82%   +0.01%     
==========================================
  Files         859      859              
  Lines       37602    37602              
  Branches     7792     7792              
==========================================
+ Hits        22488    22495       +7     
+ Misses      12031    12024       -7     
  Partials     3083     3083              

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@lagergren

Copy link
Copy Markdown
Collaborator Author

@coderabbitai review

@coderabbitai

coderabbitai Bot commented Dec 1, 2026 •

Copy link
Copy Markdown
Action not completed

Review rate limited.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@lagergren

Copy link
Copy Markdown
Collaborator Author

@coderabbitai review

@coderabbitai

coderabbitai Bot commented Dec 1, 2026 •

Copy link
Copy Markdown
Action performed

Review finished.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@lagergren
lagergren merged commit 0fe234a into redhat-developer:main Dec 1, 2026
11 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

ClassCastException whith LanguageServersRegistry.getInstance(

1 participant