Can't build plugin with TreeClassChooser

Answered

Hi.

I use TreeClassChooserFactory for configure my plugin in settings dialog.

'runIde' task works fine, without errors. But 'buildPlugin' task failed.

Starting searchable options index builder
2020-09-08 19:36:30,903 [ 1546] WARN - ConfigurableExtensionPointUtil - ignore deprecated groupId: language for id: preferences.language.Kotlin.scripting
Searchable options index builder failed
java.lang.IllegalArgumentException: Argument for @NotNull parameter 'component' of com/intellij/openapi/application/ModalityState.stateForComponent must not be null
at com.intellij.openapi.application.ModalityState.$$$reportNull$$$0(ModalityState.java)
at com.intellij.openapi.application.ModalityState.stateForComponent(ModalityState.java)
at com.intellij.ide.util.AbstractTreeClassChooserDialog.getModalityState(AbstractTreeClassChooserDialog.java:331)
at com.intellij.ide.util.AbstractTreeClassChooserDialog.createCenterPanel(AbstractTreeClassChooserDialog.java:239)
at com.intellij.openapi.ui.DialogWrapper.init(DialogWrapper.java:1338)
at com.intellij.ide.util.AbstractTreeClassChooserDialog.<init>(AbstractTreeClassChooserDialog.java:103)
at com.intellij.ide.util.AbstractTreeClassChooserDialog.<init>(AbstractTreeClassChooserDialog.java:81)
at com.intellij.ide.util.AbstractTreeClassChooserDialog.<init>(AbstractTreeClassChooserDialog.java:72)
at com.intellij.ide.util.AbstractTreeClassChooserDialog.<init>(AbstractTreeClassChooserDialog.java:68)
at com.intellij.ide.util.TreeJavaClassChooserDialog.<init>(TreeJavaClassChooserDialog.java:24)
at com.intellij.ide.util.TreeClassChooserFactoryImpl.createProjectScopeChooser(TreeClassChooserFactoryImpl.java:48)
at com.any.idea.plugin.settings.PluginSettingsComponent.<init>(PluginSettingsComponent.java:26)
at com.any.idea.plugin.settings.PluginSettingsConfigurable.createComponent(PluginSettingsConfigurable.java:27)
at com.intellij.openapi.options.ex.ConfigurableWrapper.createComponent(ConfigurableWrapper.java:172)
at com.intellij.ide.ui.search.SearchUtil.processConfigurables(SearchUtil.java:80)
at com.intellij.ide.ui.search.SearchUtil.processProjectConfigurables(SearchUtil.java:50)
at com.intellij.ide.ui.search.TraverseUIStarter.startup(TraverseUIStarter.java:97)
at com.intellij.ide.ui.search.TraverseUIStarter.main(TraverseUIStarter.java:80)
at com.intellij.idea.ApplicationLoader$startApp$8$1$1.run(ApplicationLoader.kt:237)
at com.intellij.openapi.application.TransactionGuardImpl.performUserActivity(TransactionGuardImpl.java:94)
at com.intellij.idea.ApplicationLoader$startApp$8$1.run(ApplicationLoader.kt:236)
at com.intellij.openapi.application.TransactionGuardImpl$2.run(TransactionGuardImpl.java:201)
at com.intellij.openapi.application.impl.ApplicationImpl.runIntendedWriteActionOnCurrentThread(ApplicationImpl.java:802)
at com.intellij.openapi.application.impl.ApplicationImpl.lambda$invokeLater$4(ApplicationImpl.java:322)
at com.intellij.openapi.application.impl.FlushQueue.doRun(FlushQueue.java:84)
at com.intellij.openapi.application.impl.FlushQueue.runNextEvent(FlushQueue.java:132)
at com.intellij.openapi.application.impl.FlushQueue.flushNow(FlushQueue.java:47)
at com.intellij.openapi.application.impl.FlushQueue$FlushNow.run(FlushQueue.java:188)
at java.desktop/java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:313)
at java.desktop/java.awt.EventQueue.dispatchEventImpl(EventQueue.java:776)
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.desktop/java.awt.EventQueue.dispatchEvent(EventQueue.java:746)
at com.intellij.ide.IdeEventQueue.defaultDispatchEvent(IdeEventQueue.java:967)
at com.intellij.ide.IdeEventQueue._dispatchEvent(IdeEventQueue.java:839)
at com.intellij.ide.IdeEventQueue.lambda$dispatchEvent$8(IdeEventQueue.java:450)
at com.intellij.openapi.progress.impl.CoreProgressManager.computePrioritized(CoreProgressManager.java:744)
at com.intellij.ide.IdeEventQueue.lambda$dispatchEvent$9(IdeEventQueue.java:449)
at com.intellij.openapi.application.impl.ApplicationImpl.runIntendedWriteActionOnCurrentThread(ApplicationImpl.java:802)
at com.intellij.ide.IdeEventQueue.dispatchEvent(IdeEventQueue.java:497)
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)

My code:

treeClassChooser = TreeClassChooserFactory.getInstance(project).createProjectScopeChooser(message("any.ui.settings.chooseClassTitle"));

ComponentWithBrowseButton<JBTextField> classComponent = new ComponentWithBrowseButton<>(baseClassTextField, e -> {
treeClassChooser.showDialog();
PsiClass psiClass = treeClassChooser.getSelected();
if (psiClass != null) {
baseClassTextField.setText(psiClass.getQualifiedName());
}
});

What's wrong and how can I fix it?

 

4 comments
Comment actions Permalink

Sion,

It's hard to say, what's going on, especially your code is running at some point. Can you please share a minimal reproducible project that will let me check your issue locally?

0
Comment actions Permalink

Jakub,

