Skip to content

MissingPathVariableException produces wrong status code in ProblemDetail #35829

@derklaro

Description

@derklaro

The org.springframework.web.bind.MissingPathVariableException is intended to return a 400 status code in case the value is missing after conversion. This is indicated by the getStatusCode() method:

	@Override
	public HttpStatusCode getStatusCode() {
		return (isMissingAfterConversion() ? HttpStatus.BAD_REQUEST : HttpStatus.INTERNAL_SERVER_ERROR);
	}

However, when used in combination with a ProblemDetail, the status code set in the problem detail will always be 500. This is caused by the fact that the ProblemDetail instance is initialized during construction of ServletRequestBindingException before the missingAfterConversion field is initialized in MissingRequestValueException, resulting in the invocation of getStatusCode() (in ServletRequestBindingException) to always return HttpStatus.INTERNAL_SERVER_ERROR.

The http response code will be 400 as expected.

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