Fix logic for downgrading class file major versions
Fixes
@@ -67,8 +67,16 @@ public class Java7Compatibility extends ClassVisitor {
this.superName = superName;
this.interfaces = interfaces;
isInterface = BitFlags.isSet(access, Opcodes.ACC_INTERFACE);
+ // ASM uses the high 16 bits for the minor version:
+ // https://asm.ow2.io/javadoc/org/objectweb/asm/ClassVisitor.html#visit-int-int-java.lang.String-java.lang.String-java.lang.String-java.lang.String:A-
+ // See https://github.com/bazelbuild/bazel/issues/6299 for an example of a class file with a
+ // non-zero minor version.
+ int major = version & 0xffff;
+ if (major > Opcodes.V1_7) {
+ version = Opcodes.V1_7;
+ }
super.visit(
- Math.min(version, Opcodes.V1_7),
+ version,
access,
name,
signature,
