Skip to content

configureLocator() runs outside the guarded try and can throw raw NPE #275

Description

@elharo

Summary

execute() calls configureLocator() before the try block that contains the validation and resource processing, so any runtime exception it throws is not wrapped and escapes untyped.

src/main/java/org/apache/maven/plugin/resources/remote/AbstractProcessRemoteResourcesMojo.java:429-433

configureLocator();
ClassLoader origLoader = Thread.currentThread().getContextClassLoader();
try {
    validate();
    ...

configureLocator() at :482-507 dereferences project.getFile().getParentFile():

locator.addSearchPath(FileResourceLoader.ID, project.getFile().getParentFile().getAbsolutePath());

If the current project has no associated POM file (project.getFile() null — possible for models built without a file, super POMs, or stubs), this throws a raw NullPointerException instead of a MojoExecutionException. The rest of execute() deliberately wraps work in the try/finally (which also restores the thread context classloader) precisely to contain such failures.

Suggested fix

Move configureLocator() inside the guarded try, and/or null-guard project.getFile() in configureLocator() with a clear error message.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions