diff --git a/spring-core/src/main/java/org/springframework/core/codec/StringDecoder.java b/spring-core/src/main/java/org/springframework/core/codec/StringDecoder.java index 1b41823d36..953ddbd51e 100644 --- a/spring-core/src/main/java/org/springframework/core/codec/StringDecoder.java +++ b/spring-core/src/main/java/org/springframework/core/codec/StringDecoder.java @@ -16,7 +16,6 @@ package org.springframework.core.codec; -import java.nio.CharBuffer; import java.nio.charset.Charset; import java.nio.charset.StandardCharsets; import java.util.ArrayList; @@ -189,9 +188,8 @@ public final class StringDecoder extends AbstractDataBufferDecoder { @Nullable MimeType mimeType, @Nullable Map hints) { Charset charset = getCharset(mimeType); - CharBuffer charBuffer = charset.decode(dataBuffer.toByteBuffer()); + String value = dataBuffer.toString(charset); DataBufferUtils.release(dataBuffer); - String value = charBuffer.toString(); LogFormatUtils.traceDebug(logger, traceOn -> { String formatted = LogFormatUtils.formatValue(value, !traceOn); return Hints.getLogPrefix(hints) + "Decoded " + formatted; diff --git a/spring-web/src/main/java/org/springframework/http/codec/FormHttpMessageReader.java b/spring-web/src/main/java/org/springframework/http/codec/FormHttpMessageReader.java index c8224445b8..2cfa966197 100644 --- a/spring-web/src/main/java/org/springframework/http/codec/FormHttpMessageReader.java +++ b/spring-web/src/main/java/org/springframework/http/codec/FormHttpMessageReader.java @@ -17,7 +17,6 @@ package org.springframework.http.codec; import java.net.URLDecoder; -import java.nio.CharBuffer; import java.nio.charset.Charset; import java.nio.charset.StandardCharsets; import java.util.Collections; @@ -129,8 +128,7 @@ public class FormHttpMessageReader extends LoggingCodecSupport return DataBufferUtils.join(message.getBody(), this.maxInMemorySize) .map(buffer -> { - CharBuffer charBuffer = charset.decode(buffer.toByteBuffer()); - String body = charBuffer.toString(); + String body = buffer.toString(charset); DataBufferUtils.release(buffer); MultiValueMap formData = parseFormData(charset, body); logFormData(formData, hints);