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

NPE occur when expanding the default package #611

Closed
mccreery opened this issue Feb 10, 2019 · 4 comments · Fixed by #690
Closed

NPE occur when expanding the default package #611

mccreery opened this issue Feb 10, 2019 · 4 comments · Fixed by #690
Labels
Milestone

Comments

@mccreery
Copy link

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

@jdneo
Copy link
Member

jdneo commented Feb 11, 2019

@mccreery Thank you for reporting, will take a look

@jdneo jdneo added the bug label Feb 11, 2019
@jdneo
Copy link
Member

jdneo commented Mar 6, 2019

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

@mccreery
Copy link
Author

mccreery commented Mar 6, 2019

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

@jdneo jdneo changed the title NPE when refreshing Test Explorer: JDT resolvePackage NPE occur when expanding the default package Mar 18, 2019
@jdneo jdneo added this to the 0.16.1 milestone May 8, 2019
@jdneo jdneo closed this as completed in #690 May 8, 2019
@ghost
Copy link

ghost commented Mar 12, 2020

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

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

Successfully merging a pull request may close this issue.

2 participants