Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

adds null protection in case of classes have no package. #12

Merged
merged 2 commits into from
Feb 29, 2016
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,15 @@ 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();
return name.equals(ORG_APACHE_MAVEN_MODEL)
&& ( method.getName().startsWith("set")
|| method.getName().startsWith("get")
|| method.getName().startsWith("add")
Expand All @@ -163,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) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🐜 obviously not possible, given the annotation.

return false;
}

final Package aPackage = constructor.getDeclaringClass().getPackage();

if (aPackage == null) {
return false;
}

return aPackage.getName().equals(ORG_APACHE_MAVEN_MODEL);
}

@Override
Expand All @@ -173,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) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🐜 ditto

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But nonnull is informative, we could receive a null right?
El 26 feb. 2016 6:51 p. m., "Jesse Glick" notifications@github.com
escribió:

In
src/main/java/org/jenkinsci/plugins/pipeline/utility/steps/maven/ReadMavenPomStep.java
#12 (comment)
:

@@ -173,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) {
    

[image: 🐜] ditto


Reply to this email directly or view it on GitHub
https://github.com/jenkinsci/pipeline-utility-steps-plugin/pull/12/files#r54276812
.

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) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🐜 ditto

return false;
}

final Package aPackage = receiver.getClass().getPackage();
if (aPackage == null) {
return false;
}

return aPackage.getName().equals(ORG_APACHE_MAVEN_MODEL);
}

@Override
Expand Down