Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: use JSONUtils from LSP4IJ #1297

Merged
merged 1 commit into from
Dec 20, 2023
Merged

Conversation

angelozerr
Copy link
Contributor

fix: use JSONUtils from LSP4IJ

This PR requires redhat-developer/lsp4ij#56 to avoid having this LinkageError error problem when code action is resolved:

Internal error: java.lang.LinkageError: loader constraint violation: when resolving method 'com.google.gson.Gson org.eclipse.lsp4j.jsonrpc.json.MessageJsonHandler.getGson()' the class loader com.intellij.ide.plugins.cl.PluginClassLoader @47dad50f of the current class, org/eclipse/lsp4mp/commons/utils/JSONUtility, and the class loader com.intellij.ide.plugins.cl.PluginClassLoader @54c5da1d for the method's defining class, org/eclipse/lsp4j/jsonrpc/json/MessageJsonHandler, have different Class objects for the type com/google/gson/Gson used in the signature (org.eclipse.lsp4mp.commons.utils.JSONUtility is in unnamed module of loader com.intellij.ide.plugins.cl.PluginClassLoader @47dad50f, parent loader 'bootstrap'; org.eclipse.lsp4j.jsonrpc.json.MessageJsonHandler is in unnamed module of loader com.intellij.ide.plugins.cl.PluginClassLoader @54c5da1d, parent loader 'bootstrap')

java.util.concurrent.CompletionException: java.lang.LinkageError: loader constraint violation: when resolving method 'com.google.gson.Gson org.eclipse.lsp4j.jsonrpc.json.MessageJsonHandler.getGson()' the class loader com.intellij.ide.plugins.cl.PluginClassLoader @47dad50f of the current class, org/eclipse/lsp4mp/commons/utils/JSONUtility, and the class loader com.intellij.ide.plugins.cl.PluginClassLoader @54c5da1d for the method's defining class, org/eclipse/lsp4j/jsonrpc/json/MessageJsonHandler, have different Class objects for the type com/google/gson/Gson used in the signature (org.eclipse.lsp4mp.commons.utils.JSONUtility is in unnamed module of loader com.intellij.ide.plugins.cl.PluginClassLoader @47dad50f, parent loader 'bootstrap'; org.eclipse.lsp4j.jsonrpc.json.MessageJsonHandler is in unnamed module of loader com.intellij.ide.plugins.cl.PluginClassLoader @54c5da1d, parent loader 'bootstrap')
	at java.base/java.util.concurrent.CompletableFuture.encodeThrowable(CompletableFuture.java:332)
	at java.base/java.util.concurrent.CompletableFuture.completeThrowable(CompletableFuture.java:347)
	at java.base/java.util.concurrent.CompletableFuture$UniAccept.tryFire(CompletableFuture.java:708)
	at java.base/java.util.concurrent.CompletableFuture.postComplete(CompletableFuture.java:510)
	at java.base/java.util.concurrent.CompletableFuture.completeExceptionally(CompletableFuture.java:2162)
	at com.redhat.devtools.lsp4ij.internal.PromiseToCompletableFuture.lambda$bind$0(PromiseToCompletableFuture.java:98)
	at org.jetbrains.concurrency.AsyncPromise.onError$lambda$4(AsyncPromise.kt:96)
	at org.jetbrains.concurrency.AsyncPromise$whenComplete$1.invoke(AsyncPromise.kt:114)
	at org.jetbrains.concurrency.AsyncPromise$whenComplete$1.invoke(AsyncPromise.kt:112)
	at org.jetbrains.concurrency.AsyncPromise.whenComplete$lambda$6(AsyncPromise.kt:112)
	at java.base/java.util.concurrent.CompletableFuture.uniHandle(CompletableFuture.java:934)
	at java.base/java.util.concurrent.CompletableFuture$UniHandle.tryFire(CompletableFuture.java:911)
	at java.base/java.util.concurrent.CompletableFuture.postComplete(CompletableFuture.java:510)
	at java.base/java.util.concurrent.CompletableFuture.completeExceptionally(CompletableFuture.java:2162)
	at org.jetbrains.concurrency.AsyncPromise.setError(AsyncPromise.kt:192)
	at com.intellij.openapi.application.impl.NonBlockingReadActionImpl$Submission.setError(NonBlockingReadActionImpl.java:338)
	at com.intellij.openapi.application.impl.NonBlockingReadActionImpl$Submission.insideReadAction(NonBlockingReadActionImpl.java:630)
	at com.intellij.openapi.application.impl.NonBlockingReadActionImpl$Submission.lambda$attemptComputation$4(NonBlockingReadActionImpl.java:567)
	at com.intellij.openapi.application.impl.ApplicationImpl.tryRunReadAction(ApplicationImpl.java:1075)
	at com.intellij.openapi.progress.util.ProgressIndicatorUtils.lambda$runInReadActionWithWriteActionPriority$0(ProgressIndicatorUtils.java:73)
	at com.intellij.openapi.progress.util.ProgressIndicatorUtilService.runActionAndCancelBeforeWrite(ProgressIndicatorUtilService.java:73)
	at com.intellij.openapi.progress.util.ProgressIndicatorUtils.runActionAndCancelBeforeWrite(ProgressIndicatorUtils.java:128)
	at com.intellij.openapi.progress.util.ProgressIndicatorUtils.lambda$runWithWriteActionPriority$1(ProgressIndicatorUtils.java:111)
	at com.intellij.openapi.progress.ProgressManager.lambda$runProcess$0(ProgressManager.java:73)
	at com.intellij.openapi.progress.impl.CoreProgressManager.lambda$runProcess$1(CoreProgressManager.java:192)
	at com.intellij.openapi.progress.impl.CoreProgressManager.lambda$executeProcessUnderProgress$12(CoreProgressManager.java:610)
	at com.intellij.openapi.progress.impl.CoreProgressManager.registerIndicatorAndRun(CoreProgressManager.java:685)
	at com.intellij.openapi.progress.impl.CoreProgressManager.computeUnderProgress(CoreProgressManager.java:641)
	at com.intellij.openapi.progress.impl.CoreProgressManager.executeProcessUnderProgress(CoreProgressManager.java:609)
	at com.intellij.openapi.progress.impl.ProgressManagerImpl.executeProcessUnderProgress(ProgressManagerImpl.java:78)
	at com.intellij.openapi.progress.impl.CoreProgressManager.runProcess(CoreProgressManager.java:179)
	at com.intellij.openapi.progress.ProgressManager.runProcess(ProgressManager.java:73)
	at com.intellij.openapi.progress.util.ProgressIndicatorUtils.runWithWriteActionPriority(ProgressIndicatorUtils.java:108)
	at com.intellij.openapi.progress.util.ProgressIndicatorUtils.runInReadActionWithWriteActionPriority(ProgressIndicatorUtils.java:73)
	at com.intellij.openapi.application.impl.NonBlockingReadActionImpl$Submission.attemptComputation(NonBlockingReadActionImpl.java:567)
	at com.intellij.openapi.application.impl.NonBlockingReadActionImpl$Submission.lambda$transferToBgThread$1(NonBlockingReadActionImpl.java:466)
	at com.intellij.openapi.application.impl.NonBlockingReadActionImpl$Submission.lambda$transferToBgThread$2(NonBlockingReadActionImpl.java:481)
	at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1136)
	at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:635)
	at java.base/java.util.concurrent.Executors$PrivilegedThreadFactory$1$1.run(Executors.java:702)
	at java.base/java.util.concurrent.Executors$PrivilegedThreadFactory$1$1.run(Executors.java:699)
	at java.base/java.security.AccessController.doPrivileged(AccessController.java:399)
	at java.base/java.util.concurrent.Executors$PrivilegedThreadFactory$1.run(Executors.java:699)
	at java.base/java.lang.Thread.run(Thread.java:833)
Caused by: java.lang.LinkageError: loader constraint violation: when resolving method 'com.google.gson.Gson org.eclipse.lsp4j.jsonrpc.json.MessageJsonHandler.getGson()' the class loader com.intellij.ide.plugins.cl.PluginClassLoader @47dad50f of the current class, org/eclipse/lsp4mp/commons/utils/JSONUtility, and the class loader com.intellij.ide.plugins.cl.PluginClassLoader @54c5da1d for the method's defining class, org/eclipse/lsp4j/jsonrpc/json/MessageJsonHandler, have different Class objects for the type com/google/gson/Gson used in the signature (org.eclipse.lsp4mp.commons.utils.JSONUtility is in unnamed module of loader com.intellij.ide.plugins.cl.PluginClassLoader @47dad50f, parent loader 'bootstrap'; org.eclipse.lsp4j.jsonrpc.json.MessageJsonHandler is in unnamed module of loader com.intellij.ide.plugins.cl.PluginClassLoader @54c5da1d, parent loader 'bootstrap')
	at org.eclipse.lsp4mp.commons.utils.JSONUtility.<clinit>(JSONUtility.java:33)
	at com.redhat.devtools.intellij.quarkus.lsp.QuarkusLanguageClient.lambda$resolveCodeAction$17(QuarkusLanguageClient.java:253)
	at com.redhat.devtools.lsp4ij.internal.PromiseToCompletableFuture.lambda$nonBlockingReadActionPromise$2(PromiseToCompletableFuture.java:137)
	at com.intellij.openapi.application.impl.NonBlockingReadActionImpl$OTelMonitor.callWrapped(NonBlockingReadActionImpl.java:840)
	at com.intellij.openapi.application.impl.NonBlockingReadActionImpl$OTelMonitor$MonitoredComputation.call(NonBlockingReadActionImpl.java:872)
	at com.intellij.openapi.application.impl.NonBlockingReadActionImpl$Submission.insideReadAction(NonBlockingReadActionImpl.java:604)
	... 27 more

@angelozerr angelozerr self-assigned this Dec 19, 2023
@angelozerr angelozerr added this to the 1.31.0 milestone Dec 19, 2023
@angelozerr angelozerr added the bug Something isn't working label Dec 19, 2023
@angelozerr angelozerr force-pushed the jsonutils branch 3 times, most recently from 43692b6 to 89d7a1e Compare December 19, 2023 16:36
@fbricon
Copy link
Contributor

fbricon commented Dec 19, 2023

I found this other, similar error, when clicking on the value of an undeclared property:

    @ConfigProperty(name = "missing.property")
    String foo;
2023-12-19 19:09:13,715 [  43262]   WARN - c.r.d.i.l.p.i.c.j.c.JavaCodeActionDefinition - Error while calling getCodeActions
java.lang.ClassCastException: class com.google.gson.JsonObject cannot be cast to class com.google.gson.JsonObject (com.google.gson.JsonObject is in unnamed module of loader com.intellij.ide.plugins.cl.PluginClassLoader @26aaab70; com.google.gson.JsonObject is in unnamed module of loader com.intellij.ide.plugins.cl.PluginClassLoader @56e259a8)
	at com.redhat.devtools.intellij.lsp4mp4ij.psi.internal.config.java.NoValueAssignedToPropertyQuickFix.getPropertyName(NoValueAssignedToPropertyQuickFix.java:146)
	at com.redhat.devtools.intellij.lsp4mp4ij.psi.internal.config.java.NoValueAssignedToPropertyQuickFix.getCodeActions(NoValueAssignedToPropertyQuickFix.java:91)
	at com.redhat.devtools.intellij.lsp4mp4ij.psi.internal.core.java.codeaction.JavaCodeActionDefinition.getCodeActions(JavaCodeActionDefinition.java:71)
	at com.redhat.devtools.intellij.lsp4mp4ij.psi.internal.core.java.codeaction.CodeActionHandler.lambda$codeAction$2(CodeActionHandler.java:136)
	at java.base/java.util.ArrayList.forEach(ArrayList.java:1511)
	at com.redhat.devtools.intellij.lsp4mp4ij.psi.internal.core.java.codeaction.CodeActionHandler.codeAction(CodeActionHandler.java:123)
	at com.redhat.devtools.intellij.lsp4mp4ij.psi.core.PropertiesManagerForJava.codeAction(PropertiesManagerForJava.java:626)
	at com.redhat.devtools.intellij.quarkus.lsp.QuarkusLanguageClient.lambda$getJavaCodeAction$16(QuarkusLanguageClient.java:246)

As a result several code actions are missing, like add "insert property in application.properties" or "exclude property from validation"

@angelozerr
Copy link
Contributor Author

I found this other, similar error, when clicking on the value of an undeclared property:

Good catch! I fixed by creating a PropertyNameData class. As JsonObject, JsonElement can come from to several classloader, the main idea is not to use it when you need to get or set Json to the LSP4IJ.

Copy link

sonarcloud bot commented Dec 20, 2023

Quality Gate Passed Quality Gate passed

Kudos, no new issues were introduced!

0 New issues
0 Security Hotspots
No data about Coverage
No data about Duplication

See analysis details on SonarCloud

@fbricon fbricon merged commit 0d3437e into redhat-developer:main Dec 20, 2023
8 checks passed
@fbricon
Copy link
Contributor

fbricon commented Dec 20, 2023

thanks @angelozerr

@fbricon fbricon modified the milestones: 1.31.0, 1.31.1 Jan 8, 2024
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.

2 participants