Commit 63924390 authored by Eric Bruneton's avatar Eric Bruneton

Merge branch '317807-fix-class-version-asymmetry' into 'master'

Don't check the class version when using a ClassReader to remove the ASM specific instructions. Closes #317807 See merge request !92
parents 58b93c69 27ad0875
Pipeline #606 passed with stage
in 5 minutes 42 seconds
......@@ -142,10 +142,23 @@ public class ClassReader {
*/
public ClassReader(
final byte[] classFileBuffer, final int classFileOffset, final int classFileLength) {
this(classFileBuffer, classFileOffset, /* checkClassVersion = */ true);
}
/**
* Constructs a new {@link ClassReader} object. <i>This internal constructor must not be exposed
* as a public API</i>.
*
* @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(
final byte[] classFileBuffer, final int classFileOffset, final boolean checkClassVersion) {
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 (readShort(classFileOffset + 6) > Opcodes.V10) {
if (checkClassVersion && readShort(classFileOffset + 6) > Opcodes.V10) {
throw new IllegalArgumentException();
}
// Create the constant pool arrays. The constant_pool_count field is after the magic,
......
......@@ -612,7 +612,7 @@ public class ClassWriter extends ClassVisitor {
moduleWriter = null;
firstAttribute = null;
compute = hasFrames ? MethodWriter.COMPUTE_INSERTED_FRAMES : MethodWriter.COMPUTE_NOTHING;
new ClassReader(result.data)
new ClassReader(result.data, 0, /* checkClassVersion = */ false)
.accept(this, (hasFrames ? ClassReader.EXPAND_FRAMES : 0) | ClassReader.EXPAND_ASM_INSNS);
return toByteArray();
} else {
......
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