24
24
*/
25
25
package jdk .internal .classfile .impl ;
26
26
27
+ import java .lang .classfile .constantpool .ConstantPoolException ;
27
28
import java .lang .constant .*;
28
29
import java .lang .invoke .TypeDescriptor ;
29
30
import java .nio .charset .StandardCharsets ;
@@ -258,11 +259,11 @@ private void inflate() {
258
259
// 110x xxxx 10xx xxxx
259
260
px += 2 ;
260
261
if (px > utfend ) {
261
- throw new CpException ( "malformed input: partial character at end" );
262
+ throw malformedInput ( utfend );
262
263
}
263
264
int char2 = rawBytes [px - 1 ];
264
265
if ((char2 & 0xC0 ) != 0x80 ) {
265
- throw new CpException ( "malformed input around byte " + px );
266
+ throw malformedInput ( px );
266
267
}
267
268
char v = (char ) (((c & 0x1F ) << 6 ) | (char2 & 0x3F ));
268
269
chararr [chararr_count ++] = v ;
@@ -273,12 +274,12 @@ private void inflate() {
273
274
// 1110 xxxx 10xx xxxx 10xx xxxx
274
275
px += 3 ;
275
276
if (px > utfend ) {
276
- throw new CpException ( "malformed input: partial character at end" );
277
+ throw malformedInput ( utfend );
277
278
}
278
279
int char2 = rawBytes [px - 2 ];
279
280
int char3 = rawBytes [px - 1 ];
280
281
if (((char2 & 0xC0 ) != 0x80 ) || ((char3 & 0xC0 ) != 0x80 )) {
281
- throw new CpException ( "malformed input around byte " + ( px - 1 ) );
282
+ throw malformedInput ( px - 1 );
282
283
}
283
284
char v = (char ) (((c & 0x0F ) << 12 ) | ((char2 & 0x3F ) << 6 ) | (char3 & 0x3F ));
284
285
chararr [chararr_count ++] = v ;
@@ -287,15 +288,18 @@ private void inflate() {
287
288
}
288
289
default :
289
290
// 10xx xxxx, 1111 xxxx
290
- throw new CpException ( "malformed input around byte " + px );
291
+ throw malformedInput ( px );
291
292
}
292
293
}
293
294
this .hash = hashString (hash );
294
295
charLen = chararr_count ;
295
296
this .chars = chararr ;
296
297
state = State .CHAR ;
297
298
}
299
+ }
298
300
301
+ private ConstantPoolException malformedInput (int px ) {
302
+ return new ConstantPoolException ("#%d: malformed modified UTF8 around byte %d" .formatted (index (), px ));
299
303
}
300
304
301
305
@ Override
@@ -1134,12 +1138,4 @@ public boolean equals(Object o) {
1134
1138
return false ;
1135
1139
}
1136
1140
}
1137
-
1138
- static class CpException extends RuntimeException {
1139
- static final long serialVersionUID = 32L ;
1140
-
1141
- CpException (String s ) {
1142
- super (s );
1143
- }
1144
- }
1145
1141
}
0 commit comments