Skip to content

Commit

Permalink
Prevent NPE when extension is initiated after another one
Browse files Browse the repository at this point in the history
When maven-profiler is installed in the Maven distribution ext folder
and a project uses other extension from the .mvn/extensions.xml configuration,
maven-profiler was failing with NPE in fr.jcgay.maven.profiler.ProfilerEventSpy#onEvent.

This is because the #init method of the extension was not yet called when Maven was loading
extension from .mvn/extensions.xml. Maven was firing event intercepted by maven-profiler
but as it was not yet initiated, the configuration and statistics internal state was not ready.

This commit also initiate its state in the constructor.
It will prevent NPE but the statistics gathered between the instantiation and the initialization
will be lost anyway 😥. Because #init will clean internal state, and we need this to have the extension
functional with mvnd.

Fixes #199
  • Loading branch information
jcgay committed Apr 13, 2024
1 parent c351f8c commit 00fc6bb
Showing 1 changed file with 2 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/main/java/fr/jcgay/maven/profiler/ProfilerEventSpy.java
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,9 @@ public class ProfilerEventSpy extends AbstractEventSpy {

public ProfilerEventSpy() {
this.statisticsSupplier = Statistics::new;
this.statistics = statisticsSupplier.get();
this.configurationSupplier = Configuration::read;
this.configuration = configurationSupplier.get();
this.now = Date::new;
}

Expand Down

0 comments on commit 00fc6bb

Please sign in to comment.