Commit 816ba3fa authored by raphw's avatar raphw
Browse files

Allow disabling class file version check in class reader to better allow ASM...

Allow disabling class file version check in class reader to better allow ASM users to work with EA releases of the JVM after version numbers are increased.

Makes a formerly package-private constructor accessible. As many ASM users shade ASM, it is already easily possible to use this constructor by creating a subclass in the org.objectweb.asm package that invokes this constructor with the appropriate access rights but it would be nicer to get a more official way to access the constructor.
parent ab106301
Pipeline #1214 failed with stage
in 1 minute and 41 seconds
......@@ -133,7 +133,7 @@ public class ClassReader {
* @param classFile the JVMS ClassFile structure to be read.
*/
public ClassReader(final byte[] classFile) {
this(classFile, 0, classFile.length);
this(classFile, 0);
}
/**
......@@ -142,26 +142,51 @@ public class ClassReader {
* @param classFileBuffer a byte array containing the JVMS ClassFile structure to be read.
* @param classFileOffset the offset in byteBuffer of the first byte of the ClassFile to be read.
* @param classFileLength the length in bytes of the ClassFile to be read.
* @deprecated Use {@link ClassReader#ClassReader(byte[], int)} instead.
*/
@Deprecated
public ClassReader(
final byte[] classFileBuffer, final int classFileOffset, final int classFileLength) {
final byte[] classFileBuffer, final int classFileOffset, @SuppressWarnings("unused") final int classFileLength) {
this(classFileBuffer, classFileOffset);
}
/**
* Constructs a new {@link ClassReader} object.
*
* @param classFileBuffer a byte array containing the JVMS ClassFile structure to be read.
* @param classFileOffset the offset in byteBuffer of the first byte of the ClassFile to be read.
*/
public ClassReader(
final byte[] classFileBuffer, final int classFileOffset) {
this(classFileBuffer, classFileOffset, /* checkClassVersion = */ true);
}
/**
* Constructs a new {@link ClassReader} object. <i>This internal constructor must not be exposed
* as a public API</i>.
* Constructs a new {@link ClassReader} object.
*
* @param classFileBuffer a byte array containing the JVMS ClassFile structure to be read.
* @param classFileOffset the offset in byteBuffer of the first byte of the ClassFile to be read.
* @param checkClassVersion whether to check the class version or not.
*/
ClassReader(
protected ClassReader(
final byte[] classFileBuffer, final int classFileOffset, final boolean checkClassVersion) {
this(classFileBuffer, classFileOffset, checkClassVersion, Opcodes.V10);
}
/**
* Constructs a new {@link ClassReader} object.
*
* @param classFileBuffer a byte array containing the JVMS ClassFile structure to be read.
* @param classFileOffset the offset in byteBuffer of the first byte of the ClassFile to be read.
* @param checkClassVersion whether to check the class version or not.
* @param maxVersion The maximum class file version to allow in case the check
*/
protected ClassReader(
final byte[] classFileBuffer, final int classFileOffset, final boolean checkClassVersion, final int maxVersion) {
this.b = classFileBuffer;
// Check the class' major_version. This field is after the magic and minor_version fields, which
// use 4 and 2 bytes respectively.
if (checkClassVersion && readShort(classFileOffset + 6) > Opcodes.V10) {
if (checkClassVersion && readShort(classFileOffset + 6) > maxVersion) {
throw new IllegalArgumentException(
"Unsupported class file major version " + readShort(classFileOffset + 6));
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment