[
https://issues.apache.org/jira/browse/USERGRID-22?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13926136#comment-13926136
]
Malaka Mahanama commented on USERGRID-22:
-----------------------------------------
Welcome Rod,
I am looking at a few other bugs as well. This looks like a good one to start
with to contribute.
Thought of firing up the fixes from the community and getting the review from
commiters done through the devlist to get things into rhythm.
Here goes:
If the resource name is invalid we get the service_not_found, this is because
the query ‘Identifiers’ in this case are added but are not valid ones.
However if the url has the %20 inbetween like in the example, then the query
identifier becomes null. Later methods are being invoked on these null
identifiers that cause the null pointer.
The fix I suggest is a generic one, we do a check if the identifier is null and
handle the output accordingly in 3 places. This could stop this error from
happening for other reasons similar to %20.
1)Query.java - containsNameOrEmailIdentifiersOnly()
public boolean containsNameOrEmailIdentifiersOnly() {
if ( hasQueryPredicates() ) {
return false;
}
if ( ( identifiers == null ) || identifiers.isEmpty() ) {
return false;
}
for ( Identifier identifier : identifiers ) {
//this IF check was added as part of stopping the issue, without it
identifier.isEmail() below would cause a null pointer.
if (identifier == null){
return false;
}
if ( !identifier.isEmail() && !identifier.isName() ) {
return false;
}
}
return true;
}
2) Query.java - containsUuidIdentifiersOnly()
boolean containsUuidIdentifiersOnly() {
if ( hasQueryPredicates() ) {
return false;
}
if ( ( identifiers == null ) || identifiers.isEmpty() ) {
return false;
}
for ( Identifier identifier : identifiers ) {
//this IF check was added as part of stopping the issue, without it
identifier.isUUID() below would cause a null pointer.
if (identifier == null){
return true;
}
if ( !identifier.isUUID() ) {
return false;
}
}
return true;
}"
3)Query.java - getSingleUuidIdentifier()
" @JsonIgnore
public UUID getSingleUuidIdentifier() {
if ( !containsSingleUuidIdentifier() ) {
return null;
}
//this IF check was added as part of stopping the issue, without it
'identifiers.get( 0 ).getUUID()' below would cause a null pointer.
if(identifiers.get( 0 )==null){
return null;
}
return ( identifiers.get( 0 ).getUUID() );
}
The above 3 places were changed as part of the fix. I think these are basic
checks and risk of regression is very low. Depending on the review comments I
will provide the pull request.
Regards,
Malaka
(Virtusa ~ Sri-Lanka)
> Null pointer error returned when non-existant property name with spaces used
> ----------------------------------------------------------------------------
>
> Key: USERGRID-22
> URL: https://issues.apache.org/jira/browse/USERGRID-22
> Project: Usergrid
> Issue Type: Bug
> Components: Stack
> Reporter: Rod Simpson
> Assignee: Malaka Mahanama
>
> "if I try to get a resource by name that doesn't exist
> https://api.usergrid.com/mdobs/sandbox/books/Scooter
> I get a service_resource_not_found
> but when I throw spaces into the url
> https://api.usergrid.com/mdobs/sandbox/books/Scooter%20guide
> I get a null_pointer error instead"
--
This message was sent by Atlassian JIRA
(v6.2#6252)