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

NullPointerException for empty search criteria #48

Open
dev2d opened this issue Jul 7, 2021 · 0 comments
Open

NullPointerException for empty search criteria #48

dev2d opened this issue Jul 7, 2021 · 0 comments

Comments

@dev2d
Copy link

dev2d commented Jul 7, 2021

It is mentioned that the annotation SearchSpec can be used in my RestController. I tried the same and while testing a negative scenario I came across a case where I just passed multiple spaces in search criteria like following /resource?search=(resourceId= )

This gave me a NullPointerException as below

java.lang.NullPointerException: null
        at com.sipios.springsearch.QueryVisitorImpl.visitCriteria(QueryVisitorImpl.kt:50)
        at com.sipios.springsearch.QueryVisitorImpl.visitCriteria(QueryVisitorImpl.kt:8)

Looking at the code it appears that the check implemented has following

        val criteria = SearchCriteria(
            key,
            op,
            matchResult!!.groups[1]!!.value, //here is where it breaks
            matchResult.groups[2]!!.value,
            matchResult.groups[3]!!.value
        )

was the use of !! operator intentional? If yes, how are consumers who are directly annotating SearchSpec in their controller methods are advised to handle this? If no, can this be considered a defect and prioritized?

EDIT:

After further testing, following scenario fails with similar error. When calling search without any search criteria like /resource?search=() below exception is thrown.

java.lang.NullPointerException: visit(ctx.query()) must not be null
        at com.sipios.springsearch.QueryVisitorImpl.visitPriorityQuery(QueryVisitorImpl.kt:22)
        at com.sipios.springsearch.QueryVisitorImpl.visitPriorityQuery(QueryVisitorImpl.kt:8)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant