Fix NPE when Model.getLocation() returns null#2139
Fix NPE when Model.getLocation() returns null#2139EricBlanquer wants to merge 1 commit intoeclipse-m2e:mainfrom
Conversation
5e64f63 to
cb0329f
Compare
We already have some tests that use extensions (mostly Tycho), so would you mind to try adding such test for the Beside that you must sign the Eclipse ECA so we can accept your contribution. |
cb0329f to
04ff530
Compare
Maven core extensions such as maven-git-versioning-extension can
modify the Maven model at runtime without preserving InputLocation
metadata. This causes Model.getLocation("") to return null, leading
to NullPointerException in AnnotationMappingMetadataSource and
SourceLocationHelper.
Add null checks for InputLocation and InputSource in all code paths
that dereference Model.getLocation() results.
Fixes eclipse-m2e#1310
04ff530 to
e60e738
Compare
|
@laeubi I've added a test ( Proof that the fix prevents the NPEWithout the fix, when
projectId = project.getModel().getLocation(SELF).getSource().getModelId();
// ↑ returns null → NPE on .getSource()
InputSource source = project.getModel().getLocation(SELF).getSource();
// ↑ returns null → NPE
if(pomFile.getAbsolutePath().equals(inputLocation.getSource().getLocation()))
// ↑ getSource() is null → NPEWith the fix, null checks and graceful fallbacks prevent the crash: InputLocation selfLocation = project.getModel().getLocation(SELF);
if(selfLocation != null && selfLocation.getSource() != null) {
projectId = selfLocation.getSource().getModelId();
} else {
projectId = project.getGroupId() + ":" + project.getArtifactId() + ":" + project.getVersion();
}All Also, my ECA is now valid and up to date. |
Summary
Maven core extensions such as
maven-git-versioning-extensionmodify the Maven model at runtime without preservingInputLocationmetadata. This causesModel.getLocation("")to returnnull, leading toNullPointerExceptionduring project import and update.Stack trace:
Changes
AnnotationMappingMetadataSource: add null checks in constructor andparsePIs()forModel.getLocation()andInputLocation.getSource()SourceLocationHelper: add null checks ingetSourceLocation(),findLocation()andgetMavenDependency()for allgetLocation(SELF)dereferencesReproducer
Use any Maven core extension declared in
.mvn/extensions.xml(e.g.maven-git-versioning-extension) and try to import or update a Maven project in Eclipse.Fixes #1310