Skip to content

Commit 57646a0

Browse files
committed
Refine *HttpMessageConverter#getContentLength null safety
Closes gh-32332
1 parent 380f5d5 commit 57646a0

File tree

2 files changed

+4
-2
lines changed

2 files changed

+4
-2
lines changed

spring-web/src/main/java/org/springframework/http/converter/ResourceHttpMessageConverter.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2022 the original author or authors.
2+
* Copyright 2002-2024 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -112,6 +112,7 @@ protected MediaType getDefaultContentType(Resource resource) {
112112
}
113113

114114
@Override
115+
@Nullable
115116
protected Long getContentLength(Resource resource, @Nullable MediaType contentType) throws IOException {
116117
// Don't try to determine contentLength on InputStreamResource - cannot be read afterwards...
117118
// Note: custom InputStreamResource subclasses could provide a pre-calculated content length!

spring-web/src/main/java/org/springframework/http/converter/json/AbstractJackson2HttpMessageConverter.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2022 the original author or authors.
2+
* Copyright 2002-2024 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -519,6 +519,7 @@ protected MediaType getDefaultContentType(Object object) throws IOException {
519519
}
520520

521521
@Override
522+
@Nullable
522523
protected Long getContentLength(Object object, @Nullable MediaType contentType) throws IOException {
523524
if (object instanceof MappingJacksonValue) {
524525
object = ((MappingJacksonValue) object).getValue();

0 commit comments

Comments
 (0)