jcgay / maven-profiler

Log Maven mojos execution time
MIT License
113 stars 20 forks source link

Prevent NPE when extension is initiated after another one #207

Open jcgay opened 6 months ago

jcgay commented 6 months ago

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

sonarcloud[bot] commented 6 months ago

Quality Gate Passed Quality Gate passed

Issues
0 New issues
0 Accepted issues

Measures
0 Security Hotspots
0.0% Coverage on New Code
0.0% Duplication on New Code

See analysis details on SonarCloud