PersistentStateComponent throws NPE (unable to find the solution)
Hello, I am the first time writer here. And if current topic should be in the another section - please move it.
I am getting exception
[ 15939] ERROR - .components.ComponentStoreImpl - null
java.lang.NullPointerException
at com.intellij.openapi.components.impl.stores.ComponentStoreImpl.getComponentStorageSpecs(ComponentStoreImpl.java:381)
at com.intellij.openapi.components.impl.stores.ComponentStoreImpl.initPersistentComponent(ComponentStoreImpl.java:282)
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:929)
at com.intellij.openapi.components.impl.stores.ComponentStoreImpl.initComponent(ComponentStoreImpl.java:81)
at com.intellij.openapi.application.impl.ApplicationImpl.initializeComponent(ApplicationImpl.java:208)
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:950)
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)
My persistent component:
@State(name = "CodeReviewRemarks",
storages = {
@Storage(id = "default", file = StoragePathMacros.PROJECT_FILE),
@Storage(id = "dir", file = StoragePathMacros.PROJECT_CONFIG_DIR + "/code-review-remarks.xml", scheme = StorageScheme.DIRECTORY_BASED)
}
)
public class StorageComponent implements PersistentStateComponent {
@Override
public StorageComponent getState() {
return this;
}
@Override
public void loadState(Object state) {
XmlSerializerUtil.copyBean(state, this);
}
}
And how it is registered in plugin.xml:
<extensions defaultExtensionNs="com.intellij">
<applicationService id="CodeReview.StorageService"
serviceInterface="com.codereview.fs.StorageComponent"
serviceImplementation="com.codereview.fs.StorageComponent"/>
</extensions>
When i try to get this component like
StorageComponent compl = ServiceManager.getService(StorageComponent.class);
I've got the exception described at the beginning of this topic.
I was searching for the answers, but unable to get why i have this error.
Thanks.
Please sign in to leave a comment.
You're registering an application service and requesting that its state needs to be stored in the project. This won't work. To store state in the project, you need to create a project service.
Thanks, could you give an example how to make correct call?
I want to use persistent component on application level.
And where is the actual documentation about persistence?
I have searched on the forum, but most answers from 2006 and not actual anymore.
Thanks!
Are you sure that you can't use a project service? I would expect that code review activity is always associated with a specific project.
The plugin development documentation is here: http://confluence.jetbrains.com/display/IDEADEV/PluginDevelopment
Specifically, the PersistentStateComponent interface is documented here: http://confluence.jetbrains.com/display/IDEADEV/Persisting+State+of+Components