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

[FR] Some way to have @RequestParam(required = false) be interpreted as @Nullable #751

Open
chrismgrayftsinc opened this issue Mar 21, 2023 · 3 comments

Comments

@chrismgrayftsinc
Copy link

I just added NullAway 0.10.10 to the build process of a collection of microservices that use Spring Boot and Feign to communicate. The interfaces that the microservices use are annotated to indicate whether the function parameters are put in the URL path , as query parameters, or as a request body. Most query parameters are optional and should be treated as nullable if they have the required = false argument to the @RequestParam annotation. Unfortunately, required = true is the default and there are many other arguments that the annotation takes.

In my case, it seems like treating the @RequestParam annotation as equivalent to @Nullable makes some sense because we use required = false 99% of the time, but I can imagine other times where the extra accuracy would be helpful.

@msridhar
Copy link
Collaborator

Hi there, if I understand correctly, you would like to treat @RequestParam(required = false) as equivalent to @Nullable? We do have support for custom nullability annotations but that just matches on name, not on the parameters passed. So I'm not too sure we have an out-of-the-box solution that will work for your use case. If you use required = false 99% of the time, maybe it would be best to @RequestParam as equivalent to @Nullable using the aformentioned option, and then deal with the remaining false positives using an initialization suppression?

@lazaroclapp in case you have other ideas here

@chrismgrayftsinc
Copy link
Author

Thanks. I'm requesting the feature that allows for matching on parameters. I have used the custom nullability annotations that you mentioned, which is probably good enough for my personal use case but I can imagine it not being sufficient for others. I definitely understand that matching on parameters will be difficult and this is very low priority for me personally. This issue exists mostly to document that the need may be out there.

@msridhar
Copy link
Collaborator

Thanks! Matching on parameters may not be difficult but it would have to be done with care to ensure no negative impact on NullAway performance when it is not required. If someone really needs this we are open to discussion / evaluating a PR.

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

2 participants