Skip to content

Commit

Permalink
Add experimental Java 17 support
Browse files Browse the repository at this point in the history
  • Loading branch information
marchof committed Dec 14, 2020
1 parent 918985c commit 43cd10c
Show file tree
Hide file tree
Showing 6 changed files with 52 additions and 10 deletions.
14 changes: 14 additions & 0 deletions org.jacoco.build/pom.xml
Expand Up @@ -865,6 +865,20 @@
</properties>
</profile>

<profile>
<id>java17-bytecode</id>
<activation>
<property>
<name>bytecode.version</name>
<value>17</value>
</property>
</activation>
<properties>
<maven.compiler.source>13</maven.compiler.source>
<maven.compiler.target>13</maven.compiler.target>
</properties>
</profile>

<!-- This profile enables use of ECJ -->
<profile>
<id>ecj</id>
Expand Down
25 changes: 25 additions & 0 deletions org.jacoco.core.test.validation/pom.xml
Expand Up @@ -257,6 +257,31 @@
<module>../org.jacoco.core.test.validation.scala</module>
</modules>
</profile>

<profile>
<id>java17-bytecode</id>
<activation>
<property>
<name>bytecode.version</name>
<value>17</value>
</property>
</activation>
<properties>
<!-- see respective profile in org.jacoco.build about this override -->
<maven.compiler.source>17</maven.compiler.source>
<maven.compiler.target>17</maven.compiler.target>
</properties>
<modules>
<module>../org.jacoco.core.test.validation.kotlin</module>
<module>../org.jacoco.core.test.validation.java7</module>
<module>../org.jacoco.core.test.validation.java8</module>
<module>../org.jacoco.core.test.validation.java14</module>
<!-- Does not yet support Java 17
<module>../org.jacoco.core.test.validation.groovy</module>
-->
<module>../org.jacoco.core.test.validation.scala</module>
</modules>
</profile>
</profiles>

</project>
Expand Up @@ -23,8 +23,8 @@
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.FileOutputStream;
import java.io.InputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.util.Arrays;
import java.util.Collections;
Expand All @@ -33,6 +33,7 @@
import java.util.Map;
import java.util.zip.GZIPOutputStream;
import java.util.zip.ZipEntry;
import java.util.zip.ZipInputStream;
import java.util.zip.ZipOutputStream;

import org.jacoco.core.data.ExecutionDataStore;
Expand Down Expand Up @@ -130,14 +131,14 @@ private static byte[] createClass(final int version) {
*/
@Test
public void analyzeClass_should_throw_exception_for_unsupported_class_file_version() {
final byte[] bytes = createClass(Opcodes.V16 + 1);
final byte[] bytes = createClass(Opcodes.V16 + 2);
try {
analyzer.analyzeClass(bytes, "UnsupportedVersion");
fail("exception expected");
} catch (IOException e) {
assertEquals("Error while analyzing UnsupportedVersion.",
e.getMessage());
assertEquals("Unsupported class file major version 61",
assertEquals("Unsupported class file major version 62",
e.getCause().getMessage());
}
}
Expand Down Expand Up @@ -217,15 +218,15 @@ public void testAnalyzeClass_BrokenStream() throws IOException {
*/
@Test
public void analyzeAll_should_throw_exception_for_unsupported_class_file_version() {
final byte[] bytes = createClass(Opcodes.V16 + 1);
final byte[] bytes = createClass(Opcodes.V16 + 2);
try {
analyzer.analyzeAll(new ByteArrayInputStream(bytes),
"UnsupportedVersion");
fail("exception expected");
} catch (IOException e) {
assertEquals("Error while analyzing UnsupportedVersion.",
e.getMessage());
assertEquals("Unsupported class file major version 61",
assertEquals("Unsupported class file major version 62",
e.getCause().getMessage());
}
}
Expand Down
Expand Up @@ -122,14 +122,14 @@ private static byte[] createClass(final int version) {
*/
@Test
public void instrument_should_throw_exception_for_unsupported_class_file_version() {
final byte[] bytes = createClass(Opcodes.V16 + 1);
final byte[] bytes = createClass(Opcodes.V16 + 2);
try {
instrumenter.instrument(bytes, "UnsupportedVersion");
fail("exception expected");
} catch (final IOException e) {
assertEquals("Error while instrumenting UnsupportedVersion.",
e.getMessage());
assertEquals("Unsupported class file major version 61",
assertEquals("Unsupported class file major version 62",
e.getCause().getMessage());
}
}
Expand Down Expand Up @@ -224,15 +224,15 @@ public void testSerialization() throws Exception {
*/
@Test
public void instrumentAll_should_throw_exception_for_unsupported_class_file_version() {
final byte[] bytes = createClass(Opcodes.V16 + 1);
final byte[] bytes = createClass(Opcodes.V16 + 2);
try {
instrumenter.instrumentAll(new ByteArrayInputStream(bytes),
new ByteArrayOutputStream(), "UnsupportedVersion");
fail("exception expected");
} catch (final IOException e) {
assertEquals("Error while instrumenting UnsupportedVersion.",
e.getMessage());
assertEquals("Unsupported class file major version 61",
assertEquals("Unsupported class file major version 62",
e.getCause().getMessage());
}
}
Expand Down
Expand Up @@ -273,7 +273,7 @@ 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.V16) {
if (originalVersion == Opcodes.V16 + 1) {
// temporarily downgrade version to bypass check in ASM
setMajorVersion(Opcodes.V16, b);
}
Expand Down
2 changes: 2 additions & 0 deletions org.jacoco.doc/docroot/doc/changes.html
Expand Up @@ -25,6 +25,8 @@ <h3>New Features</h3>
<li>JaCoCo now officially supports Java 15
(GitHub <a href="https://github.com/jacoco/jacoco/issues/1094">#1094</a>,
<a href="https://github.com/jacoco/jacoco/issues/1097">#1097</a>).</li>
<li>Experimental support for Java 17 class files
(GitHub <a href="https://github.com/jacoco/jacoco/issues/1132">#1132</a>).</li>
</ul>

<h3>Non-functional Changes</h3>
Expand Down

0 comments on commit 43cd10c

Please sign in to comment.