Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

NullPointerException calling com.intellij.psi.PsiElement.getReferences() #41

Open
wfhartford opened this issue Nov 29, 2023 · 6 comments

Comments

@wfhartford
Copy link

Reported by IntelliJ:

java.lang.NullPointerException: Cannot invoke "com.intellij.psi.PsiElement.getReferences()" because the return value of "com.intellij.psi.PsiElement.getFirstChild()" is null
	at com.faendir.intellij.gradleVersionCatalogs.kotlin.Accessor$Companion.find(Accessor.kt:24)
	at com.faendir.intellij.gradleVersionCatalogs.kotlin.cache.BuildGradleKtsPsiCache$findAccessor$1.invoke(BuildGradleKtsPsiCache.kt:27)
	at com.faendir.intellij.gradleVersionCatalogs.kotlin.cache.BuildGradleKtsPsiCache$findAccessor$1.invoke(BuildGradleKtsPsiCache.kt:27)
	at com.faendir.intellij.gradleVersionCatalogs.kotlin.cache.BuildGradleKtsPsiCache.findAccessor$lambda$1(BuildGradleKtsPsiCache.kt:27)
	at com.intellij.psi.util.CachedValuesManager.lambda$getProjectPsiDependentCache$0(CachedValuesManager.java:134)
	at com.intellij.psi.util.CachedValuesManager$1.compute(CachedValuesManager.java:158)
	at com.intellij.psi.impl.PsiCachedValueImpl.doCompute(PsiCachedValueImpl.java:37)
	at com.intellij.util.CachedValueBase.lambda$getValueWithLock$3(CachedValueBase.java:240)
	at com.intellij.util.CachedValueBase.computeData(CachedValueBase.java:43)
	at com.intellij.util.CachedValueBase.lambda$getValueWithLock$4(CachedValueBase.java:240)
	at com.intellij.openapi.util.RecursionManager$1.computePreventingRecursion(RecursionManager.java:110)
	at com.intellij.openapi.util.RecursionGuard.doPreventingRecursion(RecursionGuard.java:27)
	at com.intellij.openapi.util.RecursionManager.doPreventingRecursion(RecursionManager.java:65)
	at com.intellij.util.CachedValueBase.getValueWithLock(CachedValueBase.java:241)
	at com.intellij.psi.impl.PsiCachedValueImpl.getValue(PsiCachedValueImpl.java:27)
	at com.intellij.util.CachedValuesManagerImpl.getCachedValue(CachedValuesManagerImpl.java:69)
	at com.intellij.psi.util.CachedValuesManager.getCachedValue(CachedValuesManager.java:155)
	at com.intellij.psi.util.CachedValuesManager.getProjectPsiDependentCache(CachedValuesManager.java:132)
	at com.faendir.intellij.gradleVersionCatalogs.kotlin.cache.BuildGradleKtsPsiCache.findAccessor(BuildGradleKtsPsiCache.kt:27)
	at com.faendir.intellij.gradleVersionCatalogs.kotlin.inlayhints.VersionCatalogInlayHintsProvider$getCollectorFor$1.collect(VersionCatalogInlayHintsProvider.kt:37)
	at com.intellij.codeInsight.hints.CollectorWithSettings.collectHints(InlayHintsUtils.kt:91)
	at com.intellij.codeInsight.hints.InlayHintsPass.doCollectInformation$lambda$0(InlayHintsPass.kt:46)
	at com.intellij.concurrency.ApplierCompleter.execAndForkSubTasks(ApplierCompleter.java:142)
	at com.intellij.openapi.application.impl.ApplicationImpl.tryRunReadAction(ApplicationImpl.java:1133)
	at com.intellij.concurrency.ApplierCompleter.lambda$wrapInReadActionAndIndicator$1(ApplierCompleter.java:98)
	at com.intellij.openapi.progress.impl.CoreProgressManager.lambda$executeProcessUnderProgress$13(CoreProgressManager.java:604)
	at com.intellij.openapi.progress.impl.CoreProgressManager.registerIndicatorAndRun(CoreProgressManager.java:679)
	at com.intellij.openapi.progress.impl.CoreProgressManager.computeUnderProgress(CoreProgressManager.java:635)
	at com.intellij.openapi.progress.impl.CoreProgressManager.executeProcessUnderProgress(CoreProgressManager.java:603)
	at com.intellij.openapi.progress.impl.ProgressManagerImpl.executeProcessUnderProgress(ProgressManagerImpl.java:61)
	at com.intellij.concurrency.ApplierCompleter.wrapInReadActionAndIndicator(ApplierCompleter.java:110)
	at com.intellij.concurrency.ApplierCompleter.compute(ApplierCompleter.java:91)
	at java.base/java.util.concurrent.CountedCompleter.exec(CountedCompleter.java:754)
	at java.base/java.util.concurrent.ForkJoinTask.doExec(ForkJoinTask.java:373)
	at java.base/java.util.concurrent.ForkJoinPool$WorkQueue.topLevelExec(ForkJoinPool.java:1182)
	at java.base/java.util.concurrent.ForkJoinPool.scan(ForkJoinPool.java:1655)
	at java.base/java.util.concurrent.ForkJoinPool.runWorker(ForkJoinPool.java:1622)
	at java.base/java.util.concurrent.ForkJoinWorkerThread.run(ForkJoinWorkerThread.java:165)
@5peak2me
Copy link
Contributor

5peak2me commented Dec 15, 2023

@wfhartford Please provide toml file or sample project, This error appears to be caused by the following line. Thanks!

val references = if (element.lastChild.references.mapNotNull(PsiReference::resolve).isEmpty()) {
                element.lastChild.firstChild.references
            } else element.lastChild.references

@wfhartford
Copy link
Author

Hi, sorry for the delay. I'm still getting this error, but I never notice it when it happens, only some time after I've been editing the toml file. I wonder if it's caused by the plugin parsing the toml file in an invalid state.

Other than the error reported by IntelliJ, it doesn't seem like this is causing any serious problems. I'm getting all the features I expect from the plugin and not being prevented from doing anything.

@wfhartford
Copy link
Author

I've been getting this error again today and haven't been editing the libs.versions.toml file at all. I'm attaching the file; github won't let me attach a .toml file, so I've added .txt to the name.
libs.versions.toml.txt

@5peak2me
Copy link
Contributor

Thanks,I‘ll debug the issue.

@5peak2me
Copy link
Contributor

Would you mind providing the build.gradle(.kts) file?

@wfhartford
Copy link
Author

Unfortunately, I can't. This is a multi-module project so there are a handful of build build along with a few proprietary plugins. My employer does not want all those details shared. I'd be happy to answer any questions you might have though.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants