How to debug "java.lang.NullPointerException: getService(T::class.java)" in official Kotlin template of IntelliJ IDEA plugin?

Viewed 33

My plugin is based on official Jet Brains Kotlin template. Currently I am sharing only Live Templates via this plugin, so I have not touch anything below IDEsPlugins/IntelliJ_IDEA/src/main/kotlin (well, I have not Kotlin experience, but I need to develop the plugins).

When I run the plugin in test mode, I get:

java.lang.RuntimeException: java.lang.NullPointerException: getService(T::class.java) must not be null
    at com.intellij.openapi.application.impl.LaterInvocator.invokeAndWait(LaterInvocator.java:118)
    at com.intellij.openapi.application.impl.ApplicationImpl.invokeAndWait(ApplicationImpl.java:505)
    at com.intellij.openapi.application.impl.ApplicationImpl.invokeAndWait(ApplicationImpl.java:525)
    at com.intellij.openapi.project.impl.ProjectManagerExImplKt.openProject(ProjectManagerExImpl.kt:618)
    at com.intellij.openapi.project.impl.ProjectManagerExImplKt.access$openProject(ProjectManagerExImpl.kt:1)
    at com.intellij.openapi.project.impl.ProjectManagerExImpl$doOpenAsync$1.invoke(ProjectManagerExImpl.kt:149)
    at com.intellij.openapi.project.impl.ProjectManagerExImpl$doOpenAsync$1.invoke(ProjectManagerExImpl.kt:60)
    // ...

More output of Run Plugin task:

1: Task failed with an exception.
-----------
* What went wrong:
Execution failed for task ':runIde'.
> Build cancelled while executing task ':runIde'

* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.
==============================================================================

2: Task failed with an exception.
-----------
* What went wrong:
Execution failed for task ':classpathIndexCleanup'.
> Build cancelled while executing task ':classpathIndexCleanup'

* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.
==============================================================================

* Get more help at https://help.gradle.org

BUILD FAILED in 1m 42s

If to try to search getService in whole project, no search results will be.

If to check some classes like MyProjectManagerListener, in each one there are some errors. For example, in MyProjectManagerListener:

internal class MyProjectManagerListener : ProjectManagerListener {

    override fun projectOpened(project: Project) {
        project.service<MyProjectService>()
    }
}

there is the error:

Cannot access 'java.util.EventListener' which is a supertype of 'com.github.tokugawatakeshi.temp.listeners.MyProjectManagerListener'.

In MyBundle:

object MyBundle : DynamicBundle(BUNDLE) {

    @Suppress("SpreadOperator")
    @JvmStatic
    fun message(@PropertyKey(resourceBundle = BUNDLE) key: String, vararg params: Any) =
        getMessage(key, *params)

    @Suppress("SpreadOperator", "unused")
    @JvmStatic
    fun messagePointer(@PropertyKey(resourceBundle = BUNDLE) key: String, vararg params: Any) =
        getLazyMessage(key, *params)
}

there are the errors like:

Cannot access class 'java.lang.String'.

Let me repeat that I have not touch the boilerplate Kotlin code in src/main/kotlin.

I understand that I need to do some efforts myself, but currently I have no idea what exactly I need to do. Please give me some hint. If you are going to clone my repository for investigations please checkout the @v2.0 branch.

P. S. I have asked this question after has not been answered in **IDEs Support (IntelliJ Platform) ** for the more than 2 weeks.

0 Answers
Related