Skip to content

[maven-4.0.x] DefaultModelBuilder: NPE on null rootDirectory #12590

Description

@elharo

DefaultModelBuilder: NPE on null rootDirectory

Found in: maven-4.0.x branch
File: impl/maven-impl/src/main/java/org/apache/maven/impl/model/DefaultModelBuilder.java (lines 719-720)
Severity: High

Description

rootDirectory can be null — it is assigned at lines 1544-1551 where both session.getRootDirectory() can throw and modelSource.getPath() can return null. But the getEnhancedProperties method calls .toString() on it without null check:

try {
    String root = rootDirectory.toString();
    String rootUri = rootDirectory.toUri().toString();
    ...
} catch (IllegalStateException e) {
    // Root directory not available, continue without it
}

A null rootDirectory throws NullPointerException, which is NOT caught by the catch(IllegalStateException) block. This can crash the build entirely for POMs with a modelSource that has no path and no session root directory.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingmvn4

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions