-
Notifications
You must be signed in to change notification settings - Fork 164
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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") | ||
|
@@ -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) { | ||
return false; | ||
} | ||
|
||
final Package aPackage = constructor.getDeclaringClass().getPackage(); | ||
|
||
if (aPackage == null) { | ||
return false; | ||
} | ||
|
||
return aPackage.getName().equals(ORG_APACHE_MAVEN_MODEL); | ||
} | ||
|
||
@Override | ||
|
@@ -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) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🐜 ditto There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. But nonnull is informative, we could receive a null right?
|
||
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) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 | ||
|
There was a problem hiding this comment.
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.