Skip to content

Potential NPE in AbstractAnalyzeMojo.filterArtifactsByScope() #1615

@elharo

Description

@elharo

Problem

The filterArtifactsByScope() method at line 452 calls artifact.getScope().equals(scope) without checking if getScope() returns null:

private void filterArtifactsByScope(Set<Artifact> artifacts, String scope) {
    artifacts.removeIf(artifact -> artifact.getScope().equals(scope));
}

If artifact.getScope() returns null, this throws a NullPointerException.

Fix

Reverse the comparison or use Objects.equals():

artifacts.removeIf(artifact -> Objects.equals(artifact.getScope(), scope));

File

src/main/java/org/apache/maven/plugins/dependency/analyze/AbstractAnalyzeMojo.java:451-453

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions