Skip to content

Commit 9661e4d

Browse files
committed
Use UTFDataFormatException for malformed DataInputStream UTF
1 parent d8aa5c0 commit 9661e4d

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

vm/JavaAPI/src/java/io/DataInputStream.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -200,25 +200,25 @@ private static String decode(byte[] in, char[] out, int offset, int utfSize) thr
200200
s++;
201201
} else if (((a = out[s]) & 0xe0) == 0xc0) {
202202
if (count >= utfSize) {
203-
throw new RuntimeException("bad second byte at " + count);
203+
throw new UTFDataFormatException("bad second byte");
204204
}
205205
int b = in[offset + count++];
206206
if ((b & 0xC0) != 0x80) {
207-
throw new RuntimeException("bad second byte at " + (count - 1));
207+
throw new UTFDataFormatException("bad second byte");
208208
}
209209
out[s++] = (char) (((a & 0x1F) << 6) | (b & 0x3F));
210210
} else if ((a & 0xf0) == 0xe0) {
211211
if (count + 1 >= utfSize) {
212-
throw new RuntimeException("bad third byte at " + (count + 1));
212+
throw new UTFDataFormatException("bad third byte");
213213
}
214214
int b = in[offset + count++];
215215
int c = in[offset + count++];
216216
if (((b & 0xC0) != 0x80) || ((c & 0xC0) != 0x80)) {
217-
throw new RuntimeException("bad second or third byte at " + (count - 2));
217+
throw new UTFDataFormatException("bad second or third byte");
218218
}
219219
out[s++] = (char) (((a & 0x0F) << 12) | ((b & 0x3F) << 6) | (c & 0x3F));
220220
} else {
221-
throw new RuntimeException("bad byte at " + (count - 1));
221+
throw new UTFDataFormatException("bad byte");
222222
}
223223
}
224224
return new String(out, 0, s);

0 commit comments

Comments
 (0)