Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add experimental support for Java 14 class files #897

Merged
merged 2 commits into from Jun 20, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -106,7 +106,7 @@ public void should_ignore_synthetic_classes() throws Exception {
@Test
public void should_not_modify_class_bytes_to_support_next_version()
throws Exception {
final byte[] originalBytes = createClass(Opcodes.V12 + 1);
final byte[] originalBytes = createClass(Opcodes.V13 + 1);
final byte[] bytes = new byte[originalBytes.length];
System.arraycopy(originalBytes, 0, bytes, 0, originalBytes.length);
final long expectedClassId = CRC64.classId(bytes);
Expand Down
Expand Up @@ -26,6 +26,7 @@
import static org.objectweb.asm.Opcodes.V10;
import static org.objectweb.asm.Opcodes.V11;
import static org.objectweb.asm.Opcodes.V12;
import static org.objectweb.asm.Opcodes.V13;
import static org.objectweb.asm.Opcodes.V1_1;
import static org.objectweb.asm.Opcodes.V1_2;
import static org.objectweb.asm.Opcodes.V1_3;
Expand Down Expand Up @@ -116,7 +117,12 @@ public void test_12() throws IOException {

@Test
public void test_13() throws IOException {
testVersion(V12 + 1, true);
testVersion(V13, true);
}

@Test
public void test_14() throws IOException {
testVersion(V13 + 1, true);
}

private void testVersion(int version, boolean frames) throws IOException {
Expand Down
Expand Up @@ -98,7 +98,7 @@ public void setup() throws Exception {
@Test
public void should_not_modify_class_bytes_to_support_next_version()
throws Exception {
final byte[] originalBytes = createClass(Opcodes.V12 + 1);
final byte[] originalBytes = createClass(Opcodes.V13 + 1);
final byte[] bytes = new byte[originalBytes.length];
System.arraycopy(originalBytes, 0, bytes, 0, originalBytes.length);
final long expectedClassId = CRC64.classId(bytes);
Expand Down
Expand Up @@ -165,6 +165,20 @@ public void should_detect_java_13_with_preview_features() throws IOException {
assertContent();
}

@Test
public void should_detect_java_14() throws IOException {
initData(0xCA, 0xFE, 0xBA, 0xBE, 0x00, 0x00, 0x00, 0x3A);
assertEquals(ContentTypeDetector.CLASSFILE, detector.getType());
assertContent();
}

@Test
public void should_detect_java_14_with_preview_features() throws IOException {
initData(0xCA, 0xFE, 0xBA, 0xBE, 0xFF, 0xFF, 0x00, 0x3A);
assertEquals(ContentTypeDetector.CLASSFILE, detector.getType());
assertContent();
}

@Test
public void testMachObjectFile() throws IOException {
initData(0xCA, 0xFE, 0xBA, 0xBE, 0x00, 0x00, 0x00, 0x02);
Expand Down
Expand Up @@ -46,8 +46,8 @@ public void setup() {
}

@Test
public void classReaderFor_should_read_java_13_class() {
final byte[] bytes = createJava13Class();
public void classReaderFor_should_read_java_14_class() {
final byte[] bytes = createJava14Class();

final ClassReader classReader = InstrSupport.classReaderFor(bytes);

Expand All @@ -56,16 +56,16 @@ public void classReaderFor_should_read_java_13_class() {
public void visit(final int version, final int access,
final String name, final String signature,
final String superName, final String[] interfaces) {
assertEquals(Opcodes.V12 + 1, version);
assertEquals(Opcodes.V13 + 1, version);
}
}, 0);

assertArrayEquals(createJava13Class(), bytes);
assertArrayEquals(createJava14Class(), bytes);
}

private static byte[] createJava13Class() {
private static byte[] createJava14Class() {
final ClassWriter cw = new ClassWriter(0);
cw.visit(Opcodes.V12 + 1, 0, "Foo", null, "java/lang/Object", null);
cw.visit(Opcodes.V13 + 1, 0, "Foo", null, "java/lang/Object", null);
cw.visitEnd();
return cw.toByteArray();
}
Expand Down Expand Up @@ -127,7 +127,8 @@ public void needFrames_should_return_true_for_versions_greater_than_or_equal_to_
assertTrue(InstrSupport.needsFrames(Opcodes.V10));
assertTrue(InstrSupport.needsFrames(Opcodes.V11));
assertTrue(InstrSupport.needsFrames(Opcodes.V12));
assertTrue(InstrSupport.needsFrames(Opcodes.V12 + 1));
assertTrue(InstrSupport.needsFrames(Opcodes.V13));
assertTrue(InstrSupport.needsFrames(Opcodes.V13 + 1));

assertTrue(InstrSupport.needsFrames(0x0100));
}
Expand Down
Expand Up @@ -88,8 +88,10 @@ private static int determineType(final InputStream in) throws IOException {
case Opcodes.V11 | Opcodes.V_PREVIEW:
case Opcodes.V12:
case Opcodes.V12 | Opcodes.V_PREVIEW:
case (Opcodes.V12 + 1):
case (Opcodes.V12 + 1) | Opcodes.V_PREVIEW:
case Opcodes.V13:
case Opcodes.V13 | Opcodes.V_PREVIEW:
case (Opcodes.V13 + 1):
case (Opcodes.V13 + 1) | Opcodes.V_PREVIEW:
return CLASSFILE;
}
}
Expand Down
Expand Up @@ -272,9 +272,9 @@ public static void push(final MethodVisitor mv, final int value) {
*/
public static ClassReader classReaderFor(final byte[] b) {
final int originalVersion = getMajorVersion(b);
if (originalVersion == Opcodes.V12 + 1) {
if (originalVersion == Opcodes.V13 + 1) {
// temporarily downgrade version to bypass check in ASM
setMajorVersion(Opcodes.V12, b);
setMajorVersion(Opcodes.V13, b);
}
final ClassReader classReader = new ClassReader(b);
setMajorVersion(originalVersion, b);
Expand Down
2 changes: 2 additions & 0 deletions org.jacoco.doc/docroot/doc/changes.html
Expand Up @@ -22,6 +22,8 @@ <h2>Snapshot Build @qualified.bundle.version@ (@build.date@)</h2>

<h3>New Features</h3>
<ul>
<li>Experimental support for Java 14 class files
(GitHub <a href="https://github.com/jacoco/jacoco/issues/897">#897</a>).</li>
<li>Branches added by the Kotlin compiler for <code>open</code> functions with
default arguments are filtered out during generation of report
(GitHub <a href="https://github.com/jacoco/jacoco/issues/887">#887</a>).</li>
Expand Down