XmlSerializationException while de-serializing PersistentStateComponent

Hi all,

I'm trying to build a plugin, but can't get the settings to restore.  I've read through some other thread on this, and tried to follow those suggestions, but none of them have worked for me yet.  I feel like I have to be missing something stupid here, but I can't figure it out.  Any help is much appreciated.

The relevant portion of plugin.xml where I declare my service

<extensions defaultExtensionNs="com.intellij">
        <applicationService serviceInterface="com.crownpartners.intellivault.services.IntelliVaultConfigurationService"
                            serviceImplementation="com.crownpartners.intellivault.services.impl.IntelliVaultConfigurationServiceImpl"/>
</extensions>



and the declaration for com.crownpartners.intellivault.services.impl.IntelliVaultConfigurationServiceImpl which implements PersistentStateComponent

@State(
        name = "IntelliVaultConfigurationServiceImpl",
        storages = {
                @Storage(id = "main", file = "$APP_CONFIG$/IntelliVaultConfigurationService.xml")
        }
)
public class IntelliVaultConfigurationServiceImpl implements IntelliVaultConfigurationService, PersistentStateComponent<IntelliVaultPreferencesBean> {
...
}



I can modify settings, and see the IntelliVaultConfigurationService.xml written to disk.  When I close IntelliVault and open it back up, then call ServiceManager.getService(IntelliVaultConfigurationService.class) the first time, I get this error:

[  25974]  ERROR - .components.ComponentStoreImpl - java.lang.NullPointerException
com.intellij.util.xmlb.XmlSerializationException: java.lang.NullPointerException
 at com.intellij.util.xmlb.XmlSerializer.deserialize(XmlSerializer.java:64)
 at com.intellij.openapi.components.impl.stores.DefaultStateSerializer.deserializeState(DefaultStateSerializer.java:120)
 at com.intellij.openapi.components.impl.stores.XmlElementStorage.getState(XmlElementStorage.java:145)
 at com.intellij.openapi.components.impl.stores.ComponentStoreImpl.initPersistentComponent(ComponentStoreImpl.java:287)
 at com.intellij.openapi.components.impl.stores.ComponentStoreImpl.access$000(ComponentStoreImpl.java:44)
 at com.intellij.openapi.components.impl.stores.ComponentStoreImpl$1.run(ComponentStoreImpl.java:84)
 at com.intellij.openapi.application.impl.ApplicationImpl.runReadAction(ApplicationImpl.java:924)
 at com.intellij.openapi.components.impl.stores.ComponentStoreImpl.initComponent(ComponentStoreImpl.java:81)
 at com.intellij.openapi.application.impl.ApplicationImpl.initializeComponent(ApplicationImpl.java:209)
 at com.intellij.openapi.components.impl.ServiceManagerImpl$MyComponentAdapter.initializeInstance(ServiceManagerImpl.java:164)
 at com.intellij.openapi.components.impl.ServiceManagerImpl$MyComponentAdapter$1.compute(ServiceManagerImpl.java:147)
 at com.intellij.openapi.application.impl.ApplicationImpl.runReadAction(ApplicationImpl.java:945)
 at com.intellij.openapi.components.impl.ServiceManagerImpl$MyComponentAdapter.getComponentInstance(ServiceManagerImpl.java:139)
 at com.intellij.util.pico.DefaultPicoContainer.getLocalInstance(DefaultPicoContainer.java:242)
 at com.intellij.util.pico.DefaultPicoContainer.getInstance(DefaultPicoContainer.java:229)
 at com.intellij.util.pico.DefaultPicoContainer.getComponentInstance(DefaultPicoContainer.java:211)
 at org.picocontainer.alternatives.AbstractDelegatingMutablePicoContainer.getComponentInstance(AbstractDelegatingMutablePicoContainer.java:75)
 at com.intellij.openapi.components.ServiceManager.getService(ServiceManager.java:36)
 at com.crownpartners.intellivault.ui.IntelliiVaultSettings.reset(IntelliiVaultSettings.java:122)
 at com.crownpartners.intellivault.ui.IntelliiVaultSettings.createComponent(IntelliiVaultSettings.java:102)
 at com.intellij.openapi.options.newEditor.OptionsEditor$Simple.<init>(OptionsEditor.java:1260)
 at com.intellij.openapi.options.newEditor.OptionsEditor.initConfigurable(OptionsEditor.java:445)
 at com.intellij.openapi.options.newEditor.OptionsEditor.access$2500(OptionsEditor.java:68)
 at com.intellij.openapi.options.newEditor.OptionsEditor$8$1$1.run(OptionsEditor.java:414)
 at com.intellij.openapi.application.impl.ApplicationImpl.runEdtSafeAction(ApplicationImpl.java:1103)
 at com.intellij.openapi.options.newEditor.OptionsEditor$8$1.run(OptionsEditor.java:408)
 at com.intellij.openapi.application.impl.ApplicationImpl.runReadAction(ApplicationImpl.java:935)
 at com.intellij.openapi.options.newEditor.OptionsEditor$8.run(OptionsEditor.java:406)
 at com.intellij.openapi.application.impl.ApplicationImpl$6.run(ApplicationImpl.java:465)
 at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:441)
 at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:303)
 at java.util.concurrent.FutureTask.run(FutureTask.java:138)
 at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886)
 at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)
 at java.lang.Thread.run(Thread.java:662)
 at com.intellij.openapi.application.impl.ApplicationImpl$1$1.run(ApplicationImpl.java:153)
Caused by: java.lang.NullPointerException
 at com.intellij.util.xmlb.CollectionBinding.processResult(CollectionBinding.java:34)
 at com.intellij.util.xmlb.AbstractCollectionBinding.deserialize(AbstractCollectionBinding.java:162)
 at com.intellij.util.xmlb.OptionTagBinding.deserialize(OptionTagBinding.java:106)
 at com.intellij.util.xmlb.BeanBinding._deserializeInto(BeanBinding.java:163)
 at com.intellij.util.xmlb.BeanBinding.deserialize(BeanBinding.java:120)
 at com.intellij.util.xmlb.XmlSerializer.deserialize(XmlSerializer.java:58)
 ... 35 more

2 comments

Hi Sean,

Problem place seems to be 'ava.lang.NullPointerException at com.intellij.util.xmlb.CollectionBinding.processResult(CollectionBinding.java:34)'.

Please ensure that all fields of the returned state object are not nulls. Just use an empty collection instead.

Denis

0

Denis, thanks for this.

It turns out that my state class, IntelliVaultPreferencesBean, was missing a default constructor to intialize the fields with default values, hence the NPE.

0

Please sign in to leave a comment.