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 17 class files #1132

Merged
merged 3 commits into from Dec 15, 2020
Merged
Show file tree
Hide file tree
Changes from 2 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
2 changes: 2 additions & 0 deletions .azure-pipelines/azure-pipelines.yml
Expand Up @@ -29,6 +29,8 @@ jobs:
JDK_VERSION: 15
JDK 16:
JDK_VERSION: 16
JDK 17:
JDK_VERSION: 17
pool:
vmImage: 'ubuntu-18.04'
steps:
Expand Down
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
Godin marked this conversation as resolved.
Show resolved Hide resolved
<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