Skip to content

Commit 33f9eb1

Browse files
committed
Restore required catch for checked CharacterCodingException
CharsetDecoder.decode(ByteBuffer) declares throws CharacterCodingException even though CodingErrorAction.REPLACE makes it unreachable; the compiler still requires the exception to be caught or declared.
1 parent 5d471a6 commit 33f9eb1

1 file changed

Lines changed: 12 additions & 6 deletions

File tree

internal-api/src/main/java/datadog/trace/api/http/MultipartContentDecoder.java

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package datadog.trace.api.http;
22

33
import java.nio.ByteBuffer;
4+
import java.nio.charset.CharacterCodingException;
45
import java.nio.charset.Charset;
56
import java.nio.charset.CodingErrorAction;
67

@@ -10,12 +11,17 @@ public final class MultipartContentDecoder {
1011
public static String decodeBytes(byte[] buf, int length, String contentType) {
1112
Charset charset = extractCharset(contentType);
1213
if (charset == null) charset = Charset.defaultCharset();
13-
return charset
14-
.newDecoder()
15-
.onMalformedInput(CodingErrorAction.REPLACE)
16-
.onUnmappableCharacter(CodingErrorAction.REPLACE)
17-
.decode(ByteBuffer.wrap(buf, 0, length))
18-
.toString();
14+
try {
15+
return charset
16+
.newDecoder()
17+
.onMalformedInput(CodingErrorAction.REPLACE)
18+
.onUnmappableCharacter(CodingErrorAction.REPLACE)
19+
.decode(ByteBuffer.wrap(buf, 0, length))
20+
.toString();
21+
} catch (CharacterCodingException e) {
22+
// unreachable: CodingErrorAction.REPLACE never throws CharacterCodingException
23+
throw new IllegalStateException(e);
24+
}
1925
}
2026

2127
public static Charset extractCharset(String contentType) {

0 commit comments

Comments
 (0)