ProjectService (PersistentStateComponent) getting null project in constructor

Answered

PROBLEM FIXED (see next two posts)

Hi,

I'm trying to implement a persistent state component as a project service, but I get an initialization exception when a project is being saved:

2021-08-15 10:46:03,446 [ 35730] ERROR - rationStore.ComponentStoreImpl - Unable to serialize LSPProjectState state 
com.intellij.util.xmlb.XmlSerializationException: Can't serialize instance of class com.github.gtache.lsp.settings.LSPProjectStateImpl
at com.intellij.configurationStore.JdomSerializerImpl.serialize(xmlSerializer.kt:59)
at com.intellij.configurationStore.XmlSerializer.serialize(xmlSerializer.kt:23)
at com.intellij.configurationStore.XmlSerializer.serialize$default(xmlSerializer.kt:22)
at com.intellij.configurationStore.SaveSessionBaseKt.serializeState(SaveSessionBase.kt:46)
at com.intellij.configurationStore.SaveSessionBase.setState(SaveSessionBase.kt:20)
at com.intellij.configurationStore.ComponentStoreImpl.setStateToSaveSessionProducer(ComponentStoreImpl.kt:342)
at com.intellij.configurationScript.providers.MyProjectStore.setStateToSaveSessionProducer(ConfigurationScriptProjectStoreFactory.kt:72)
at com.intellij.configurationStore.ComponentStoreImpl.commitComponent(ComponentStoreImpl.kt:335)
at com.intellij.configurationStore.ComponentStoreImpl.commitComponents$intellij_platform_configurationStore_impl(ComponentStoreImpl.kt:233)
at com.intellij.configurationStore.ComponentStoreWithExtraComponents.commitComponents$intellij_platform_configurationStore_impl(ComponentStoreWithExtraComponents.kt:95)
at com.intellij.configurationStore.ComponentStoreImpl$commitComponentsOnEdt$$inlined$withEdtContext$intellij_platform_configurationStore_impl$1.invokeSuspend(ComponentStoreImpl.kt:721)
at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(ContinuationImpl.kt:33)
at kotlinx.coroutines.DispatchedTask.run(DispatchedTask.kt:106)
at com.intellij.openapi.application.constraints.BaseConstrainedExecution$Companion$scheduleWithinConstraints$1.invoke(BaseConstrainedExecution.kt:68)
at com.intellij.openapi.application.constraints.BaseConstrainedExecution$Companion.scheduleWithinConstraints(BaseConstrainedExecution.kt:71)
at com.intellij.openapi.application.constraints.BaseConstrainedExecution.scheduleWithinConstraints(BaseConstrainedExecution.kt:38)
at com.intellij.openapi.application.impl.BaseExpirableExecutorMixinImpl.access$scheduleWithinConstraints$s1153900543(BaseExpirableExecutorMixinImpl.kt:12)
at com.intellij.openapi.application.impl.BaseExpirableExecutorMixinImpl$scheduleWithinConstraints$$inlined$Runnable$1.run(Runnable.kt:19)
at com.intellij.openapi.application.TransactionGuardImpl.runWithWritingAllowed(TransactionGuardImpl.java:214)
at com.intellij.openapi.application.TransactionGuardImpl.access$200(TransactionGuardImpl.java:21)
at com.intellij.openapi.application.TransactionGuardImpl$2.run(TransactionGuardImpl.java:196)
at com.intellij.openapi.application.impl.ApplicationImpl.runIntendedWriteActionOnCurrentThread(ApplicationImpl.java:794)
at com.intellij.openapi.application.impl.ApplicationImpl.lambda$invokeLater$4(ApplicationImpl.java:350)
at com.intellij.openapi.application.impl.FlushQueue.doRun(FlushQueue.java:84)
at com.intellij.openapi.application.impl.FlushQueue.runNextEvent(FlushQueue.java:133)
at com.intellij.openapi.application.impl.FlushQueue.flushNow(FlushQueue.java:46)
at com.intellij.openapi.application.impl.FlushQueue$FlushNow.run(FlushQueue.java:189)
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:886)
at com.intellij.ide.IdeEventQueue._dispatchEvent(IdeEventQueue.java:755)
at com.intellij.ide.IdeEventQueue.lambda$dispatchEvent$7(IdeEventQueue.java:442)
at com.intellij.openapi.progress.impl.CoreProgressManager.computePrioritized(CoreProgressManager.java:825)
at com.intellij.ide.IdeEventQueue.lambda$dispatchEvent$8(IdeEventQueue.java:441)
at com.intellij.openapi.application.impl.ApplicationImpl.runIntendedWriteActionOnCurrentThread(ApplicationImpl.java:794)
at com.intellij.ide.IdeEventQueue.dispatchEvent(IdeEventQueue.java:487)
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)
Caused by: java.lang.RuntimeException: java.lang.reflect.InvocationTargetException
at com.intellij.util.ExceptionUtil.rethrow(ExceptionUtil.java:132)
at com.intellij.util.ReflectionUtil.createAsDataClass(ReflectionUtil.java:511)
at com.intellij.util.ReflectionUtil.newInstance(ReflectionUtil.java:441)
at com.intellij.util.ReflectionUtil.newInstance(ReflectionUtil.java:416)
at com.intellij.util.xmlb.SkipDefaultValuesSerializationFilters.getDefaultValue(SkipDefaultValuesSerializationFilters.java:53)
at com.intellij.util.xmlb.SkipDefaultValuesSerializationFilters.getDefaultBean(SkipDefaultValuesSerializationFilters.java:46)
at com.intellij.util.xmlb.SkipDefaultsSerializationFilter.equal(SkipDefaultsSerializationFilter.java:32)
at com.intellij.util.xmlb.BeanBinding.serializePropertyInto(BeanBinding.java:108)
at com.intellij.util.xmlb.BeanBinding.serializeInto(BeanBinding.java:93)
at com.intellij.serialization.xml.KotlinAwareBeanBinding.serializeInto(KotlinAwareBeanBinding.kt:39)
at com.intellij.util.xmlb.BeanBinding.serialize(BeanBinding.java:84)
at com.intellij.configurationStore.JdomSerializerImpl.serialize(xmlSerializer.kt:49)
... 46 more
Caused by: java.lang.reflect.InvocationTargetException
at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
at java.base/jdk.internal.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.base/java.lang.reflect.Constructor.newInstance(Constructor.java:490)
at com.intellij.util.ReflectionUtil.createAsDataClass(ReflectionUtil.java:487)
... 56 more
Caused by: java.lang.NullPointerException: Parameter specified as non-null is null: method com.github.gtache.lsp.settings.LSPProjectStateImpl.<init>, parameter project
at com.github.gtache.lsp.settings.LSPProjectStateImpl.<init>(LSPProjectStateImpl.kt)
... 61 more
2021-08-15 10:46:03,448 [ 35732] ERROR - rationStore.ComponentStoreImpl - IntelliJ IDEA 2021.2 Build #IC-212.4746.92
2021-08-15 10:46:03,448 [ 35732] ERROR - rationStore.ComponentStoreImpl - JDK: 11.0.11; VM: OpenJDK 64-Bit Server VM; Vendor: JetBrains s.r.o.
2021-08-15 10:46:03,448 [ 35732] ERROR - rationStore.ComponentStoreImpl - OS: Windows 10
2021-08-15 10:46:03,449 [ 35733] ERROR - rationStore.ComponentStoreImpl - Plugin to blame: LSP Support version: 2.0
2021-08-15 10:46:03,449 [ 35733] ERROR - rationStore.ComponentStoreImpl - Last Action:
2021-08-15 10:46:03,467 [ 35751] INFO - rationStore.ComponentStoreImpl - Saving Project(name=DottyExample, containerState=COMPONENT_CREATED, componentStore=I:\Projects\Scala\DottyExample)RunManager took 13 ms

I got it registered as a service :

<extensions defaultExtensionNs="com.intellij">
...
<projectService id="LSPProjectState"
serviceInterface="com.github.gtache.lsp.settings.LSPProjectState"
serviceImplementation="com.github.gtache.lsp.settings.LSPProjectStateImpl"/>
...
</extensions>

and when I call it from my code it works perfectly fine:

The LSPProjectState interface:

interface LSPProjectState {
var isLoggingServersOutput: Boolean
var isAlwaysSendRequests: Boolean
var extToServ: Map<String, Array<String>>
var forcedAssociations: Map<String, Array<String>>
}

The LSPProjectStateImpl class : 

@State(name = "LSPProjectState")
class LSPProjectStateImpl(private val project: Project) : LSPProjectState, PersistentStateComponent<LSPProjectStateImpl> {

override var isLoggingServersOutput = false
override var isAlwaysSendRequests = false
override var extToServ: Map<String, Array<String>> = emptyMap()
get() = field.mapValues { it.value.copyOf() }.toMap()
set(value) {
field = value.mapValues { it.value.copyOf() }.toMap()
}
override var forcedAssociations: Map<String, Array<String>> = emptyMap()
get() = field.toMap()
set(value) {
field = value.toMap()
}

override fun hashCode(): Int {
return Objects.hash(isLoggingServersOutput, isAlwaysSendRequests, extToServ, forcedAssociations)
}

override fun equals(other: Any?): Boolean {
return (other is LSPProjectStateImpl) && isLoggingServersOutput == other.isLoggingServersOutput && isAlwaysSendRequests == other.isAlwaysSendRequests && extToServ == other.extToServ && forcedAssociations == other.forcedAssociations
}

override fun getState(): LSPProjectStateImpl {
return this
}

override fun loadState(lspState: LSPProjectStateImpl) {
try {
XmlSerializerUtil.copyBean(lspState, this)
logger.info("LSP Project State loaded")
project.service<LSPProjectService>().notifyStateLoaded()
} catch (e: Exception) {
logger.warn("Couldn't load LSP Project State : $e")
ApplicationUtils.invokeLater {
Messages.showErrorDialog(
"Couldn't load LSP settings, you will need to reconfigure them.",
"LSP plugin"
)
}
}
}

companion object {
private val logger = Logger.getInstance(LSPProjectStateImpl::class.java)
}
}

