NPE in DefaultProjectDependency.findProjectConfiguration

I’m playing with using Kotlin Script for Gradle. When syncing IntelliJ IDEA with Gradle in a larger multi-project setup, I get a NullPointerException for various subprojects and the root project.

I’ve attached the debugger and found the cause in DefaultProjectDependency, line 92:

    public Configuration findProjectConfiguration(Map<String, String> clientAttributes) {
        Configuration selectedConfiguration = null;
        ConfigurationContainer dependencyConfigurations = getDependencyProject().getConfigurations();
        String declaredConfiguration = getTargetConfiguration();
        if (declaredConfiguration == null && !clientAttributes.isEmpty()) { // <<< declaredConfiguration and clientAttributes are null here
            List<Configuration> candidateConfigurations = new ArrayList<Configuration>(1);
            for (Configuration dependencyConfiguration : dependencyConfigurations) {

In the same class on line 126, the context with the null attributes was created:

    public Set<File> resolve(boolean transitive) {
        CachingDependencyResolveContext context = new CachingDependencyResolveContext(transitive, null); // <<< null attributes passed
        context.add(this);
        return context.resolve().getFiles();
    }

Stack trace:

findProjectConfiguration:92, DefaultProjectDependency (org.gradle.api.internal.artifacts.dependencies)
resolve:139, DefaultProjectDependency (org.gradle.api.internal.artifacts.dependencies)
getNodeValues:70, CachingDependencyResolveContext$DependencyGraph (org.gradle.api.internal.artifacts)
getNodeValues:202, CachingDirectedGraphWalker$GraphWithEmpyEdges (org.gradle.internal.graph)
doSearch:112, CachingDirectedGraphWalker (org.gradle.internal.graph)
findValues:64, CachingDirectedGraphWalker (org.gradle.internal.graph)
resolve:52, CachingDependencyResolveContext (org.gradle.api.internal.artifacts)
resolve:128, DefaultProjectDependency (org.gradle.api.internal.artifacts.dependencies)
resolve:122, DefaultProjectDependency (org.gradle.api.internal.artifacts.dependencies)
call:-1, SelfResolvingDependency$resolve (org.gradle.api.artifacts)
...

Please fix :slight_smile:

Gradle Version: 3.3-20161007221720+0000
Operating System and JVM version: macOS Sierra, JVM 1.8.0_65

PS: What are scans? https://scans.gradle.com is not working and redirects to the home page.

Thanks for the problem report. We happened to encounter the same problem quite recently. This is fixed by https://github.com/gradle/gradle/commit/f88ae7aa / https://github.com/gradle/gradle/commit/f8e703d7 .

1 Like