mirror of
https://github.com/spring-projects/spring-framework
synced 2026-06-08 17:33:33 +00:00
Release DataBuffer in AbstractCharSequenceDecoder
if String creation fails See gh-35625 Signed-off-by: Marius Lichtblau <marius@lichtblau.io>
This commit is contained in:
committed by
rstoyanchev
parent
141df5291d
commit
ba2bb08589
+12
-8
@@ -175,14 +175,18 @@ public abstract class AbstractCharSequenceDecoder<T extends CharSequence> extend
|
||||
public final T decode(DataBuffer dataBuffer, ResolvableType elementType,
|
||||
@Nullable MimeType mimeType, @Nullable Map<String, Object> hints) {
|
||||
|
||||
Charset charset = getCharset(mimeType);
|
||||
T value = decodeInternal(dataBuffer, charset);
|
||||
DataBufferUtils.release(dataBuffer);
|
||||
LogFormatUtils.traceDebug(logger, traceOn -> {
|
||||
String formatted = LogFormatUtils.formatValue(value, !traceOn);
|
||||
return Hints.getLogPrefix(hints) + "Decoded " + formatted;
|
||||
});
|
||||
return value;
|
||||
try {
|
||||
Charset charset = getCharset(mimeType);
|
||||
T value = decodeInternal(dataBuffer, charset);
|
||||
LogFormatUtils.traceDebug(logger, traceOn -> {
|
||||
String formatted = LogFormatUtils.formatValue(value, !traceOn);
|
||||
return Hints.getLogPrefix(hints) + "Decoded " + formatted;
|
||||
});
|
||||
return value;
|
||||
}
|
||||
finally {
|
||||
DataBufferUtils.release(dataBuffer);
|
||||
}
|
||||
}
|
||||
|
||||
private Charset getCharset(@Nullable MimeType mimeType) {
|
||||
|
||||
+4
@@ -35,4 +35,8 @@ public class DataBufferLimitException extends IllegalStateException {
|
||||
super(message);
|
||||
}
|
||||
|
||||
public DataBufferLimitException(String message, Throwable cause) {
|
||||
super(message, cause);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -379,7 +379,12 @@ public class NettyDataBuffer implements PooledDataBuffer {
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return this.byteBuf.toString();
|
||||
try {
|
||||
return this.byteBuf.toString();
|
||||
}
|
||||
catch (OutOfMemoryError ex) {
|
||||
throw new DataBufferLimitException("Failed to convert data buffer to string: " + ex.getMessage(), ex);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user