Skip to content

NullPointerException while building error message in InvocableHandlerMethod [SPR-13917] #18491

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

Closed
spring-projects-issues opened this issue Feb 4, 2016 · 1 comment
Assignees
Labels
in: web Issues in web modules (web, webmvc, webflux, websocket) status: backported An issue that has been backported to maintenance branches type: bug A general bug
Milestone

Comments

@spring-projects-issues
Copy link
Collaborator

lionel b opened SPR-13917 and commented

Hello,

I have a problem when I try to call my resource,
Here is my signature :

@RestController public class AccountOperationResource {
//...
@RequestMapping (method = RequestMethod.POST, path = "/account/{iban}/deposit")
    public Response<AccountHistoryOperation> deposit (
                                    @PathVariable final String iban, 
                                    @RequestBodyPath ("amount") final double amount) 
    throws BankAccountException {
        //RequestBodyPath is an annotation that is handled by an arg resolver
    }
//...
}

As you see, the second argument ("amount") is a primitive type.

  1. Using the controller, the org.springframework.web.method.support.InvocableHandlerMethod tries to get my method and to invoke it with some arguments parsed from my argresolver.

  2. If I try to pass nothing for the "amount" value, the null value will be selected, and therefore the InvocableHandlerMethod will invoke the method with a null amount, which is forbidden by the fact that the double class is primitive. That is okay and logical.

  3. Then I get an IllegalArgumentException from the java.lang.reflect API. The message of this exception is null. The InvocableHandlerMethod.getInvocationErrorMessage is called. It is fine.

4)This method passes this null String to the InvocableHandlerMethod.getDetailedErrorMessage method, ok.

5)Then this method calls new "StringBuilder(message)", which is resolved to do "new StringBuilder(null)"

=> I expect the null message to be ignored
... But instead, I get a NullPointerException

Can you help me ?

Regards,
Lionel.

Source code of the InvocableHandlerMethod class in the spring web framework :
https://github.com/spring-projects/spring-framework/blob/master/spring-web/src/main/java/org/springframework/web/method/support/InvocableHandlerMethod.java


Affects: 3.2.16, 4.2.1

Backported to: 3.2.17

@spring-projects-issues
Copy link
Collaborator Author

Rossen Stoyanchev commented

This should be fixed now. Thanks.

@spring-projects-issues spring-projects-issues added type: bug A general bug status: backported An issue that has been backported to maintenance branches in: web Issues in web modules (web, webmvc, webflux, websocket) labels Jan 11, 2019
@spring-projects-issues spring-projects-issues added this to the 4.2.5 milestone Jan 11, 2019
bclozel added a commit that referenced this issue Sep 9, 2022
This commit improves the fix for gh-18491 for Java 18 as in this case
the exception message might not be null.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
in: web Issues in web modules (web, webmvc, webflux, websocket) status: backported An issue that has been backported to maintenance branches type: bug A general bug
Projects
None yet
Development

No branches or pull requests

2 participants