Thanks for your help!

3 comments
Comment actions Permalink

Okay, after refactoring a bit and using a data class as bean (I suppose the "private val project" caused problems), I'm getting a new error: 

2021-08-17 00:07:03,299 [ 11197] ERROR - rationStore.ComponentStoreImpl - Cannot init component state (componentName=LSPProjectState, componentClass=LSPProjectSettingsImpl) [Plugin: com.github.gtache.lsp] 
com.intellij.diagnostic.PluginException: Cannot init component state (componentName=LSPProjectState, componentClass=LSPProjectSettingsImpl) [Plugin: com.github.gtache.lsp]
at com.intellij.configurationStore.ComponentStoreImpl.initComponent(ComponentStoreImpl.kt:145)
at com.intellij.configurationStore.ComponentStoreWithExtraComponents.initComponent(ComponentStoreWithExtraComponents.kt:48)
at com.intellij.serviceContainer.ComponentManagerImpl.initializeComponent$intellij_platform_serviceContainer(ComponentManagerImpl.kt:525)
at com.intellij.serviceContainer.ServiceComponentAdapter.createAndInitialize(ServiceComponentAdapter.kt:52)
at com.intellij.serviceContainer.ServiceComponentAdapter.doCreateInstance(ServiceComponentAdapter.kt:36)
at com.intellij.serviceContainer.BaseComponentAdapter.getInstanceUncached(BaseComponentAdapter.kt:113)
at com.intellij.serviceContainer.BaseComponentAdapter.getInstance(BaseComponentAdapter.kt:67)
at com.intellij.serviceContainer.BaseComponentAdapter.getInstance$default(BaseComponentAdapter.kt:60)
at com.intellij.serviceContainer.ComponentManagerImpl.doGetService(ComponentManagerImpl.kt:590)
at com.intellij.serviceContainer.ComponentManagerImpl.getService(ComponentManagerImpl.kt:573)
at com.intellij.openapi.client.ClientAwareComponentManager.getFromSelfOrCurrentSession(ClientAwareComponentManager.kt:37)
at com.intellij.openapi.client.ClientAwareComponentManager.getService(ClientAwareComponentManager.kt:22)
at com.github.gtache.lsp.settings.gui.MiscGUI.<init>(MiscGUI.java:24)
at com.github.gtache.lsp.settings.MiscSettings.createComponent(MiscSettings.kt:20)
at com.intellij.openapi.options.ex.ConfigurableWrapper.createComponent(ConfigurableWrapper.java:169)
at com.intellij.openapi.options.ex.ConfigurableCardPanel.lambda$createConfigurableComponent$4(ConfigurableCardPanel.java:115)
at com.intellij.openapi.application.impl.ApplicationImpl.runReadAction(ApplicationImpl.java:854)
at com.intellij.openapi.application.ReadAction.compute(ReadAction.java:61)
at com.intellij.openapi.options.ex.ConfigurableCardPanel.createConfigurableComponent(ConfigurableCardPanel.java:111)
at com.intellij.openapi.options.ex.ConfigurableCardPanel.create(ConfigurableCardPanel.java:59)
at com.intellij.openapi.options.newEditor.ConfigurableEditor$1.create(ConfigurableEditor.java:54)
at com.intellij.openapi.options.newEditor.ConfigurableEditor$1.create(ConfigurableEditor.java:51)
at com.intellij.ui.CardLayoutPanel.createValue(CardLayoutPanel.java:73)
at com.intellij.ui.CardLayoutPanel.select(CardLayoutPanel.java:101)
at com.intellij.ui.CardLayoutPanel.lambda$selectLater$0(CardLayoutPanel.java:117)
at com.intellij.openapi.application.TransactionGuardImpl.runWithWritingAllowed(TransactionGuardImpl.java:214)
at com.intellij.openapi.application.TransactionGuardImpl.access$200(TransactionGuardImpl.java:21)
at com.intellij.openapi.application.TransactionGuardImpl$2.run(TransactionGuardImpl.java:196)
at com.intellij.openapi.application.impl.ApplicationImpl.runIntendedWriteActionOnCurrentThread(ApplicationImpl.java:794)
at com.intellij.openapi.application.impl.ApplicationImpl.lambda$invokeLater$4(ApplicationImpl.java:350)
at com.intellij.openapi.application.impl.FlushQueue.doRun(FlushQueue.java:84)
at com.intellij.openapi.application.impl.FlushQueue.runNextEvent(FlushQueue.java:133)
at com.intellij.openapi.application.impl.FlushQueue.flushNow(FlushQueue.java:46)
at com.intellij.openapi.application.impl.FlushQueue$FlushNow.run(FlushQueue.java:189)
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:886)
at com.intellij.ide.IdeEventQueue._dispatchEvent(IdeEventQueue.java:755)
at com.intellij.ide.IdeEventQueue.lambda$dispatchEvent$7(IdeEventQueue.java:442)
at com.intellij.openapi.progress.impl.CoreProgressManager.computePrioritized(CoreProgressManager.java:825)
at com.intellij.ide.IdeEventQueue.lambda$dispatchEvent$8(IdeEventQueue.java:441)
at com.intellij.openapi.application.impl.ApplicationImpl.runIntendedWriteActionOnCurrentThread(ApplicationImpl.java:794)
at com.intellij.ide.IdeEventQueue.dispatchEvent(IdeEventQueue.java:487)
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.pumpEventsForFilter(EventDispatchThread.java:117)
at java.desktop/java.awt.WaitDispatchSupport$2.run(WaitDispatchSupport.java:190)
at java.desktop/java.awt.WaitDispatchSupport$4.run(WaitDispatchSupport.java:235)
at java.desktop/java.awt.WaitDispatchSupport$4.run(WaitDispatchSupport.java:233)
at java.base/java.security.AccessController.doPrivileged(Native Method)
at java.desktop/java.awt.WaitDispatchSupport.enter(WaitDispatchSupport.java:233)
at java.desktop/java.awt.Dialog.show(Dialog.java:1063)
at com.intellij.openapi.ui.impl.DialogWrapperPeerImpl$MyDialog.show(DialogWrapperPeerImpl.java:699)
at com.intellij.openapi.ui.impl.DialogWrapperPeerImpl.show(DialogWrapperPeerImpl.java:435)
at com.intellij.openapi.ui.DialogWrapper.doShow(DialogWrapper.java:1726)
at com.intellij.openapi.ui.DialogWrapper.show(DialogWrapper.java:1685)
at com.intellij.ide.actions.ShowSettingsUtilImpl.showSettingsDialog(ShowSettingsUtilImpl.java:90)
at com.intellij.ide.actions.ShowSettingsAction.perform(ShowSettingsAction.java:55)
at com.intellij.ide.actions.ShowSettingsAction.actionPerformed(ShowSettingsAction.java:42)
at com.intellij.openapi.actionSystem.ex.ActionUtil.lambda$performActionDumbAwareWithCallbacks$4(ActionUtil.java:240)
at com.intellij.openapi.actionSystem.ex.ActionUtil.performDumbAwareWithCallbacks(ActionUtil.java:261)
at com.intellij.openapi.actionSystem.ex.ActionUtil.performActionDumbAwareWithCallbacks(ActionUtil.java:240)
at com.intellij.openapi.actionSystem.impl.ActionMenuItem$ActionTransmitter.lambda$actionPerformed$0(ActionMenuItem.java:272)
at com.intellij.openapi.wm.impl.FocusManagerImpl.runOnOwnContext(FocusManagerImpl.java:236)
at com.intellij.openapi.wm.impl.IdeFocusManagerImpl.runOnOwnContext(IdeFocusManagerImpl.java:67)
at com.intellij.openapi.actionSystem.impl.ActionMenuItem$ActionTransmitter.actionPerformed(ActionMenuItem.java:264)
at java.desktop/javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:1967)
at com.intellij.openapi.actionSystem.impl.ActionMenuItem.lambda$fireActionPerformed$0(ActionMenuItem.java:98)
at com.intellij.openapi.application.TransactionGuardImpl.performUserActivity(TransactionGuardImpl.java:94)
at com.intellij.openapi.actionSystem.impl.ActionMenuItem.fireActionPerformed(ActionMenuItem.java:98)
at com.intellij.ui.plaf.beg.BegMenuItemUI.doClick(BegMenuItemUI.java:515)
at com.intellij.ui.plaf.beg.BegMenuItemUI$MyMouseInputHandler.mouseReleased(BegMenuItemUI.java:545)
at java.desktop/java.awt.Component.processMouseEvent(Component.java:6652)
at java.desktop/javax.swing.JComponent.processMouseEvent(JComponent.java:3345)
at java.desktop/java.awt.Component.processEvent(Component.java:6417)
at java.desktop/java.awt.Container.processEvent(Container.java:2263)
at java.desktop/java.awt.Component.dispatchEventImpl(Component.java:5027)
at java.desktop/java.awt.Container.dispatchEventImpl(Container.java:2321)
at java.desktop/java.awt.Component.dispatchEvent(Component.java:4859)
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:2784)
at java.desktop/java.awt.Component.dispatchEvent(Component.java:4859)
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:886)
at com.intellij.ide.IdeEventQueue.dispatchMouseEvent(IdeEventQueue.java:815)
at com.intellij.ide.IdeEventQueue._dispatchEvent(IdeEventQueue.java:752)
at com.intellij.ide.IdeEventQueue.lambda$dispatchEvent$7(IdeEventQueue.java:442)
at com.intellij.openapi.progress.impl.CoreProgressManager.computePrioritized(CoreProgressManager.java:825)
at com.intellij.ide.IdeEventQueue.lambda$dispatchEvent$8(IdeEventQueue.java:441)
at com.intellij.openapi.application.impl.ApplicationImpl.runIntendedWriteActionOnCurrentThread(ApplicationImpl.java:794)
at com.intellij.ide.IdeEventQueue.dispatchEvent(IdeEventQueue.java:493)
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)
Caused by: com.intellij.util.xmlb.XmlSerializationException: Cannot deserialize class com.github.gtache.lsp.settings.LSPProjectState
at com.intellij.configurationStore.JdomSerializerImpl.deserialize(xmlSerializer.kt:97)
at com.intellij.configurationStore.DefaultStateSerializerKt.deserializeState(DefaultStateSerializer.kt:29)
at com.intellij.configurationStore.StateStorageBase.deserializeState(StateStorageBase.kt:35)
at com.intellij.configurationStore.StateGetterImpl.getState(StorageBaseEx.kt:57)
at com.intellij.configurationStore.ComponentStoreImpl.doInitComponent(ComponentStoreImpl.kt:423)
at com.intellij.configurationStore.ComponentStoreImpl.initComponent(ComponentStoreImpl.kt:373)
at com.intellij.configurationStore.ComponentStoreImpl.initComponent(ComponentStoreImpl.kt:124)
... 114 more
Caused by: java.util.NoSuchElementException: List is empty.
at kotlin.collections.CollectionsKt___CollectionsKt.first(_Collections.kt:212)
at kotlin.collections.CollectionsKt___CollectionsKt.first(_Collections.kt:196)
at com.intellij.serialization.BaseBeanBindingKt.createUsingKotlin(BaseBeanBinding.kt:49)
at com.intellij.serialization.BaseBeanBindingKt.access$createUsingKotlin(BaseBeanBinding.kt:1)
at com.intellij.serialization.BaseBeanBinding.newInstance(BaseBeanBinding.kt:34)
at com.intellij.serialization.xml.KotlinAwareBeanBinding.newInstance(KotlinAwareBeanBinding.kt:76)
at com.intellij.util.xmlb.BeanBinding.deserialize(BeanBinding.java:142)
at com.intellij.configurationStore.JdomSerializerImpl.deserialize(xmlSerializer.kt:91)
... 120 more

The relevant classes:

LSPProjectSettings

interface LSPProjectSettings : PersistentStateComponent<LSPProjectState> {
var projectState : LSPProjectState
}

LSPProjectSettingsImpl

@State(name = "LSPProjectState", storages = [Storage(value = "LSPProjectState.xml")])
class LSPProjectSettingsImpl(private val project: Project) : LSPProjectSettings {

override var projectState: LSPProjectState = LSPProjectStateImpl()

override fun hashCode(): Int {
return Objects.hash(project, projectState)
}

override fun equals(other: Any?): Boolean {
return (other is LSPProjectSettingsImpl) && project == other.project && projectState == other.projectState
}

override fun getState(): LSPProjectState {
return projectState
}

override fun loadState(state: LSPProjectState) {
projectState = state
logger.info("LSP Project State loaded")
project.service<LSPProjectService>().notifyStateLoaded()
}

companion object {
private val logger = Logger.getInstance(LSPProjectSettingsImpl::class.java)
}
}

LSPProjectState

interface LSPProjectState {
var isLoggingServersOutput: Boolean
var isAlwaysSendRequests: Boolean
var extToServ: Map<String, Array<String>>
var forcedAssociations: Map<String, Array<String>>

fun withLoggingServersOutput(isLoggingServersOutput: Boolean): LSPProjectState
fun withAlwaysSendRequests(isAlwaysSendRequests: Boolean): LSPProjectState
fun withExtToServ(extToServ: Map<String, Array<String>>): LSPProjectState
fun withForcedAssociations(forcedAssociations: Map<String, Array<String>>): LSPProjectState
}

