Vscode-java-test: NPE occur when expanding the default package

Created on 10 Feb 2019  路  4Comments  路  Source: microsoft/vscode-java-test

I have a very simple Gradle (5.1.1) project with JUnit 4 tests configured in my build.gradle. The resulting .classpath file used by Eclipse JDT contains the following entries:


Eclipse .classpath entries

<classpathentry kind="src" output="bin/main" path="src/main/java">
    <attributes>
        <attribute name="gradle_scope" value="main"/>
        <attribute name="gradle_used_by_scope" value="main,test"/>
    </attributes>
</classpathentry>
<classpathentry kind="src" output="bin/test" path="src/test/java">
    <attributes>
        <attribute name="gradle_scope" value="test"/>
        <attribute name="gradle_used_by_scope" value="test"/>
        <attribute name="test" value="true"/>
    </attributes>
</classpathentry>

(I added the "test" attribute to the test entry manually, as per #470.)

Everything is compiled correctly and the VS Code Problems view is empty. However, when I try to load my tests (just one class, src/test/java/Tests.java) into the test explorer, I reach a NullPointerException from this line:


NPE Stacktrace

java.lang.NullPointerException
    at com.microsoft.java.test.plugin.util.TestSearchUtils.searchInPackage(TestSearchUtils.java:294)
    at com.microsoft.java.test.plugin.util.TestSearchUtils.searchTestItems(TestSearchUtils.java:133)
    at com.microsoft.java.test.plugin.handler.TestDelegateCommandHandler.executeCommand(TestDelegateCommandHandler.java:45)
    at org.eclipse.jdt.ls.core.internal.handlers.WorkspaceExecuteCommandHandler$1.run(WorkspaceExecuteCommandHandler.java:152)
    at org.eclipse.core.runtime.SafeRunner.run(SafeRunner.java:45)
    at org.eclipse.jdt.ls.core.internal.handlers.WorkspaceExecuteCommandHandler.executeCommand(WorkspaceExecuteCommandHandler.java:142)
    at org.eclipse.jdt.ls.core.internal.handlers.JDTLanguageServer.lambda$4(JDTLanguageServer.java:451)
    at org.eclipse.jdt.ls.core.internal.handlers.JDTLanguageServer.lambda$26(JDTLanguageServer.java:793)
    at java.util.concurrent.CompletableFuture.uniApply(CompletableFuture.java:602)
    at java.util.concurrent.CompletableFuture$UniApply.tryFire(CompletableFuture.java:577)
    at java.util.concurrent.CompletableFuture$Completion.exec(CompletableFuture.java:443)
    at java.util.concurrent.ForkJoinTask.doExec(ForkJoinTask.java:289)
    at java.util.concurrent.ForkJoinPool$WorkQueue.runTask(ForkJoinPool.java:1056)
    at java.util.concurrent.ForkJoinPool.runWorker(ForkJoinPool.java:1692)
    at java.util.concurrent.ForkJoinWorkerThread.run(ForkJoinWorkerThread.java:157)

It seems like resolvePackage can and does return null, but this plugin does not check for null.

Code


src/test/java/Tests.java

import org.junit.Assert;
import org.junit.Test;

public class Tests {
    @Test
    public void testA() {
        Assert.assertTrue(true);
    }
}



build.gradle

apply plugin: 'java'
apply plugin: 'eclipse'

repositories {
    mavenCentral()
}

dependencies {
    testCompile 'junit:junit:4.12'
}

Reproduction

Just create a Gradle 5.1.1 (should still happen on other versions) project with the above code and populate the test explorer, then try to expand the empty entry under the root project. Mine looks like this:
Test Explorer view

bug

Most helpful comment

Using a package is a good fix for the time being, thanks.

All 4 comments

@mccreery Thank you for reporting, will take a look

@mccreery For now the extension does not support the default package. I'll figure out if there is any way to support it.

Using a package is a good fix for the time being, thanks.

add eclipse to gradle plugins, and then gradle eclipse, .classpath will generated and recognized by vscode.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

gabloe picture gabloe  路  7Comments

spottedmahn picture spottedmahn  路  7Comments

Gueka picture Gueka  路  3Comments

ZhengguanLi picture ZhengguanLi  路  8Comments

andifalk picture andifalk  路  9Comments