Skip to content

LinkageError: loader constraint violation #459

Open

Description

@InSyncWithFoo

I'm getting the following error when targeting PyCharm Professional 2024.2, with a dependency on both the native client and LSP4IJ:

java.lang.LinkageError: loader constraint violation: loader com.intellij.ide.plugins.cl.PluginClassLoader @182fa87a wants to load class org.eclipse.lsp4j.Diagnostic. A different class with the same name was previously loaded by com.intellij.util.lang.PathClassLoader @65ab7765. (org.eclipse.lsp4j.Diagnostic is in unnamed module of loader com.intellij.util.lang.PathClassLoader @65ab7765)
	at insyncwithfoo.plugin.lsp.DiagnosticsSupportKt.getCodeAsString(DiagnosticsSupport.kt:10)
	at insyncwithfoo.plugin.lsp.DiagnosticsSupportKt.access$getCodeAsString(DiagnosticsSupport.kt:1)
	at insyncwithfoo.plugin.lsp.DiagnosticsSupport.getTooltip(DiagnosticsSupport.kt:19)
	at com.intellij.platform.lsp.api.customization.LspDiagnosticsSupport.createAnnotation(LspDiagnosticsSupport.kt:28)
	at com.intellij.platform.lsp.impl.highlighting.LspAnnotator.q(LspAnnotator.kt:71)
	at com.intellij.platform.lsp.impl.highlighting.LspAnnotator.annotate(LspAnnotator.kt:51)
	at com.intellij.codeInsight.daemon.impl.AnnotationHolderImpl.runAnnotatorWithContext(AnnotationHolderImpl.java:216)
	at com.intellij.codeInsight.daemon.impl.AnnotatorRunner.lambda$runAnnotator$3(AnnotatorRunner.java:139)
	at com.intellij.codeInsight.daemon.impl.AnnotationSessionImpl.computeWithSession(AnnotationSessionImpl.java:87)
	at com.intellij.codeInsight.daemon.impl.AnnotatorRunner.runAnnotator(AnnotatorRunner.java:129)
	at com.intellij.codeInsight.daemon.impl.AnnotatorRunner.lambda$runAnnotatorsAsync$0(AnnotatorRunner.java:66)
	at com.intellij.openapi.application.impl.AnyThreadWriteThreadingSupport.tryRunReadAction(AnyThreadWriteThreadingSupport.kt:279)
	at com.intellij.openapi.application.impl.ApplicationImpl.tryRunReadAction(ApplicationImpl.java:965)
	at com.intellij.codeInsight.daemon.impl.AnnotatorRunner.lambda$runAnnotatorsAsync$1(AnnotatorRunner.java:66)
	at com.intellij.concurrency.JobLauncherImpl$2MyProcessQueueTask.lambda$call$0(JobLauncherImpl.java:494)
	at com.intellij.openapi.progress.impl.CoreProgressManager.lambda$executeProcessUnderProgress$13(CoreProgressManager.java:660)
	at com.intellij.openapi.progress.impl.CoreProgressManager.computeUnderProgress(CoreProgressManager.java:684)
	at com.intellij.openapi.progress.impl.CoreProgressManager.executeProcessUnderProgress(CoreProgressManager.java:659)
	at com.intellij.openapi.progress.impl.ProgressManagerImpl.executeProcessUnderProgress(ProgressManagerImpl.java:79)
	at com.intellij.concurrency.JobLauncherImpl$2MyProcessQueueTask.call(JobLauncherImpl.java:483)
	at com.intellij.concurrency.JobLauncherImpl$2MyProcessQueueTask.call(JobLauncherImpl.java:471)
	at com.intellij.concurrency.JobLauncherImpl$2.compute(JobLauncherImpl.java:456)
	at java.base/java.util.concurrent.CountedCompleter.exec(CountedCompleter.java:759)
	at java.base/java.util.concurrent.ForkJoinTask.doExec(ForkJoinTask.java:507)
	at java.base/java.util.concurrent.ForkJoinTask.invoke(ForkJoinTask.java:676)
	at com.intellij.concurrency.JobLauncherImpl.procInOrderAsync(JobLauncherImpl.java:554)
	at com.intellij.codeInsight.daemon.impl.AnnotatorRunner.runAnnotatorsAsync(AnnotatorRunner.java:67)
	at com.intellij.codeInsight.daemon.impl.GeneralHighlightingPass.collectHighlights(GeneralHighlightingPass.java:231)
	at com.intellij.codeInsight.daemon.impl.GeneralHighlightingPass.lambda$collectInformationWithProgress$10(GeneralHighlightingPass.java:176)
	at com.intellij.codeInsight.daemon.impl.HighlightVisitorRunner.createHighlightVisitorsFor(HighlightVisitorRunner.java:84)
	at com.intellij.codeInsight.daemon.impl.GeneralHighlightingPass.collectInformationWithProgress(GeneralHighlightingPass.java:109)
	at com.intellij.codeInsight.daemon.impl.ProgressableTextEditorHighlightingPass.doCollectInformation(ProgressableTextEditorHighlightingPass.java:84)
	at com.intellij.codeHighlighting.TextEditorHighlightingPass.collectInformation(TextEditorHighlightingPass.java:57)
	at com.intellij.codeInsight.daemon.impl.PassExecutorService$ScheduledPass.lambda$doRun$2(PassExecutorService.java:418)
	at com.intellij.platform.diagnostic.telemetry.helpers.TraceKt.runWithSpanIgnoreThrows(trace.kt:118)
	at com.intellij.platform.diagnostic.telemetry.helpers.TraceUtil.runWithSpanThrows(TraceUtil.java:36)
	at com.intellij.codeInsight.daemon.impl.PassExecutorService$ScheduledPass.lambda$doRun$3(PassExecutorService.java:413)
	at com.intellij.openapi.application.impl.AnyThreadWriteThreadingSupport.tryRunReadAction(AnyThreadWriteThreadingSupport.kt:291)
	at com.intellij.openapi.application.impl.ApplicationImpl.tryRunReadAction(ApplicationImpl.java:965)
	at com.intellij.codeInsight.daemon.impl.PassExecutorService$ScheduledPass.lambda$doRun$4(PassExecutorService.java:404)
	at com.intellij.openapi.progress.impl.CoreProgressManager.lambda$executeProcessUnderProgress$13(CoreProgressManager.java:660)
	at com.intellij.openapi.progress.impl.CoreProgressManager.registerIndicatorAndRun(CoreProgressManager.java:735)
	at com.intellij.openapi.progress.impl.CoreProgressManager.computeUnderProgress(CoreProgressManager.java:691)
	at com.intellij.openapi.progress.impl.CoreProgressManager.executeProcessUnderProgress(CoreProgressManager.java:659)
	at com.intellij.openapi.progress.impl.ProgressManagerImpl.executeProcessUnderProgress(ProgressManagerImpl.java:79)
	at com.intellij.codeInsight.daemon.impl.PassExecutorService$ScheduledPass.doRun(PassExecutorService.java:403)
	at com.intellij.codeInsight.daemon.impl.PassExecutorService$ScheduledPass.lambda$run$0(PassExecutorService.java:379)
	at com.intellij.openapi.fileTypes.impl.FileTypeManagerImpl.cacheFileTypesInside(FileTypeManagerImpl.java:802)
	at com.intellij.codeInsight.daemon.impl.PassExecutorService$ScheduledPass.lambda$run$1(PassExecutorService.java:379)
	at com.intellij.openapi.application.impl.AnyThreadWriteThreadingSupport.executeByImpatientReader(AnyThreadWriteThreadingSupport.kt:486)
	at com.intellij.openapi.application.impl.ApplicationImpl.executeByImpatientReader(ApplicationImpl.java:179)
	at com.intellij.codeInsight.daemon.impl.PassExecutorService$ScheduledPass.run(PassExecutorService.java:377)
	at com.intellij.concurrency.JobLauncherImpl$VoidForkJoinTask$1.exec(JobLauncherImpl.java:190)
	at java.base/java.util.concurrent.ForkJoinTask.doExec(ForkJoinTask.java:507)
	at java.base/java.util.concurrent.ForkJoinPool$WorkQueue.topLevelExec(ForkJoinPool.java:1491)
	at java.base/java.util.concurrent.ForkJoinPool.scan(ForkJoinPool.java:2073)
	at java.base/java.util.concurrent.ForkJoinPool.runWorker(ForkJoinPool.java:2035)
	at java.base/java.util.concurrent.ForkJoinWorkerThread.run(ForkJoinWorkerThread.java:187)

