Skip to content

ContentLength for InputStreamResource subclasses #24522

Closed
@admoca60

Description

@admoca60

Affects: spring-web-5.2.3


Dear all

I could see that the treatment of subclasses of InputStreamResource is not really good in some converters or codecs for Resource instances. Exactly, I could see that there are some classes that they don't take into account that InputStreamResource could have subclasses (as my case). These examples classes are org.springframework.http.codec.ResourceHttpMessageWriter (method lengthOf(Resource) line if (InputStreamResource.class != resource.getClass()) {) or org.springframework.http.converter.ResourceHttpMessageConverter (method getContentLength and line if (InputStreamResource.class == resource.getClass()) {

I could see another opened issue about it (#20990) and in it, you talk about the possibility to override the contentLength method for all subclasses, but in my opinion, this is a workaround because the right fix should be changing the above lines for something like this: if (!(resource instanceof InputStreamResource)) {. In that way, all of subclasses of InputStreamResource will have the same treatment, because by definition, all of these subclasses are based on an opened InputStream so the treatment should be the same for all cases.

I'm open to collaborate and send you a PR to fix both cases.

I await your reply!

Metadata

Metadata

Assignees

Labels

status: invalidAn issue that we don't feel is valid

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions