Fix NPE in ResourceHttpMessageConverter
ResourceHttpMessageConverter tries to use the filename to determine the media type, but for Resource implementations such as ByteArrayResource it is null, which causes NullPointerException. The fix checks whether getFilename returns null before attempting to determine the media type by it. Issue: SPR-10848
This commit is contained in:
committed by
Rossen Stoyanchev
parent
a455217743
commit
d66206704e
@@ -138,6 +138,9 @@ public class ResourceHttpMessageConverter extends AbstractHttpMessageConverter<R
|
||||
}
|
||||
|
||||
public static MediaType getMediaType(Resource resource) {
|
||||
if(resource.getFilename() == null) {
|
||||
return null;
|
||||
}
|
||||
String mediaType = fileTypeMap.getContentType(resource.getFilename());
|
||||
return (StringUtils.hasText(mediaType) ? MediaType.parseMediaType(mediaType) : null);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user