-
Notifications
You must be signed in to change notification settings - Fork 38.7k
Closed
Labels
in: webIssues in web modules (web, webmvc, webflux, websocket)Issues in web modules (web, webmvc, webflux, websocket)type: regressionA bug that is also a regressionA bug that is also a regression
Milestone
Description
The following example works with Spring Framework 6.0, but not with 6.1:
class MyForm {
private String name;
private MultipartFile file;
MyForm(String name, @Nullable MultipartFile file) {
this.name = name;
this.file = file;
}
// ...
}
@Controller
public class FileUploadController {
@PostMapping("/form")
public String handleFormUpload(MyForm form, BindingResult errors) {
if (!form.getFile().isEmpty()) {
byte[] bytes = form.getFile().getBytes();
// store the bytes somewhere
return "redirect:uploadSuccess";
}
return "redirect:uploadFailure";
}
}
The above code throws the exception java.lang.IllegalStateException: No primary or single unique constructor found for interface org.springframework.web.multipart.MultipartFile
if the file is not specified in the request.
The method DataBinder#shouldCreateObject(MethodParameter)
was introduced with #31488. I think this method should also check whether the parameter is optional or not by calling MethodParameter#isOptional()
.
Metadata
Metadata
Assignees
Labels
in: webIssues in web modules (web, webmvc, webflux, websocket)Issues in web modules (web, webmvc, webflux, websocket)type: regressionA bug that is also a regressionA bug that is also a regression