Skip to content

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

Closed
@spring-projects-issues

Description

@spring-projects-issues

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

Metadata

Metadata

Assignees

Labels

in: webIssues in web modules (web, webmvc, webflux, websocket)status: backportedAn issue that has been backported to maintenance branchestype: bugA general bug

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions