palantir / palantir/palantir-java-format

Update IntelliJ integration

Open
#992 2 comments 2 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Java
Stars
907
Forks
101
Avg merge
1d 3h
Merged PRs (30d)
19

Description

What happened?

I'm seeing some exceptions in IntelliJ attempting to format:

Exceptions occurred on invoking the intention 'Add Javadoc' on a copy of the file.

com.intellij.openapi.diagnostic.RuntimeExceptionWithAttachments: Write access is allowed inside write-action only (see Application.runWriteAction()); see https://jb.gg/ij-platform-threading for details
Current thread: Thread[ApplicationImpl pooled thread 599,4,main] 2003325589 (EventQueue.isDispatchThread()=false)
SystemEventQueueThread: Thread[AWT-EventQueue-0,6,main] 1819580665
	at com.intellij.util.concurrency.ThreadingAssertions.createThreadAccessException(ThreadingAssertions.java:149)
	at com.intellij.util.concurrency.ThreadingAssertions.throwThreadAccessException(ThreadingAssertions.java:143)
	at com.intellij.util.concurrency.ThreadingAssertions.assertWriteAccess(ThreadingAssertions.java:138)
	at com.intellij.openapi.application.impl.ApplicationImpl.assertWriteAccessAllowed(ApplicationImpl.java:1262)
	at com.palantir.javaformat.intellij.PalantirCodeStyleManager.formatInternal(PalantirCodeStyleManager.java:169)
	at com.palantir.javaformat.intellij.PalantirCodeStyleManager.reformatText(PalantirCodeStyleManager.java:110)
	at jdk.internal.reflect.GeneratedMethodAccessor1121.invoke(Unknown Source)
	at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.base/java.lang.reflect.Method.invoke(Method.java:568)
	at krasa.formatter.plugin.ProxyCodeStyleManagerDelegator.PLEASE_REPORT_BUGS_TO_JETBRAINS_IF_IT_FAILS_HERE____ORIGINAL_INTELLIJ_FORMATTER_WAS_USED(ProxyCodeStyleManagerDelegator.java:60)
	at krasa.formatter.plugin.ProxyCodeStyleManagerDelegator.invoke(ProxyCodeStyleManagerDelegator.java:28)
	at net.sf.cglib.empty.Object$$EnhancerByCGLIB$$a6c18dd5.reformatText(<generated>)
	at com.intellij.codeInsight.editorActions.FixDocCommentAction.lambda$reformatCommentKeepingEmptyTags$3(FixDocCommentAction.java:242)
	at com.intellij.psi.codeStyle.CodeStyleSettingsManager.runWithLocalSettings(CodeStyleSettingsManager.java:113)
	at com.intellij.application.options.CodeStyle.runWithLocalSettings(CodeStyle.java:366)
	at com.intellij.codeInsight.editorActions.FixDocCommentAction.reformatCommentKeepingEmptyTags(FixDocCommentAction.java:232)
	at com.intellij.codeInsight.editorActions.FixDocCommentAction.generateComment(FixDocCommentAction.java:218)
	at com.intellij.codeInsight.editorActions.FixDocCommentAction.lambda$generateOrFixComment$0(FixDocCommentAction.java:110)
	at com.intellij.codeInsight.editorActions.FixDocCommentAction.generateOrFixComment(FixDocCommentAction.java:122)
	at com.intellij.codeInsight.intention.impl.AddJavadocIntention.invoke(AddJavadocIntention.java:21)
	at com.intellij.codeInsight.intention.BaseElementAtCaretIntentionAction.invoke(BaseElementAtCaretIntentionAction.java:58)
	at com.intellij.codeInsight.intention.IntentionAction.generatePreview(IntentionAction.java:113)
	at com.intellij.codeInsight.intention.impl.config.IntentionActionWrapper.generatePreview(IntentionActionWrapper.java:90)
	at com.intellij.codeInsight.intention.impl.IntentionActionWithTextCaching$MyIntentionAction.generatePreview(IntentionActionWithTextCaching.java:254)
	at com.intellij.codeInsight.intention.impl.preview.IntentionPreviewComputable$invokePreview$1$1$1.invoke(IntentionPreviewComputable.kt:122)
	at com.intellij.codeInsight.intention.impl.preview.IntentionPreviewComputable$invokePreview$1$1$1.invoke(IntentionPreviewComputable.kt:121)
	at com.intellij.model.SideEffectGuard$Companion.computeWithAllowedSideEffectsBlocking(SideEffectGuard.kt:42)
	at com.intellij.model.SideEffectGuard$Companion.computeWithoutSideEffects(SideEffectGuard.kt:27)
	at com.intellij.codeInsight.intention.impl.preview.IntentionPreviewComputable.invokePreview$lambda$2$lambda$1(IntentionPreviewComputable.kt:121)
	at com.intellij.psi.impl.source.PostprocessReformattingAspectImpl.lambda$postponeFormattingInside$2(PostprocessReformattingAspectImpl.java:139)
	at com.intellij.psi.impl.source.PostprocessReformattingAspectImpl.postponeFormattingInside(PostprocessReformattingAspectImpl.java:148)
	at com.intellij.psi.impl.source.PostprocessReformattingAspectImpl.postponeFormattingInside(PostprocessReformattingAspectImpl.java:138)
	at com.intellij.codeInsight.intention.impl.preview.IntentionPreviewComputable.invokePreview$lambda$2(IntentionPreviewComputable.kt:120)
	at com.intellij.codeInsight.intention.preview.IntentionPreviewUtils.previewSession(IntentionPreviewUtils.java:123)
	at com.intellij.codeInsight.intention.impl.preview.IntentionPreviewComputable.invokePreview(IntentionPreviewComputable.kt:119)
	at com.intellij.codeInsight.intention.impl.preview.IntentionPreviewComputable.generatePreview(IntentionPreviewComputable.kt:88)
	at com.intellij.codeInsight.intention.impl.preview.IntentionPreviewComputable.tryCreateDiffContent(IntentionPreviewComputable.kt:66)
	at com.intellij.codeInsight.intention.impl.preview.IntentionPreviewComputable.call(IntentionPreviewComputable.kt:44)
	at com.intellij.codeInsight.intention.impl.preview.IntentionPreviewComputable.call(IntentionPreviewComputable.kt:38)
	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)
	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:840)

What did you want to happen?

No exceptions in IntelliJ

Suggestion

Sync with google-java-format IntelliJ plugin, mainly https://github.com/google/google-java-format/commit/84b2c9a2ba382ee7a968518b46afb0d6000ada8d that migrated from CodeStyleManager to AsyncDocumentFormattingService plugin API.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with PalantirCodeStyleManager.formatInternal and reformatText, where the reported IntelliJ write-access exception occurs. Compare the google-java-format IntelliJ plugin's AsyncDocumentFormattingService migration, especially commit 84b2c9a2ba382ee7a968518b46afb0d6000ada8d. Done means the IntelliJ Add Javadoc intention preview formats without exceptions.

Written by the indexing model from the issue text.

Assessment

Tech stack
java
Domain
tooling
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.