Skip to content

Commit dfc9093

Browse files
committed
8340132: Remove internal CpException for reading malformed utf8
Reviewed-by: asotona
1 parent f0ae90f commit dfc9093

File tree

1 file changed

+9
-13
lines changed

1 file changed

+9
-13
lines changed

src/java.base/share/classes/jdk/internal/classfile/impl/AbstractPoolEntry.java

+9-13
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
*/
2525
package jdk.internal.classfile.impl;
2626

27+
import java.lang.classfile.constantpool.ConstantPoolException;
2728
import java.lang.constant.*;
2829
import java.lang.invoke.TypeDescriptor;
2930
import java.nio.charset.StandardCharsets;
@@ -258,11 +259,11 @@ private void inflate() {
258259
// 110x xxxx 10xx xxxx
259260
px += 2;
260261
if (px > utfend) {
261-
throw new CpException("malformed input: partial character at end");
262+
throw malformedInput(utfend);
262263
}
263264
int char2 = rawBytes[px - 1];
264265
if ((char2 & 0xC0) != 0x80) {
265-
throw new CpException("malformed input around byte " + px);
266+
throw malformedInput(px);
266267
}
267268
char v = (char) (((c & 0x1F) << 6) | (char2 & 0x3F));
268269
chararr[chararr_count++] = v;
@@ -273,12 +274,12 @@ private void inflate() {
273274
// 1110 xxxx 10xx xxxx 10xx xxxx
274275
px += 3;
275276
if (px > utfend) {
276-
throw new CpException("malformed input: partial character at end");
277+
throw malformedInput(utfend);
277278
}
278279
int char2 = rawBytes[px - 2];
279280
int char3 = rawBytes[px - 1];
280281
if (((char2 & 0xC0) != 0x80) || ((char3 & 0xC0) != 0x80)) {
281-
throw new CpException("malformed input around byte " + (px - 1));
282+
throw malformedInput(px - 1);
282283
}
283284
char v = (char) (((c & 0x0F) << 12) | ((char2 & 0x3F) << 6) | (char3 & 0x3F));
284285
chararr[chararr_count++] = v;
@@ -287,15 +288,18 @@ private void inflate() {
287288
}
288289
default:
289290
// 10xx xxxx, 1111 xxxx
290-
throw new CpException("malformed input around byte " + px);
291+
throw malformedInput(px);
291292
}
292293
}
293294
this.hash = hashString(hash);
294295
charLen = chararr_count;
295296
this.chars = chararr;
296297
state = State.CHAR;
297298
}
299+
}
298300

301+
private ConstantPoolException malformedInput(int px) {
302+
return new ConstantPoolException("#%d: malformed modified UTF8 around byte %d".formatted(index(), px));
299303
}
300304

301305
@Override
@@ -1134,12 +1138,4 @@ public boolean equals(Object o) {
11341138
return false;
11351139
}
11361140
}
1137-
1138-
static class CpException extends RuntimeException {
1139-
static final long serialVersionUID = 32L;
1140-
1141-
CpException(String s) {
1142-
super(s);
1143-
}
1144-
}
11451141
}

0 commit comments

Comments
 (0)