DbDataSourceImpl.getModel fails because: parent is null

I'm using the DbDataSource API and sometimes after working with Intellij for while & I think it's only after

opening more then a single instance of Intellij an error raises when calling the checkValid on the dbElementImpl

The stacktrace I'm getting :

 

2019-01-23 17:50:43,150 [23149249] ERROR - on.DataSourceAccessorComponent - Element: class com.intellij.database.psi.DbDataSourceImpl because: parent is null
invalidated at: no info
com.intellij.psi.PsiInvalidElementAccessException: Element: class com.intellij.database.psi.DbDataSourceImpl because: parent is null
invalidated at: no info
at com.intellij.psi.util.PsiUtilCore.ensureValid(PsiUtilCore.java:502)
at com.intellij.database.psi.DbElementImpl.checkValid(DbElementImpl.java:397)
at com.intellij.database.psi.DbDataSourceImpl.getModel(DbDataSourceImpl.java:193)
at com.idi.intellij.plugin.query.annoref.connection.DataSourceAccessorComponent.initializeStoreProceduresMap(DataSourceAccessorComponent.java:369)
at com.idi.intellij.plugin.query.annoref.connection.DataSourceAccessorComponent.getSpNames(DataSourceAccessorComponent.java:382)
at com.idi.intellij.plugin.query.annoref.config.SPViewPanelForm.searchForStartAndEndIndices(SPViewPanelForm.java:288)
at com.idi.intellij.plugin.query.annoref.config.SPViewPanelForm.highLightSPExecText(SPViewPanelForm.java:240)
at com.idi.intellij.plugin.query.annoref.config.SPViewPanelForm.isTextSetForViewing(SPViewPanelForm.java:212)
at com.idi.intellij.plugin.query.annoref.component.SPViewContentStateManager.getSPViewContent(SPViewContentStateManager.java:172)
at com.idi.intellij.plugin.query.annoref.component.SPViewContentStateManager.fetchSpForContentDisplay(SPViewContentStateManager.java:155)
at com.idi.intellij.plugin.query.annoref.codeInsight.SPToolWindowDisplayHelper.displaySPInToolWindow(SPToolWindowDisplayHelper.java:61)
at com.idi.intellij.plugin.query.annoref.codeInsight.SPToolWindowDisplayHelper.displayStorageProcedureText(SPToolWindowDisplayHelper.java:51)
at com.idi.intellij.plugin.query.annoref.codeInsight.MyJavaDocumentationProvider.lambda$getQuickNavigateInfo$24(MyJavaDocumentationProvider.java:95)
at com.intellij.openapi.project.DumbServiceImpl.b(DumbServiceImpl.java:170)
at com.intellij.ide.startup.impl.StartupManagerImpl.a(StartupManagerImpl.java:396)
at com.intellij.openapi.application.TransactionGuardImpl$2.run(TransactionGuardImpl.java:315)
at com.intellij.openapi.application.impl.LaterInvocator$FlushQueue.a(LaterInvocator.java:424)
at com.intellij.openapi.application.impl.LaterInvocator$FlushQueue.run(LaterInvocator.java:407)
at java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:311)
at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:762)
at java.awt.EventQueue.access$500(EventQueue.java:98)
at java.awt.EventQueue$3.run(EventQueue.java:715)
at java.awt.EventQueue$3.run(EventQueue.java:709)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:80)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:732)
at com.intellij.ide.IdeEventQueue.g(IdeEventQueue.java:822)
at com.intellij.ide.IdeEventQueue._dispatchEvent(IdeEventQueue.java:650)
at com.intellij.ide.IdeEventQueue.dispatchEvent(IdeEventQueue.java:366)
at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:201)
at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:116)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:105)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:101)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:93)
at java.awt.EventDispatchThread.run(EventDispatchThread.java:82)

which is called from - 

private void initializeStoreProceduresMap() {
if (getDataSource() != null) {
try {
DatabaseSystem databaseSystem = getDataSource();
databaseSystem.getModel().traverser()
.expand(o -> o instanceof DasNamespace)
.filter(DasRoutine.class)
.map(DasObject::getName).toMap((Convertor<String, String>) s -> null);
spNamesMap = Maps.newHashMapWithExpectedSize(getDataSource().getModel().getModelRoots().size());
} catch (PsiInvalidElementAccessException e) {
LOGGER.error(e);
}
}
}


Trying to get the DataSource with this code :

DbPsiFacade dataSourceManager = DbPsiFacade.getInstance(project);
Optional<DbDataSource> dbDataSource = dataSourceManager.getDataSources().stream().filter(dbDataSource1 -> dbDataSource1.getName().equals(selectDataSource)).findFirst();
if (!dbDataSource.isPresent()) {
logger.error("initDataSource(): No DataSource with name=" + selectDataSource + " was found!");
return false;
}
dataSource = dbDataSource.get();

The call I'm making is always from the main DispatchThread. 

Why is the Element is inValid on some occasions? 

Any help would be mostly appreciated.

Eldad.

Please sign in to leave a comment.