205 final byte[] classFileBuffer,
206 final int classFileOffset,
207 final int classFileLength) { // NOPMD(UnusedFormalParameter) used for backward compatibility.
208 this(classFileBuffer, classFileOffset, /* checkClassVersion = */ true);
209 }
210
211 /**
212 * Constructs a new {@link ClassReader} object. <i>This internal constructor must not be exposed
213 * as a public API</i>.
214 *
215 * @param classFileBuffer a byte array containing the JVMS ClassFile structure to be read.
216 * @param classFileOffset the offset in byteBuffer of the first byte of the ClassFile to be read.
217 * @param checkClassVersion whether to check the class version or not.
218 */
219 ClassReader(
220 final byte[] classFileBuffer, final int classFileOffset, final boolean checkClassVersion) {
221 this.classFileBuffer = classFileBuffer;
222 this.b = classFileBuffer;
223 // Check the class' major_version. This field is after the magic and minor_version fields, which
224 // use 4 and 2 bytes respectively.
225 if (checkClassVersion && readShort(classFileOffset + 6) > Opcodes.V15) {
226 throw new IllegalArgumentException(
227 "Unsupported class file major version " + readShort(classFileOffset + 6));
228 }
229 // Create the constant pool arrays. The constant_pool_count field is after the magic,
230 // minor_version and major_version fields, which use 4, 2 and 2 bytes respectively.
231 int constantPoolCount = readUnsignedShort(classFileOffset + 8);
232 cpInfoOffsets = new int[constantPoolCount];
233 constantUtf8Values = new String[constantPoolCount];
234 // Compute the offset of each constant pool entry, as well as a conservative estimate of the
235 // maximum length of the constant pool strings. The first constant pool entry is after the
236 // magic, minor_version, major_version and constant_pool_count fields, which use 4, 2, 2 and 2
237 // bytes respectively.
238 int currentCpInfoIndex = 1;
239 int currentCpInfoOffset = classFileOffset + 10;
240 int currentMaxStringLength = 0;
241 boolean hasBootstrapMethods = false;
242 boolean hasConstantDynamic = false;
243 // The offset of the other entries depend on the total size of all the previous entries.
244 while (currentCpInfoIndex < constantPoolCount) {
245 cpInfoOffsets[currentCpInfoIndex++] = currentCpInfoOffset + 1;
|
205 final byte[] classFileBuffer,
206 final int classFileOffset,
207 final int classFileLength) { // NOPMD(UnusedFormalParameter) used for backward compatibility.
208 this(classFileBuffer, classFileOffset, /* checkClassVersion = */ true);
209 }
210
211 /**
212 * Constructs a new {@link ClassReader} object. <i>This internal constructor must not be exposed
213 * as a public API</i>.
214 *
215 * @param classFileBuffer a byte array containing the JVMS ClassFile structure to be read.
216 * @param classFileOffset the offset in byteBuffer of the first byte of the ClassFile to be read.
217 * @param checkClassVersion whether to check the class version or not.
218 */
219 ClassReader(
220 final byte[] classFileBuffer, final int classFileOffset, final boolean checkClassVersion) {
221 this.classFileBuffer = classFileBuffer;
222 this.b = classFileBuffer;
223 // Check the class' major_version. This field is after the magic and minor_version fields, which
224 // use 4 and 2 bytes respectively.
225 if (checkClassVersion && readShort(classFileOffset + 6) > Opcodes.V16) {
226 throw new IllegalArgumentException(
227 "Unsupported class file major version " + readShort(classFileOffset + 6));
228 }
229 // Create the constant pool arrays. The constant_pool_count field is after the magic,
230 // minor_version and major_version fields, which use 4, 2 and 2 bytes respectively.
231 int constantPoolCount = readUnsignedShort(classFileOffset + 8);
232 cpInfoOffsets = new int[constantPoolCount];
233 constantUtf8Values = new String[constantPoolCount];
234 // Compute the offset of each constant pool entry, as well as a conservative estimate of the
235 // maximum length of the constant pool strings. The first constant pool entry is after the
236 // magic, minor_version, major_version and constant_pool_count fields, which use 4, 2, 2 and 2
237 // bytes respectively.
238 int currentCpInfoIndex = 1;
239 int currentCpInfoOffset = classFileOffset + 10;
240 int currentMaxStringLength = 0;
241 boolean hasBootstrapMethods = false;
242 boolean hasConstantDynamic = false;
243 // The offset of the other entries depend on the total size of all the previous entries.
244 while (currentCpInfoIndex < constantPoolCount) {
245 cpInfoOffsets[currentCpInfoIndex++] = currentCpInfoOffset + 1;
|