diff options
| author | Carsten Pfeiffer | 2016-01-28 15:47:11 +0000 |
|---|---|---|
| committer | Fred Bricon | 2016-05-03 17:24:27 +0000 |
| commit | dfd4dbbe643508f1866a5a14ce755298fcdceb4f (patch) | |
| tree | 893bb09cd64aa2c1e6acfe01281f7022104aafe2 | |
| parent | c9809b498c511b3fb8bbf1e534cfe1f5b13d2293 (diff) | |
| download | m2e-core-dfd4dbbe643508f1866a5a14ce755298fcdceb4f.tar.gz m2e-core-dfd4dbbe643508f1866a5a14ce755298fcdceb4f.tar.xz m2e-core-dfd4dbbe643508f1866a5a14ce755298fcdceb4f.zip | |
486732 : Avoid NPE when no source location is available
Bug: #486732
Change-Id: I536a617adc8ef58c24a7c6b9ce72580e801ac2f0
Signed-off-by: Carsten Pfeiffer <carsten.pfeiffer@gebit.de>
| -rw-r--r-- | org.eclipse.m2e.core/src/org/eclipse/m2e/core/internal/markers/SourceLocationHelper.java | 58 |
1 files changed, 36 insertions, 22 deletions
diff --git a/org.eclipse.m2e.core/src/org/eclipse/m2e/core/internal/markers/SourceLocationHelper.java b/org.eclipse.m2e.core/src/org/eclipse/m2e/core/internal/markers/SourceLocationHelper.java index c2b8d4ca..266465f4 100644 --- a/org.eclipse.m2e.core/src/org/eclipse/m2e/core/internal/markers/SourceLocationHelper.java +++ b/org.eclipse.m2e.core/src/org/eclipse/m2e/core/internal/markers/SourceLocationHelper.java @@ -53,12 +53,14 @@ public class SourceLocationHelper { public static SourceLocation findPackagingLocation(MavenProject mavenProject) { InputLocation inputLocation = mavenProject.getModel().getLocation(PACKAGING); if(inputLocation != null) { - return new SourceLocation(inputLocation.getLineNumber(), inputLocation.getColumnNumber() - PACKAGING.length() - - COLUMN_START_OFFSET, inputLocation.getColumnNumber() - COLUMN_END_OFFSET); + return new SourceLocation(inputLocation.getLineNumber(), + inputLocation.getColumnNumber() - PACKAGING.length() - COLUMN_START_OFFSET, + inputLocation.getColumnNumber() - COLUMN_END_OFFSET); } inputLocation = mavenProject.getModel().getLocation(SELF); - return new SourceLocation(inputLocation.getLineNumber(), inputLocation.getColumnNumber() - PROJECT.length() - - COLUMN_START_OFFSET, inputLocation.getColumnNumber() - COLUMN_END_OFFSET); + return new SourceLocation(inputLocation.getLineNumber(), + inputLocation.getColumnNumber() - PROJECT.length() - COLUMN_START_OFFSET, + inputLocation.getColumnNumber() - COLUMN_END_OFFSET); } public static SourceLocation findLocation(Plugin plugin, String attribute) { @@ -98,12 +100,14 @@ public class SourceLocationHelper { // Plugin is specified in the maven lifecycle definition, not explicit in current pom or parent pom inputLocation = mavenProject.getModel().getLocation(PACKAGING); if(inputLocation != null) { - return new SourceLocation(inputLocation.getLineNumber(), inputLocation.getColumnNumber() - PACKAGING.length() - - COLUMN_START_OFFSET, inputLocation.getColumnNumber() - COLUMN_END_OFFSET); + return new SourceLocation(inputLocation.getLineNumber(), + inputLocation.getColumnNumber() - PACKAGING.length() - COLUMN_START_OFFSET, + inputLocation.getColumnNumber() - COLUMN_END_OFFSET); } inputLocation = mavenProject.getModel().getLocation(SELF); - return new SourceLocation(inputLocation.getLineNumber(), inputLocation.getColumnNumber() - PROJECT.length() - - COLUMN_START_OFFSET, inputLocation.getColumnNumber() - COLUMN_END_OFFSET); + return new SourceLocation(inputLocation.getLineNumber(), + inputLocation.getColumnNumber() - PROJECT.length() - COLUMN_START_OFFSET, + inputLocation.getColumnNumber() - COLUMN_END_OFFSET); } String elementName; @@ -118,17 +122,24 @@ public class SourceLocationHelper { File pomFile = mavenProject.getFile(); if(pomFile.getAbsolutePath().equals(inputLocation.getSource().getLocation())) { // Plugin/execution is specified in current pom - return new SourceLocation(inputLocation.getLineNumber(), inputLocation.getColumnNumber() - elementName.length() - - COLUMN_START_OFFSET, inputLocation.getColumnNumber() - COLUMN_END_OFFSET); + return new SourceLocation(inputLocation.getLineNumber(), + inputLocation.getColumnNumber() - elementName.length() - COLUMN_START_OFFSET, + inputLocation.getColumnNumber() - COLUMN_END_OFFSET); } // Plugin/execution is specified in some parent pom - SourceLocation causeLocation = new SourceLocation(inputLocation.getSource().getLocation(), inputLocation - .getSource().getModelId(), inputLocation.getLineNumber(), inputLocation.getColumnNumber() - - elementName.length() - COLUMN_START_OFFSET, inputLocation.getColumnNumber() - COLUMN_END_OFFSET); + SourceLocation causeLocation = new SourceLocation(inputLocation.getSource().getLocation(), + inputLocation.getSource().getModelId(), inputLocation.getLineNumber(), + inputLocation.getColumnNumber() - elementName.length() - COLUMN_START_OFFSET, + inputLocation.getColumnNumber() - COLUMN_END_OFFSET); inputLocation = mavenProject.getModel().getParent().getLocation(SELF); - return new SourceLocation(inputLocation.getLineNumber(), inputLocation.getColumnNumber() - PARENT.length() - - COLUMN_START_OFFSET, inputLocation.getColumnNumber() - COLUMN_END_OFFSET, causeLocation); + if(inputLocation == null) { + // parent location cannot be determined for participant-added parents + return new SourceLocation(1, 1, 1, causeLocation); + } + return new SourceLocation(inputLocation.getLineNumber(), + inputLocation.getColumnNumber() - PARENT.length() - COLUMN_START_OFFSET, + inputLocation.getColumnNumber() - COLUMN_END_OFFSET, causeLocation); } private static InputLocation findExecutionLocation(Plugin plugin, String executionId) { @@ -232,16 +243,19 @@ public class SourceLocationHelper { File pomFile = mavenProject.getFile(); if(pomFile.getAbsolutePath().equals(inputLocation.getSource().getLocation())) { // Dependency is specified in current pom - return new SourceLocation(inputLocation.getLineNumber(), inputLocation.getColumnNumber() - DEPENDENCY.length() - - COLUMN_START_OFFSET, inputLocation.getColumnNumber() - COLUMN_END_OFFSET); + return new SourceLocation(inputLocation.getLineNumber(), + inputLocation.getColumnNumber() - DEPENDENCY.length() - COLUMN_START_OFFSET, + inputLocation.getColumnNumber() - COLUMN_END_OFFSET); } // Plugin/execution is specified in some parent pom - SourceLocation causeLocation = new SourceLocation(inputLocation.getSource().getLocation(), inputLocation - .getSource().getModelId(), inputLocation.getLineNumber(), inputLocation.getColumnNumber() - DEPENDENCY.length() - - COLUMN_START_OFFSET, inputLocation.getColumnNumber() - COLUMN_END_OFFSET); + SourceLocation causeLocation = new SourceLocation(inputLocation.getSource().getLocation(), + inputLocation.getSource().getModelId(), inputLocation.getLineNumber(), + inputLocation.getColumnNumber() - DEPENDENCY.length() - COLUMN_START_OFFSET, + inputLocation.getColumnNumber() - COLUMN_END_OFFSET); inputLocation = mavenProject.getModel().getParent().getLocation(SELF); - return new SourceLocation(inputLocation.getLineNumber(), inputLocation.getColumnNumber() - PARENT.length() - - COLUMN_START_OFFSET, inputLocation.getColumnNumber() - COLUMN_END_OFFSET, causeLocation); + return new SourceLocation(inputLocation.getLineNumber(), + inputLocation.getColumnNumber() - PARENT.length() - COLUMN_START_OFFSET, + inputLocation.getColumnNumber() - COLUMN_END_OFFSET, causeLocation); } } |
