| Summary: | NPE if VersionRange is missing in PluginExecutionFilter | ||||||
|---|---|---|---|---|---|---|---|
| Product: | z_Archived | Reporter: | Jochen Wiedmann <jochen.wiedmann> | ||||
| Component: | m2e | Assignee: | Project Inbox <m2e.core-inbox> | ||||
| Status: | RESOLVED FIXED | QA Contact: | |||||
| Severity: | normal | ||||||
| Priority: | P3 | CC: | adr_gonzalez, antonio.petrelli, bentatham, d_a_carver, fukanchik, igor, jnbu, Knut.Friedhelm, Sebastian.Leske, sslavic | ||||
| Version: | unspecified | ||||||
| Target Milestone: | --- | ||||||
| Hardware: | PC | ||||||
| OS: | Windows 7 | ||||||
| Whiteboard: | |||||||
| Attachments: |
|
||||||
*** Bug 350159 has been marked as a duplicate of this bug. *** *** Bug 350444 has been marked as a duplicate of this bug. *** I'm experiencing similar behavior (see [1]) when action is not defined. Should I report this as separate ticket?
[1] stacktrace from eclipse workspace log file
!ENTRY org.eclipse.core.resources 4 75 2011-08-17 08:57:02.623
!MESSAGE Errors occurred during the build.
!SUBENTRY 1 org.eclipse.m2e.core 4 75 2011-08-17 08:57:02.623
!MESSAGE Errors running builder 'Maven Project Builder' on project 'foo-bar'.
!STACK 0
java.lang.NullPointerException
at org.eclipse.m2e.core.internal.lifecyclemapping.model.PluginExecutionMetadata.getAction(PluginExecutionMetadata.java:81)
at org.eclipse.m2e.core.internal.lifecyclemapping.LifecycleMappingFactory.isPrimaryMapping(LifecycleMappingFactory.java:968)
at org.eclipse.m2e.core.internal.lifecyclemapping.LifecycleMappingFactory.calculateEffectiveLifecycleMappingMetadata(LifecycleMappingFactory.java:296)
at org.eclipse.m2e.core.internal.lifecyclemapping.LifecycleMappingFactory.calculateEffectiveLifecycleMappingMetadata(LifecycleMappingFactory.java:208)
at org.eclipse.m2e.core.internal.lifecyclemapping.LifecycleMappingFactory.calculateLifecycleMapping(LifecycleMappingFactory.java:159)
at org.eclipse.m2e.core.internal.project.registry.ProjectRegistryManager.setupLifecycleMapping(ProjectRegistryManager.java:526)
at org.eclipse.m2e.core.internal.project.registry.ProjectRegistryManager.refresh(ProjectRegistryManager.java:445)
at org.eclipse.m2e.core.internal.project.registry.ProjectRegistryManager.refresh(ProjectRegistryManager.java:327)
at org.eclipse.m2e.core.internal.project.registry.ProjectRegistryManager.refresh(ProjectRegistryManager.java:278)
at org.eclipse.m2e.core.internal.project.registry.MavenProjectManager.refresh(MavenProjectManager.java:58)
at org.eclipse.m2e.core.internal.builder.MavenBuilder.build(MavenBuilder.java:120)
at org.eclipse.core.internal.events.BuildManager$2.run(BuildManager.java:728)
at org.eclipse.core.runtime.SafeRunner.run(SafeRunner.java:42)
at org.eclipse.core.internal.events.BuildManager.basicBuild(BuildManager.java:199)
at org.eclipse.core.internal.events.BuildManager.basicBuild(BuildManager.java:239)
at org.eclipse.core.internal.events.BuildManager$1.run(BuildManager.java:292)
at org.eclipse.core.runtime.SafeRunner.run(SafeRunner.java:42)
at org.eclipse.core.internal.events.BuildManager.basicBuild(BuildManager.java:295)
at org.eclipse.core.internal.events.BuildManager.basicBuildLoop(BuildManager.java:351)
at org.eclipse.core.internal.events.BuildManager.build(BuildManager.java:374)
at org.eclipse.core.internal.events.AutoBuildJob.doBuild(AutoBuildJob.java:143)
at org.eclipse.core.internal.events.AutoBuildJob.run(AutoBuildJob.java:241)
at org.eclipse.core.internal.jobs.Worker.run(Worker.java:54)
*** Bug 351090 has been marked as a duplicate of this bug. *** closing old/stale bugreports With the current version from the Eclipse Git repo for m2e (commit 608ed13, 2014-02-14), the bug still occurs. The problem seems to be that m2e expects that for every PluginExecutionFilter entry the fields groupId, artifactId and versionRange are always available. This is never checked, so omitting one of them in the lifecycle mapping XML file (either in the POM, or in lifecycle-mapping-metadata.xml) will cause a NPE. Created attachment 240254 [details] Check required fields for PluginExecutionFilter to avoid NPE. The attached patch m2e-check-fields.diff adds a check for the required fields (groupId, artifactId, versionRange, goals), so omitting them produces a helpful (hopefully) error message. For example, if versionRange is omitted, you get: java.lang.IllegalArgumentException: Missing parameter for pluginExecutionFilter. groupId, artifactId, versionRange and goals must be specified, but found: groupId = 'org.apache.maven.plugins' artifactId = 'maven-compiler-plugin' versionRange = 'null' goals = '[compiler:compile]' Notes: 1) Since the code just throws an exception, the error shows up in the Eclipse error log, and not as a build problem. Reporting it properly as a build problem could be the next step :-). 2) Ideally, the required fields would be checked directly when parsing the XML via Modello. Unfortunately, Modello apparently cannot do this ( "MODELLO-44 Modello XPP3 Reader does not honor <required>true</required> in model.", https://jira.codehaus.org/browse/MODELLO-44 ). I hope this patch can be applied to fix this rather annoying bug. If there is a problem with the patch, I'd be grateful for feedback. As explained in [1], you need to use gerrit to submit m2e patches. We do not accept or review patches submitted via bugzilla. Your analysis of the problem is generally correct, however the patch (judging purely by comment #7) is not sufficient. The correct fix to this problem must create error marker on the most relevant pom.xml element -- either lifecycle mapping itself, or lifecycle mapping reference or parent pom. I've reopened this bugzilla so hopefully you can contribute proper fix for this old bug. [1] https://wiki.eclipse.org/M2E_Development_Environment (In reply to Igor Fedorenko from comment #8) > As explained in [1], you need to use gerrit to submit m2e patches. We do not > accept or review patches submitted via bugzilla. I have re-submitted the patch via Gerrit. Change: https://git.eclipse.org/r/22679 About your comments: > Your analysis of the problem is generally correct, however the patch > (judging purely by comment #7) is not sufficient. The correct fix to this > problem must create error marker on the most relevant pom.xml element -- > either lifecycle mapping itself, or lifecycle mapping reference or parent > pom. I agree that a fix creating error markers would be better. However, it would also be significantly more work, which I unfortunately cannot put in right now (especially as I have virtually no knowledge of either Eclipse plugin development or the internals of m2e - I would not even know how to create error markers). IMHO, this patch already significantly improves the situation: Instead of a NPE with zero indication what the problem is, you get a proper error message. I created the patch because I spent half a day finding out why m2e was throwing a NPE (not knowing whether it was a problem with my config, or with another plugin, or with my Java version or whatever...). If I had received the error message from the patch, I would have saved these hours. So my proposal would be: Include this patch (or some equivalent) now to solve the immediate problem (NPE without any indication what is wrong). Then I will gladly open a new feature request ticket to produce a proper error marker (or even have some kind of auto-fix, or make the fields optional). Ok. Fair enough. Please provide a unit test that verifies your fix (in other words, fails without the fix, passes with it) and I'll merge your changes. (In reply to Igor Fedorenko from comment #10) > Ok. Fair enough. Please provide a unit test that verifies your fix (in other > words, fails without the fix, passes with it) and I'll merge your changes. Yes, sounds fair :-). One question: Where do I find the unit tests? There aren't any in the m2e-core repository. I found this repo: https://github.com/tesla/m2e-core-tests . Is that the right one? And if yes, how do I submit my unit test? Gerrit does not seem to work - I could not find a suitable project in Gerrit. So I'm a bit confused about the repo structure... Sorry, missed your question. Yes, https://github.com/tesla/m2e-core-tests is the right place (eclipse.org legal process is just too cumbersome, so we decided to keep the tests at github). Open a pull request with your test, link it here and I'll take care of the rest. Pull request opened: https://github.com/tesla/m2e-core-tests/pull/6 Hope everything's ok like this. BTW, I just wanted to propose you update the docs to mention the test repo, but I see you already updated the development guide at http://wiki.eclipse.org/M2E_Development_Environment . Good idea! Merged to master http://git.eclipse.org/c/m2e/m2e-core.git/commit/?id=98028eb929dd76ddb00f5500dab5d9506b523ca2 https://github.com/tesla/m2e-core-tests/commit/50aa9ff057c8a82050cb89afee0503bdf989d7e0 |
If a lifecycle mappings pluginexecutionfilter doesn't contain a VersionRange, then an NPE is thrown. I can think of no reason, why a VersionRange should be required. At least, an error message should be shown instead of an NPE. Example configuration: <plugin> <groupId>org.eclipse.m2e</groupId> <artifactId>lifecycle-mapping</artifactId> <version>1.0.0</version> <configuration> <lifecycleMappingMetadata> <pluginExecutions> <pluginExecution> <pluginExecutionFilter> <groupId>org.codehaus.mojo</groupId> <artifactId>hibernate3-maven-plugin</artifactId> <goals><goal>hbm2ddl</goal></goals> </pluginExecutionFilter> <action> <execute/> </action> </pluginExecution> </pluginExecutions> </lifecycleMappingMetadata> </configuration> </plugin> Stack trace: java.lang.NullPointerException at org.eclipse.m2e.core.internal.lifecyclemapping.model.PluginExecutionFilter.match(PluginExecutionFilter.java:304) at org.eclipse.m2e.core.internal.lifecyclemapping.SimpleMappingMetadataSource.getPluginExecutionMetadata(SimpleMappingMetadataSource.java:71) at org.eclipse.m2e.core.internal.lifecyclemapping.LifecycleMappingFactory.calculateEffectiveLifecycleMappingMetadata(LifecycleMappingFactory.java:294) at org.eclipse.m2e.core.internal.lifecyclemapping.LifecycleMappingFactory.calculateEffectiveLifecycleMappingMetadata(LifecycleMappingFactory.java:208) at org.eclipse.m2e.core.internal.lifecyclemapping.LifecycleMappingFactory.calculateLifecycleMapping(LifecycleMappingFactory.java:159) at org.eclipse.m2e.core.internal.project.registry.ProjectRegistryManager.setupLifecycleMapping(ProjectRegistryManager.java:526) at org.eclipse.m2e.core.internal.project.registry.ProjectRegistryManager.refresh(ProjectRegistryManager.java:445) at org.eclipse.m2e.core.internal.project.registry.ProjectRegistryManager.refresh(ProjectRegistryManager.java:327) at org.eclipse.m2e.core.internal.project.registry.ProjectRegistryManager.refresh(ProjectRegistryManager.java:278) at org.eclipse.m2e.core.internal.project.registry.MavenProjectManager.refresh(MavenProjectManager.java:58) at org.eclipse.m2e.core.internal.builder.MavenBuilder.build(MavenBuilder.java:120) at org.eclipse.core.internal.events.BuildManager$2.run(BuildManager.java:728)