mercedes-benz/sechub-plugin-intellij

SecHub import fails, when action is executed, but SecHub view was not visible before

Closed this issue · 4 comments

The intelliJ Plugin does not work with:

Android Studio Arctic Fox | 2020.3.1 Patch 2
Build #AI-203.7717.56.2031.7678000, built on August 26, 2021
Runtime version: 11.0.10+0-b96-7249189 amd64
VM: OpenJDK 64-Bit Server VM by JetBrains s.r.o.
Linux 5.4.0-81-generic
GC: G1 Young Generation, G1 Old Generation
Memory: 1280M
Cores: 4
Registry: external.system.auto.import.disabled=true
Non-Bundled Plugins: com.daimler.sechub.sechub-plugin-intellij
Current Desktop: MATE

The report is loaded into the plugin, the Job UUID, Traffic light and Findings fields are populated correctly. However, no Finding is visible in the list.

android_studio_empty_findings

Update de-jcup, 2021-09-07

The problem exists when the SecHub tool window was not created (never shown before) but the action was triggered. Those tool windows are created by IntelliJ in a lazy way. For more details see explanations/comments below.

Had same issue with IntelliJ 2020.1 - launched from IntelliJ2020.1 with runIDE task

Reason is that the sechub tool windows is not be found (but it is visible on screen!)

java.lang.Throwable: Did not found sechub tool window!
	at com.intellij.openapi.diagnostic.Logger.error(Logger.java:146)
	at com.daimler.sechub.SecHubReportViewUpdater.internalUpdateReportView(SecHubReportViewUpdater.java:25)
	at com.daimler.sechub.SecHubReportViewUpdater.lambda$updateReportViewInSWTThread$0(SecHubReportViewUpdater.java:19)
	at com.intellij.openapi.progress.impl.CoreProgressManager.executeProcessUnderProgress(CoreProgressManager.java:577)
	at com.intellij.openapi.progress.impl.ProgressManagerImpl.executeProcessUnderProgress(ProgressManagerImpl.java:61)
	at com.daimler.sechub.SecHubReportViewUpdater.updateReportViewInSWTThread(SecHubReportViewUpdater.java:19)
	at com.daimler.sechub.SecHubReportImporter.importAndDisplayReport(SecHubReportImporter.java:55)
	at com.daimler.sechub.SecHubReportImporter.importAndDisplayReport(SecHubReportImporter.java:28)
	at com.daimler.sechub.action.SechubImportAction.actionPerformed(SechubImportAction.java:43)
	at com.intellij.openapi.actionSystem.ex.ActionUtil.performActionDumbAware(ActionUtil.java:280)
	at com.intellij.openapi.actionSystem.impl.ActionMenuItem$ActionTransmitter.lambda$actionPerformed$0(ActionMenuItem.java:296)
	at com.intellij.openapi.wm.impl.FocusManagerImpl.runOnOwnContext(FocusManagerImpl.java:281)
	at com.intellij.openapi.wm.impl.IdeFocusManagerImpl.runOnOwnContext(IdeFocusManagerImpl.java:77)
	at com.intellij.openapi.actionSystem.impl.ActionMenuItem$ActionTransmitter.actionPerformed(ActionMenuItem.java:285)
	at java.desktop/javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:1967)
	at com.intellij.openapi.actionSystem.impl.ActionMenuItem.lambda$fireActionPerformed$0(ActionMenuItem.java:112)
	at com.intellij.openapi.application.TransactionGuardImpl.performUserActivity(TransactionGuardImpl.java:94)
	at com.intellij.openapi.actionSystem.impl.ActionMenuItem.fireActionPerformed(ActionMenuItem.java:112)
	at com.intellij.ui.plaf.beg.BegMenuItemUI.doClick(BegMenuItemUI.java:517)
	at com.intellij.ui.plaf.beg.BegMenuItemUI.access$300(BegMenuItemUI.java:36)
	at com.intellij.ui.plaf.beg.BegMenuItemUI$MyMouseInputHandler.mouseReleased(BegMenuItemUI.java:539)
	at java.desktop/java.awt.Component.processMouseEvent(Component.java:6651)
	at java.desktop/javax.swing.JComponent.processMouseEvent(JComponent.java:3345)
	at java.desktop/java.awt.Component.processEvent(Component.java:6416)
	at java.desktop/java.awt.Container.processEvent(Container.java:2263)
	at java.desktop/java.awt.Component.dispatchEventImpl(Component.java:5026)
	at java.desktop/java.awt.Container.dispatchEventImpl(Container.java:2321)
	at java.desktop/java.awt.Component.dispatchEvent(Component.java:4858)
	at java.desktop/java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4918)
	at java.desktop/java.awt.LightweightDispatcher.processMouseEvent(Container.java:4547)
	at java.desktop/java.awt.LightweightDispatcher.dispatchEvent(Container.java:4488)
	at java.desktop/java.awt.Container.dispatchEventImpl(Container.java:2307)
	at java.desktop/java.awt.Window.dispatchEventImpl(Window.java:2773)
	at java.desktop/java.awt.Component.dispatchEvent(Component.java:4858)
	at java.desktop/java.awt.EventQueue.dispatchEventImpl(EventQueue.java:778)
	at java.desktop/java.awt.EventQueue$4.run(EventQueue.java:727)
	at java.desktop/java.awt.EventQueue$4.run(EventQueue.java:721)
	at java.base/java.security.AccessController.doPrivileged(Native Method)
	at java.base/java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:85)
	at java.base/java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:95)
	at java.desktop/java.awt.EventQueue$5.run(EventQueue.java:751)
	at java.desktop/java.awt.EventQueue$5.run(EventQueue.java:749)
	at java.base/java.security.AccessController.doPrivileged(Native Method)
	at java.base/java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:85)
	at java.desktop/java.awt.EventQueue.dispatchEvent(EventQueue.java:748)
	at com.intellij.ide.IdeEventQueue.defaultDispatchEvent(IdeEventQueue.java:974)
	at com.intellij.ide.IdeEventQueue.dispatchMouseEvent(IdeEventQueue.java:912)
	at com.intellij.ide.IdeEventQueue._dispatchEvent(IdeEventQueue.java:844)
	at com.intellij.ide.IdeEventQueue.lambda$null$8(IdeEventQueue.java:449)
	at com.intellij.openapi.progress.impl.CoreProgressManager.computePrioritized(CoreProgressManager.java:739)
	at com.intellij.ide.IdeEventQueue.lambda$dispatchEvent$9(IdeEventQueue.java:448)
	at com.intellij.openapi.application.impl.ApplicationImpl.runIntendedWriteActionOnCurrentThread(ApplicationImpl.java:831)
	at com.intellij.ide.IdeEventQueue.dispatchEvent(IdeEventQueue.java:502)
	at java.desktop/java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:203)
	at java.desktop/java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:124)
	at java.desktop/java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:113)
	at java.desktop/java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:109)
	at java.desktop/java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:101)
	at java.desktop/java.awt.EventDispatchThread.run(EventDispatchThread.java:90)

A strange situation

Hmm... very strange:

https://github.com/Daimler/sechub-plugin-intellij/blob/86283c553e81f9268c2be0965c056c342a9656d5/src/main/java-intellij/com/daimler/sechub/SecHubReportViewUpdater.java#L22-L30

does fetch the sechub tool window and complains it is null.

But the tool window factory does register the created tool window inside the AWT thread before it's content is added:
https://github.com/Daimler/sechub-plugin-intellij/blob/86283c553e81f9268c2be0965c056c342a9656d5/src/main/java-intellij/com/daimler/sechub/window/SecHubToolWindowFactory.java#L11-L22

The registration is super simple by a static field:
https://github.com/Daimler/sechub-plugin-intellij/blob/86283c553e81f9268c2be0965c056c342a9656d5/src/main/java-intellij/com/daimler/sechub/window/SecHubToolWindow.java#L129-L135

So why can this be null?

I started in debug mode and added a breakpoint - the tool factory was called, the instance registered... and ... no longer null!
Then I started again normal - and it is now working!

This very strange and sound a little bit like a cache mechanism, so the tool factory is not always called.

I found the problem!

After reading https://developerlife.com/2021/03/13/ij-idea-plugin-advanced/
I found following:

Note that if a user does not interact with the button, then a tool window doesn’t get created.

I tried to run the IDE plugin again in runIDE and ... thats the point! The factory only creates the view when it is visible!

Solution is to always show up the tool window programmatically when report view is updated .