platan/idea-gradle-dependencies-formatter

StringNotationToMapNotationIntention - NullPointerException

Vity01 opened this issue ยท 9 comments

I don't have some piece of code to reproduce the problem, but I hope it helps.
Plugin version 0.6
Intellij Idea Ultimate 2020.3.2

EDIT1. I think it's somehow related with a editing Groovy code in the README.MD when you mark code section as groovy, eg. :

README.MD

|```groovy
|  some piece of Groovy code   
|```

Stacktrace

java.lang.NullPointerException
	at com.github.platan.idea.dependencies.intentions.StringNotationToMapNotationIntention.findElement(StringNotationToMapNotationIntention.java:107)
	at com.github.platan.idea.dependencies.intentions.StringNotationToMapNotationIntention.lambda$getElementPredicate$0(StringNotationToMapNotationIntention.java:89)
	at org.jetbrains.plugins.groovy.intentions.base.Intention.findMatchingElement(Intention.java:92)
	at org.jetbrains.plugins.groovy.intentions.base.Intention.isAvailable(Intention.java:113)
	at com.github.platan.idea.dependencies.intentions.SelectionIntention.isAvailable(SelectionIntention.java:71)
	at com.intellij.codeInsight.intention.impl.ShowIntentionActionsHandler.availableFor(ShowIntentionActionsHandler.java:155)
	at com.intellij.codeInsight.daemon.impl.ShowIntentionsPass.lambda$getActionsToShow$1(ShowIntentionsPass.java:322)
	at com.intellij.codeInsight.intention.impl.ShowIntentionActionsHandler.chooseBetweenHostAndInjected(ShowIntentionActionsHandler.java:182)
	at com.intellij.codeInsight.daemon.impl.ShowIntentionsPass.getActionsToShow(ShowIntentionsPass.java:321)
	at com.intellij.codeInsight.daemon.impl.ShowIntentionsPass.doCollectInformation(ShowIntentionsPass.java:226)
	at com.intellij.codeHighlighting.TextEditorHighlightingPass.collectInformation(TextEditorHighlightingPass.java:56)
	at com.intellij.codeInsight.daemon.impl.PassExecutorService$ScheduledPass.lambda$doRun$1(PassExecutorService.java:400)
	at com.intellij.openapi.application.impl.ApplicationImpl.tryRunReadAction(ApplicationImpl.java:1137)
	at com.intellij.codeInsight.daemon.impl.PassExecutorService$ScheduledPass.lambda$doRun$2(PassExecutorService.java:393)
	at com.intellij.openapi.progress.impl.CoreProgressManager.registerIndicatorAndRun(CoreProgressManager.java:658)
	at com.intellij.openapi.progress.impl.CoreProgressManager.executeProcessUnderProgress(CoreProgressManager.java:610)
	at com.intellij.openapi.progress.impl.ProgressManagerImpl.executeProcessUnderProgress(ProgressManagerImpl.java:65)
	at com.intellij.codeInsight.daemon.impl.PassExecutorService$ScheduledPass.doRun(PassExecutorService.java:392)
	at com.intellij.codeInsight.daemon.impl.PassExecutorService$ScheduledPass.lambda$run$0(PassExecutorService.java:368)
	at com.intellij.openapi.application.impl.ReadMostlyRWLock.executeByImpatientReader(ReadMostlyRWLock.java:172)
	at com.intellij.openapi.application.impl.ApplicationImpl.executeByImpatientReader(ApplicationImpl.java:183)
	at com.intellij.codeInsight.daemon.impl.PassExecutorService$ScheduledPass.run(PassExecutorService.java:366)
	at com.intellij.concurrency.JobLauncherImpl$VoidForkJoinTask$1.exec(JobLauncherImpl.java:188)
	at java.base/java.util.concurrent.ForkJoinTask.doExec(ForkJoinTask.java:290)
	at java.base/java.util.concurrent.ForkJoinPool$WorkQueue.topLevelExec(ForkJoinPool.java:1020)
	at java.base/java.util.concurrent.ForkJoinPool.scan(ForkJoinPool.java:1656)
	at java.base/java.util.concurrent.ForkJoinPool.runWorker(ForkJoinPool.java:1594)
	at java.base/java.util.concurrent.ForkJoinWorkerThread.run(ForkJoinWorkerThread.java:183)

@Vity01 thank you for reporting this ๐Ÿ‘ . I can reproduce it and I will fix it.

@platan how it's going? There doesn't seem to be much activity in the repository ๐Ÿ˜”

Same exception here:

java.lang.NullPointerException: Cannot invoke "com.intellij.psi.PsiElement.getParent()" because the return value of "com.intellij.psi.PsiElement.getParent()" is null
	at com.github.platan.idea.dependencies.intentions.StringNotationToMapNotationIntention.findElement(StringNotationToMapNotationIntention.java:107)
	at com.github.platan.idea.dependencies.intentions.StringNotationToMapNotationIntention.lambda$getElementPredicate$0(StringNotationToMapNotationIntention.java:89)
	at org.jetbrains.plugins.groovy.intentions.base.Intention.findMatchingElement(Intention.java:92)
	at org.jetbrains.plugins.groovy.intentions.base.Intention.isAvailable(Intention.java:113)
	at com.github.platan.idea.dependencies.intentions.SelectionIntention.isAvailable(SelectionIntention.java:71)
	at com.intellij.codeInsight.intention.impl.ShowIntentionActionsHandler.availableFor(ShowIntentionActionsHandler.java:169)
	at com.intellij.codeInsight.daemon.impl.ShowIntentionsPass.lambda$getActionsToShow$1(ShowIntentionsPass.java:336)
	at com.intellij.codeInsight.intention.impl.ShowIntentionActionsHandler.chooseBetweenHostAndInjected(ShowIntentionActionsHandler.java:202)
	at com.intellij.codeInsight.daemon.impl.ShowIntentionsPass.getActionsToShow(ShowIntentionsPass.java:335)
	at com.intellij.codeInsight.daemon.impl.ShowIntentionsPass.doCollectInformation(ShowIntentionsPass.java:240)
	at com.intellij.codeHighlighting.TextEditorHighlightingPass.collectInformation(TextEditorHighlightingPass.java:56)
	at com.intellij.codeInsight.daemon.impl.PassExecutorService$ScheduledPass.lambda$doRun$1(PassExecutorService.java:414)
	at com.intellij.openapi.application.impl.ApplicationImpl.tryRunReadAction(ApplicationImpl.java:1078)
	at com.intellij.codeInsight.daemon.impl.PassExecutorService$ScheduledPass.lambda$doRun$2(PassExecutorService.java:407)
	at com.intellij.openapi.progress.impl.CoreProgressManager.registerIndicatorAndRun(CoreProgressManager.java:705)
	at com.intellij.openapi.progress.impl.CoreProgressManager.executeProcessUnderProgress(CoreProgressManager.java:647)
	at com.intellij.openapi.progress.impl.ProgressManagerImpl.executeProcessUnderProgress(ProgressManagerImpl.java:63)
	at com.intellij.codeInsight.daemon.impl.PassExecutorService$ScheduledPass.doRun(PassExecutorService.java:406)
	at com.intellij.codeInsight.daemon.impl.PassExecutorService$ScheduledPass.lambda$run$0(PassExecutorService.java:382)
	at com.intellij.openapi.application.impl.ReadMostlyRWLock.executeByImpatientReader(ReadMostlyRWLock.java:174)
	at com.intellij.openapi.application.impl.ApplicationImpl.executeByImpatientReader(ApplicationImpl.java:183)
	at com.intellij.codeInsight.daemon.impl.PassExecutorService$ScheduledPass.run(PassExecutorService.java:380)
	at com.intellij.concurrency.JobLauncherImpl$VoidForkJoinTask$1.exec(JobLauncherImpl.java:188)
	at java.base/java.util.concurrent.ForkJoinTask.doExec(ForkJoinTask.java:295)
	at java.base/java.util.concurrent.ForkJoinPool$WorkQueue.topLevelExec(ForkJoinPool.java:1016)
	at java.base/java.util.concurrent.ForkJoinPool.scan(ForkJoinPool.java:1665)
	at java.base/java.util.concurrent.ForkJoinPool.runWorker(ForkJoinPool.java:1598)
	at java.base/java.util.concurrent.ForkJoinWorkerThread.run(ForkJoinWorkerThread.java:183)

@0xfaulty @Janmm14 Thank you for reporting this. Did you get the exception while editing a *.gradle file or a *.md file?

@platan Exception does not occur so often, and I was unable to reproduce it on purpose, when it appears next time I will try to describe how got to it.
But as far as I remember, it wasn't necessary to edit the *.gradle file, it was enough for it to be displayed, for example, by the search window (Find in Files) for the project.

@platan got stable way how I face with this exception
Tested on latest (at this time) Idea version 2021.2.1
I use multimodule project if that matter (not tested in single module gradle projects)

  1. need to add several lines in different place of *.gradle file (idk maybe just one enough)
In my case these lines:
    compile "io.springfox:springfox-swagger2:${project.swaggerVersion}"
    compile "io.springfox:springfox-swagger-ui:${project.swaggerVersion}"
    ....
    compile project(":common")
  1. Git>Uncommited Changes>Stash Changes for stash these changes
  2. Restart idea and wait for indexing complete
  3. Git>Uncommited Changes>Unstash Changes then press View button and open changed file
  4. Then press << arrows to appy changes one by one
  5. Close that unstash windows
  6. (!) icon should appear with exception

@0xfaulty Thank you for detailed description. I was able to reproduce it easily.

I've just released a new version 0.6.1 which fixes this bug. The new version should be available in JetBrains marketplace within few days.

Version 0.6.1 is available in JetBrains marketplace.