From 887e7ad09188ce9d94b953343bdc5a305c49ac2d Mon Sep 17 00:00:00 2001 From: Alex Soto Date: Fri, 26 Feb 2016 17:44:30 +0100 Subject: [PATCH 1/2] adds null protection in case of classes have no package. --- .../utility/steps/maven/ReadMavenPomStep.java | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/src/main/java/org/jenkinsci/plugins/pipeline/utility/steps/maven/ReadMavenPomStep.java b/src/main/java/org/jenkinsci/plugins/pipeline/utility/steps/maven/ReadMavenPomStep.java index e0083427..a76de76b 100644 --- a/src/main/java/org/jenkinsci/plugins/pipeline/utility/steps/maven/ReadMavenPomStep.java +++ b/src/main/java/org/jenkinsci/plugins/pipeline/utility/steps/maven/ReadMavenPomStep.java @@ -153,7 +153,19 @@ public boolean permitsMethod(Method method, Object receiver, Object[] args) { return false; } - return receiver.getClass().getPackage().getName().equals(ORG_APACHE_MAVEN_MODEL) + final Class aClass = receiver.getClass(); + final Package aPackage = aClass.getPackage(); + + if(aPackage == null) { + return false; + } + + final String name = aPackage.getName(); + + if (name == null) { + return false; + } + return name.equals(ORG_APACHE_MAVEN_MODEL) && ( method.getName().startsWith("set") || method.getName().startsWith("get") || method.getName().startsWith("add") From d75679c99fd514f34b1a680526ad4d50edd19785 Mon Sep 17 00:00:00 2001 From: Alex Soto Date: Fri, 26 Feb 2016 18:46:00 +0100 Subject: [PATCH 2/2] adds null protection in case of classes have no package. --- .../utility/steps/maven/ReadMavenPomStep.java | 41 +++++++++++++++---- 1 file changed, 34 insertions(+), 7 deletions(-) diff --git a/src/main/java/org/jenkinsci/plugins/pipeline/utility/steps/maven/ReadMavenPomStep.java b/src/main/java/org/jenkinsci/plugins/pipeline/utility/steps/maven/ReadMavenPomStep.java index a76de76b..2258963d 100644 --- a/src/main/java/org/jenkinsci/plugins/pipeline/utility/steps/maven/ReadMavenPomStep.java +++ b/src/main/java/org/jenkinsci/plugins/pipeline/utility/steps/maven/ReadMavenPomStep.java @@ -161,10 +161,6 @@ public boolean permitsMethod(Method method, Object receiver, Object[] args) { } final String name = aPackage.getName(); - - if (name == null) { - return false; - } return name.equals(ORG_APACHE_MAVEN_MODEL) && ( method.getName().startsWith("set") || method.getName().startsWith("get") @@ -175,7 +171,17 @@ public boolean permitsMethod(Method method, Object receiver, Object[] args) { @Override public boolean permitsConstructor(@Nonnull Constructor constructor, @Nonnull Object[] args) { - return constructor.getDeclaringClass().getPackage().getName().equals(ORG_APACHE_MAVEN_MODEL); + if (constructor == null) { + return false; + } + + final Package aPackage = constructor.getDeclaringClass().getPackage(); + + if (aPackage == null) { + return false; + } + + return aPackage.getName().equals(ORG_APACHE_MAVEN_MODEL); } @Override @@ -185,12 +191,33 @@ public boolean permitsStaticMethod(@Nonnull Method method, @Nonnull Object[] arg @Override public boolean permitsFieldGet(@Nonnull Field field, @Nonnull Object receiver) { - return receiver.getClass().getPackage().getName().equals(ORG_APACHE_MAVEN_MODEL); + + if (receiver == null) { + return false; + } + + + final Package aPackage = receiver.getClass().getPackage(); + if (aPackage == null) { + return false; + } + + return aPackage.getName().equals(ORG_APACHE_MAVEN_MODEL); } @Override public boolean permitsFieldSet(@Nonnull Field field, @Nonnull Object receiver, Object value) { - return receiver.getClass().getPackage().getName().equals(ORG_APACHE_MAVEN_MODEL); + + if (receiver == null) { + return false; + } + + final Package aPackage = receiver.getClass().getPackage(); + if (aPackage == null) { + return false; + } + + return aPackage.getName().equals(ORG_APACHE_MAVEN_MODEL); } @Override