LSPProjectStateImpl

data class LSPProjectStateImpl(
override var isLoggingServersOutput: Boolean,
override var isAlwaysSendRequests: Boolean,
override var extToServ: Map<String, Array<String>>,
override var forcedAssociations: Map<String, Array<String>>
) : LSPProjectState {
constructor() : this(false, false, emptyMap(), emptyMap())

override fun withLoggingServersOutput(isLoggingServersOutput: Boolean): LSPProjectState {
return LSPProjectStateImpl(isLoggingServersOutput, isAlwaysSendRequests, extToServ, forcedAssociations)
}

override fun withAlwaysSendRequests(isAlwaysSendRequests: Boolean): LSPProjectState {
return LSPProjectStateImpl(isLoggingServersOutput, isAlwaysSendRequests, extToServ, forcedAssociations)
}

override fun withExtToServ(extToServ: Map<String, Array<String>>): LSPProjectState {
return LSPProjectStateImpl(isLoggingServersOutput, isAlwaysSendRequests, extToServ, forcedAssociations)
}

override fun withForcedAssociations(forcedAssociations: Map<String, Array<String>>): LSPProjectState {
return LSPProjectStateImpl(isLoggingServersOutput, isAlwaysSendRequests, extToServ, forcedAssociations)
}
}

I also have the same problem with my (basically the same) LSPApplicationState structure.

Not sure if I needed an empty private constructor for the data class or if default values would have sufficed. I'm not sure either if the "projectState" value must change for it to be saved (hence the existence of the "with..." methods) or if changing its fields (like isLoggingServersOutput) would be sufficient.

Tell me if you need any other information!

0
Comment actions Permalink

Alright fixed it, I simply removed the State interfaces and directly referenced the StateImpl classes (so that they don't inherit anything). The BaseBeanBinding#newInstance method was trying to find the constructor of the interface, which obviously didn't work.

Should I simply delete this topic or keep it in case someone has the same problem(s)?

0
Comment actions Permalink

Thanks for all the details and providing the final answer, Guillaume! Let's keep your thread for the others.

0

Please sign in to leave a comment.