It might have something to do with this one in the docs, but I'm not sure.

If codebase access is necessary, give me a ping.

Activity

  1. angelozerr commented on Aug 16, 2024

    @angelozerr
    Contributor

    It might have something to do with this one in the docs, but I'm not sure.

    I don't think so. You need to do that when your plugin import a library which have a dependency to LSP4IJ (case of IJ Quarkus).

    If it works before PyCharm 2024.2, my understand of this problem is that:

    • before 2024.2, LSP4IJ and Jetbreains LSP use the same version of LSPJ which expose Diagnostic class code
    • in 2024.2, LSP4IJ and Jetbreains LSP don't use the same version of LSPJ and you have this problem.

    The fix is that LSP4IJ should uses the same version of LS4J than Jetbrains LSP, but it will work with 2024.2, but not with <2024.2.

    Perhaps I'm wrong, but Ifear that there is no solution because your plugin requires Diagnostic class from 2 version of LSP4J.

  2. InSyncWithFoo commented on Aug 16, 2024

    @InSyncWithFoo
    ContributorAuthor

    I checked the About section, and it says LSP4J is at 0.21.1. Let's say I don't care about compatibility with 2024.1 and lower; what can I do so that I no longer get this error?

  3. angelozerr commented on Aug 16, 2024

    @angelozerr
    Contributor

    I checked the About section, and it says LSP4J is at 0.21.1.

    Thats strange LSP4IJ used too 0.21.1?

    Let's say I don't care about compatibility with 2024.1 and lower; what can I do so that I no longer get this error?

    I dont master this problem but I think to avoid having LSP4IJ should have the same version of LSP4J than LSP Jetbrains.

    The thing I dont understand is that it seems good according your comment?

  4. angelozerr commented on Aug 16, 2024

    @angelozerr
    Contributor

    @InSyncWithFoo if you remove LSP4J as dependency in your plugin, is it working better?

  5. InSyncWithFoo commented on Aug 16, 2024

    @InSyncWithFoo
    ContributorAuthor

    That's the thing: I don't depend on LSP4J directly, but LSP4IJ and the native client both depend on it, which is why I assumed there was some conflict between them.

    I also tried adding this to my build.gradle.kts, but nothing changed.

    implementation("org.jetbrains.plugins:com.redhat.devtools.lsp4ij:0.3.0") {
        exclude("org.eclipse.lsp4j")
    }
  6. angelozerr commented on Aug 16, 2024

    @angelozerr
    Contributor

    If there is the linkage problem it means that several plugins like LSP4IJ, LSP Jetbrains provide an LSP4J library which have different version

    We need to check really which version of LSP4J is used in 2024 2

  7. InSyncWithFoo commented on Aug 16, 2024

    @InSyncWithFoo
    ContributorAuthor

    The version numbers are actually inconsistent, but it was the same in 2024.1:

  8. angelozerr commented on Aug 16, 2024

    @angelozerr
    Contributor

    The version numbers are actually inconsistent, but it was the same in 2024.1:

    @InSyncWithFoo I'm little lost. You mean that there are the same version of LSP4J in 2024.1 and it is working?

  9. InSyncWithFoo commented on Aug 16, 2024

    @InSyncWithFoo
    ContributorAuthor

    I mean it was just as inconsistent. Not sure if JetBrains updated their LSP4J version or not.

  10. angelozerr commented on Aug 16, 2024

    @angelozerr
    Contributor

    Not sure if JetBrains updated their LSP4J version or not.

    We need to know the exact version of LSP4J that Jetbrains provide. If you can find that please tell me.

  11. InSyncWithFoo commented on Aug 22, 2024

    @InSyncWithFoo
    ContributorAuthor

    According to this SO answer, the version, or even the JAR file the class is from, doesn't matter.

    I asked about this on Slack and here's the reply from a JetBrains employee:

    Sorry, hard to say what to do 🤷 no one expects such configuration
    [...]
    You could have a plugin-like architecture and build different versions for community and commercial IDEs

    ...I suppose that means it is currently impossible to not get such an error. Ideas for workarounds and corresponding obvious drawbacks include:

    • Try to load all LSP4J classes at the same time the plugin is loaded: This might consume memory unnecessarily.
    • Doing some monkeypatch on our own to prevent loading the classes twice: I have no idea if this is even possible.
    • File an issue on YouTrack and wait for JetBrains to fix it: This should only be the last resort.
  12. angelozerr commented on Aug 22, 2024

    @angelozerr
    Contributor

    According to this SO answer, the version, or even the JAR file the class is from, doesn't matter.

    I asked about this on Slack and here's the reply from a JetBrains employee:

    Sorry, hard to say what to do 🤷 no one expects such configuration
    [...]
    You could have a plugin-like architecture and build different versions for community and commercial IDEs

    ...I suppose that means it is currently impossible to not get such an error. Ideas for workarounds and corresponding obvious drawbacks include:

    • Try to load all LSP4J classes at the same time the plugin is loaded: This might consume memory unnecessarily.
    • Doing some monkeypatch on our own to prevent loading the classes twice: I have no idea if this is even possible.
    • File an issue on YouTrack and wait for JetBrains to fix it: This should only be the last resort.

    It was my fear. But I wonder why you provide the both LSP support in the same plugin.

    For me using LSP4IJ is for providing an IJ plugin for community, no?

    If your plugin use LSP Support of Jetbrains your plugin can be used with IJ community.

  13. InSyncWithFoo commented on Aug 22, 2024

    @InSyncWithFoo
    ContributorAuthor

    But I wonder why you provide the both LSP support in the same plugin.

    A plugin of mine has already been using the native LSP ever since it was created, so I don't want to break user experience. Guess I'll have to document this as a limitation.

  14. InSyncWithFoo commented on Aug 25, 2024

    @InSyncWithFoo
    ContributorAuthor

    I found this documentation page regarding class loaders. Might worth looking into.

  15. added
    bug
    on Aug 27, 2024
  16. 12 remaining items

  17. angelozerr commented on Apr 25, 2025

    @angelozerr
    Contributor

    Which version of ij are you using?

  18. InSyncWithFoo commented on Apr 25, 2025

    @InSyncWithFoo
    ContributorAuthor

    @angelozerr I'm using IntelliJ IDEA Ultimate 2025.1 on Windows.

  19. angelozerr commented on Apr 25, 2025

    @angelozerr
    Contributor

    That's too bad. I have tried to use the same version of LSP4J librarries than @SCWells72 have seen in Ultimate, but it seems it doesn't work.

    It is a a real nightmare.

  20. angelozerr commented on Apr 25, 2025

    @angelozerr
    Contributor

    @InSyncWithFoo could you check which version of LSP4J do you have in Ultimate

    See #988 (comment)

  21. InSyncWithFoo commented on Apr 25, 2025

    @InSyncWithFoo
    ContributorAuthor

    @angelozerr It's still 0.21.1. That is, exactly the same as in that comment.

  22. SCWells72 commented on Apr 25, 2025

    @SCWells72
    Contributor

    That's too bad. I have tried to use the same version of LSP4J librarries than @SCWells72 have seen in Ultimate, but it seems it doesn't work.

    For clarity, here's what I tested during my verification which may not be as extensive as a full usage of LSP4IJ under a commercial JetBrains IDE that bundles LSP4J:

    IntelliJ IDEA Ultimate Edition 2024.1 / 2024.2 / 2024.3 / 2025.1 / WebStorm

    • Confirmed that the Google Gson conflict with the IDE's integrated TypeScript compiler that I'd seen previously was resolved
    • Confirmed that a simple diagnostics-only language server that I've integrated via LSP4IJ works properly

    IntelliJ IDEA Community Edition 2025.1

    • Confirmed that LSP4IJ user-defined TypeScript and CSS language servers work properly

    Since Gson is no longer bundled with LSP4IJ, it makes sense that the Gson-specific conflict I'd seen would be resolved. My guess is that the only language server that I use in commercial IDEs that bundle LSP4J doesn't result in exhaustive enough usage of that library to trigger the conflict, and of course that conflict wouldn't occur in Community Edition IDEs without LSP4J bundled where I was testing language servers with more complete capability sets.

  23. InSyncWithFoo commented on Apr 25, 2025

    @InSyncWithFoo
    ContributorAuthor

    Also to be clear, here's what I did:

    • Install RyeCharm, Pyright, Pyrefly and LSP4IJ.
    • Install uv.
    • Run uv tool install ruff pyright pyrefly.
    • Within IntelliJ IDEA, go to each plugin's setting panel and change the running mode to Native client.
    • Open any Python file.

    The error shows up even when LSP4IJ is not used.

  24. InSyncWithFoo commented on Jul 18, 2025

    @InSyncWithFoo
    ContributorAuthor

    IntelliJ IDEA Community and Ultimate are now one unified product starting 2025.2.

  25. angelozerr commented on Jul 19, 2025

    @angelozerr
    Contributor

    It means that lsp4j lib will be available in any platform. Lsp4ij could consume the lsp4j from jetbrains and avoid haing this issue
    N

    ..

  26. InSyncWithFoo commented on Nov 26, 2025

    @InSyncWithFoo
    ContributorAuthor

    @angelozerr You said you will remove LSP4J as a dependency to fix this problem. Have you actually verified that it does?

  27. angelozerr commented on Nov 26, 2025

    @angelozerr
    Contributor

    @angelozerr You said you will remove LSP4J as a dependency to fix this problem. Have you actually verified that it does?

    No but I am pretty sure that if I remove LSP4J dependency it should work.

  28. InSyncWithFoo commented on Nov 26, 2025

    @InSyncWithFoo
    ContributorAuthor

    @angelozerr Please create a PR. I'll test the build.

  29. angelozerr commented on Nov 27, 2025

    @angelozerr
    Contributor
  30. InSyncWithFoo commented on Nov 30, 2025

    @InSyncWithFoo
    ContributorAuthor

    Replied at the PR.

  31. added this to the 0.30.3 milestone on Nov 30, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bug

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions