Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorCarsten Pfeiffer2016-01-28 10:47:11 -0500
committerFred Bricon2016-05-03 13:24:27 -0400
commitdfd4dbbe643508f1866a5a14ce755298fcdceb4f (patch)
tree893bb09cd64aa2c1e6acfe01281f7022104aafe2 /org.eclipse.m2e.core
parentc9809b498c511b3fb8bbf1e534cfe1f5b13d2293 (diff)
downloadm2e-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>
Diffstat (limited to 'org.eclipse.m2e.core')
-rw-r--r--org.eclipse.m2e.core/src/org/eclipse/m2e/core/internal/markers/SourceLocationHelper.java58
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);
}
}

Back to the top