Skip to content

Jackson encoder releases resources in wrong order #30493

Closed
@Kiskae

Description

@Kiskae

Affects: 5.2.10+, 5.3.0+


Ran into the following issue while using AbstractJackson2Encoder and the jackson csv serializer:

java.lang.NullPointerException: null
	at com.fasterxml.jackson.core.util.ByteArrayBuilder.write(ByteArrayBuilder.java:245) ~[jackson-core-2.13.5.jar:2.13.5]
	at com.fasterxml.jackson.dataformat.csv.impl.UTF8Writer.close(UTF8Writer.java:62) ~[jackson-dataformat-csv-2.13.5.jar:2.13.5]
	at com.fasterxml.jackson.dataformat.csv.impl.CsvEncoder.close(CsvEncoder.java:994) ~[jackson-dataformat-csv-2.13.5.jar:2.13.5]
	at com.fasterxml.jackson.dataformat.csv.CsvGenerator.close(CsvGenerator.java:503) ~[jackson-dataformat-csv-2.13.5.jar:2.13.5]
	at org.springframework.http.codec.json.AbstractJackson2Encoder.lambda$encode$2(AbstractJackson2Encoder.java:173) ~[spring-web-5.3.27.jar:5.3.27]

The problem is the optimization in commit 7bee3d1 after calling byteBuilder.release() it should not be used, but if generator has its own buffers then generator.close() can trigger a flush to the byteBuilder.
It should be fixable by reordering the operations so byteBuilder is released last.

This probably also means the generator needs to be flushed and checked whether there is a trailing DataBuffer that still needs to be sent before terminating the stream. (concatWith(if generator.flush() != [], DataBuffer))

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