I'm uploaded example project on GitHub https://github.com/AlexanderDobrenky/idea-any-plugin. A buildPlugin task still failed with message

Searchable options index builder failed
java.lang.IllegalArgumentException: Argument for @NotNull parameter 'component' of com/intellij/openapi/application/ModalityState.stateForComponent must not be null
at com.intellij.openapi.application.ModalityState.$$$reportNull$$$0(ModalityState.java)
at com.intellij.openapi.application.ModalityState.stateForComponent(ModalityState.java)
at com.intellij.ide.util.AbstractTreeClassChooserDialog.getModalityState(AbstractTreeClassChooserDialog.java:331)
at com.intellij.ide.util.AbstractTreeClassChooserDialog.createCenterPanel(AbstractTreeClassChooserDialog.java:239)
at com.intellij.openapi.ui.DialogWrapper.init(DialogWrapper.java:1336)
at com.intellij.ide.util.AbstractTreeClassChooserDialog.<init>(AbstractTreeClassChooserDialog.java:103)
at com.intellij.ide.util.AbstractTreeClassChooserDialog.<init>(AbstractTreeClassChooserDialog.java:81)
at com.intellij.ide.util.AbstractTreeClassChooserDialog.<init>(AbstractTreeClassChooserDialog.java:72)
at com.intellij.ide.util.AbstractTreeClassChooserDialog.<init>(AbstractTreeClassChooserDialog.java:68)
at com.intellij.ide.util.TreeJavaClassChooserDialog.<init>(TreeJavaClassChooserDialog.java:24)
at com.intellij.ide.util.TreeClassChooserFactoryImpl.createProjectScopeChooser(TreeClassChooserFactoryImpl.java:48)
at com.any.PluginSettingsComponent.<init>(PluginSettingsComponent.java:21)
at com.any.PluginSettingsConfigurable.createComponent(PluginSettingsConfigurable.java:26)
at com.intellij.openapi.options.ex.ConfigurableWrapper.createComponent(ConfigurableWrapper.java:172)
at com.intellij.ide.ui.search.SearchUtil.processConfigurables(SearchUtil.java:80)
at com.intellij.ide.ui.search.SearchUtil.processProjectConfigurables(SearchUtil.java:50)
at com.intellij.ide.ui.search.TraverseUIStarter.startup(TraverseUIStarter.java:97)
at com.intellij.ide.ui.search.TraverseUIStarter.main(TraverseUIStarter.java:80)
at com.intellij.idea.ApplicationLoader$startApp$8$1$1.run(ApplicationLoader.kt:237)
at com.intellij.openapi.application.TransactionGuardImpl.performUserActivity(TransactionGuardImpl.java:94)
at com.intellij.idea.ApplicationLoader$startApp$8$1.run(ApplicationLoader.kt:236)
at com.intellij.openapi.application.TransactionGuardImpl$2.run(TransactionGuardImpl.java:201)
at com.intellij.openapi.application.impl.ApplicationImpl.runIntendedWriteActionOnCurrentThread(ApplicationImpl.java:802)
at com.intellij.openapi.application.impl.ApplicationImpl.lambda$invokeLater$4(ApplicationImpl.java:322)
at com.intellij.openapi.application.impl.FlushQueue.doRun(FlushQueue.java:84)
at com.intellij.openapi.application.impl.FlushQueue.runNextEvent(FlushQueue.java:132)
at com.intellij.openapi.application.impl.FlushQueue.flushNow(FlushQueue.java:47)
at com.intellij.openapi.application.impl.FlushQueue$FlushNow.run(FlushQueue.java:188)
at java.desktop/java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:313)
at java.desktop/java.awt.EventQueue.dispatchEventImpl(EventQueue.java:776)
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.desktop/java.awt.EventQueue.dispatchEvent(EventQueue.java:746)
at com.intellij.ide.IdeEventQueue.defaultDispatchEvent(IdeEventQueue.java:971)
at com.intellij.ide.IdeEventQueue._dispatchEvent(IdeEventQueue.java:841)
at com.intellij.ide.IdeEventQueue.lambda$dispatchEvent$8(IdeEventQueue.java:452)
at com.intellij.openapi.progress.impl.CoreProgressManager.computePrioritized(CoreProgressManager.java:744)
at com.intellij.ide.IdeEventQueue.lambda$dispatchEvent$9(IdeEventQueue.java:451)
at com.intellij.openapi.application.impl.ApplicationImpl.runIntendedWriteActionOnCurrentThread(ApplicationImpl.java:802)
at com.intellij.ide.IdeEventQueue.dispatchEvent(IdeEventQueue.java:499)
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)

The line of code specified in the stacktrace https://github.com/AlexanderDobrenky/idea-any-plugin/blob/master/src/main/java/com/any/PluginSettingsComponent.java#L21

0
Comment actions Permalink

Your build fails on the :buildSearchableOptions task, which initializes the PluginSettingsConfigurable class. Since it happens in the build process (headless mode), ModalityState that represents the active modal dialogs state stack may not work correctly.

To fix your issue, postpone the invoking of the createProjectScopeChooser method to the UI thread - i.e. in the ActionListener:

public class PluginSettingsComponent {
private final TreeClassChooserFactory treeClassChooserFactory;

// ...

public PluginSettingsComponent(Project project) {
treeClassChooserFactory = TreeClassChooserFactory.getInstance(project);

ComponentWithBrowseButton<JBTextField> classComponent = new ComponentWithBrowseButton<>(baseClassTextField, e -> {
TreeClassChooser chooser = treeClassChooserFactory.createProjectScopeChooser("Choose class ...");
chooser.showDialog();

// ...
});

// ...
}

// ...
}
0
Comment actions Permalink

Jakub, thank you.

0

Please sign in to leave a comment.