diff --git a/compiler/tests-common/org/jetbrains/kotlin/codegen/DxChecker.java b/compiler/tests-common/org/jetbrains/kotlin/codegen/DxChecker.java index c15b54deedf..2018344eed3 100644 --- a/compiler/tests-common/org/jetbrains/kotlin/codegen/DxChecker.java +++ b/compiler/tests-common/org/jetbrains/kotlin/codegen/DxChecker.java @@ -23,10 +23,10 @@ import com.android.dx.dex.cf.CfTranslator; import com.android.dx.dex.file.DexFile; import org.jetbrains.annotations.NotNull; import org.jetbrains.kotlin.backend.common.output.OutputFile; +import org.jetbrains.org.objectweb.asm.Opcodes; import org.junit.Assert; -import java.io.PrintWriter; -import java.io.StringWriter; +import java.io.*; import java.util.regex.Matcher; import java.util.regex.Pattern; @@ -47,7 +47,9 @@ public class DxChecker { for (OutputFile file : ClassFileUtilsKt.getClassFiles(outputFiles)) { try { byte[] bytes = file.asByteArray(); - checkFileWithDx(bytes, file.getRelativePath(), arguments); + if (isJava6Class(bytes)) { + checkFileWithDx(bytes, file.getRelativePath(), arguments); + } } catch (Throwable e) { Assert.fail(generateExceptionMessage(e)); @@ -55,6 +57,18 @@ public class DxChecker { } } + private static boolean isJava6Class(byte[] bytes) throws IOException { + try (DataInputStream stream = new DataInputStream(new ByteArrayInputStream(bytes))) { + int header = stream.readInt(); + if (0xCAFEBABE != header) { + throw new IOException("Invalid header class header: " + header); + } + int minor = stream.readUnsignedShort(); + int major = stream.readUnsignedShort(); + return major == Opcodes.V1_6; + } + } + public static void checkFileWithDx(byte[] bytes, @NotNull String relativePath) { Main.Arguments arguments = new Main.Arguments(); String[] array = new String[1];