Skip to content

Commit 1485a41

Browse files
authored
Add experimental support for Java 16 (#1059)
1 parent d60a5b2 commit 1485a41

File tree

10 files changed

+76
-20
lines changed

10 files changed

+76
-20
lines changed

.travis.sh

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,9 @@ case "$JDK" in
7575
15-ea)
7676
install_jdk $JDK15_EA_URL
7777
;;
78+
16-ea)
79+
install_jdk $JDK16_EA_URL
80+
;;
7881
esac
7982

8083
# Do not use "~/.mavenrc" set by Travis (https://github.com/travis-ci/travis-ci/issues/3893),
@@ -110,6 +113,10 @@ case "$JDK" in
110113
mvn -V -B -e verify -Dbytecode.version=15 \
111114
--settings=./.travis/settings.xml
112115
;;
116+
16-ea)
117+
mvn -V -B -e verify -Dbytecode.version=16 \
118+
--settings=./.travis/settings.xml
119+
;;
113120
*)
114121
echo "Incorrect JDK [$JDK]"
115122
exit 1;

.travis.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,5 +31,6 @@ env:
3131
- JDK=13
3232
- JDK=14
3333
- JDK=15-ea
34+
- JDK=16-ea
3435

3536
script: ./.travis.sh

org.jacoco.build/pom.xml

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -841,6 +841,20 @@
841841
</properties>
842842
</profile>
843843

844+
<profile>
845+
<id>java16-bytecode</id>
846+
<activation>
847+
<property>
848+
<name>bytecode.version</name>
849+
<value>16</value>
850+
</property>
851+
</activation>
852+
<properties>
853+
<maven.compiler.source>13</maven.compiler.source>
854+
<maven.compiler.target>13</maven.compiler.target>
855+
</properties>
856+
</profile>
857+
844858
<!-- This profile enables use of ECJ -->
845859
<profile>
846860
<id>ecj</id>

org.jacoco.core.test.validation/pom.xml

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -246,6 +246,31 @@
246246
<module>../org.jacoco.core.test.validation.scala</module>
247247
</modules>
248248
</profile>
249+
250+
<profile>
251+
<id>java16-bytecode</id>
252+
<activation>
253+
<property>
254+
<name>bytecode.version</name>
255+
<value>16</value>
256+
</property>
257+
</activation>
258+
<properties>
259+
<!-- see respective profile in org.jacoco.build about this override -->
260+
<maven.compiler.source>16</maven.compiler.source>
261+
<maven.compiler.target>16</maven.compiler.target>
262+
</properties>
263+
<modules>
264+
<module>../org.jacoco.core.test.validation.kotlin</module>
265+
<module>../org.jacoco.core.test.validation.java7</module>
266+
<module>../org.jacoco.core.test.validation.java8</module>
267+
<module>../org.jacoco.core.test.validation.java14</module>
268+
<!-- Groovy 2.5.8 doesn't support bytecode version 16
269+
<module>../org.jacoco.core.test.validation.groovy</module>
270+
-->
271+
<module>../org.jacoco.core.test.validation.scala</module>
272+
</modules>
273+
</profile>
249274
</profiles>
250275

251276
</project>

org.jacoco.core.test/src/org/jacoco/core/analysis/AnalyzerTest.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ public void should_ignore_synthetic_classes() throws Exception {
107107
@Test
108108
public void should_not_modify_class_bytes_to_support_next_version()
109109
throws Exception {
110-
final byte[] originalBytes = createClass(Opcodes.V14 + 1);
110+
final byte[] originalBytes = createClass(Opcodes.V15 + 1);
111111
final byte[] bytes = new byte[originalBytes.length];
112112
System.arraycopy(originalBytes, 0, bytes, 0, originalBytes.length);
113113
final long expectedClassId = CRC64.classId(bytes);
@@ -130,14 +130,14 @@ private static byte[] createClass(final int version) {
130130
*/
131131
@Test
132132
public void analyzeClass_should_throw_exception_for_unsupported_class_file_version() {
133-
final byte[] bytes = createClass(Opcodes.V14 + 2);
133+
final byte[] bytes = createClass(Opcodes.V15 + 2);
134134
try {
135135
analyzer.analyzeClass(bytes, "UnsupportedVersion");
136136
fail("exception expected");
137137
} catch (IOException e) {
138138
assertEquals("Error while analyzing UnsupportedVersion.",
139139
e.getMessage());
140-
assertEquals("Unsupported class file major version 60",
140+
assertEquals("Unsupported class file major version 61",
141141
e.getCause().getMessage());
142142
}
143143
}
@@ -217,15 +217,15 @@ public void testAnalyzeClass_BrokenStream() throws IOException {
217217
*/
218218
@Test
219219
public void analyzeAll_should_throw_exception_for_unsupported_class_file_version() {
220-
final byte[] bytes = createClass(Opcodes.V14 + 2);
220+
final byte[] bytes = createClass(Opcodes.V15 + 2);
221221
try {
222222
analyzer.analyzeAll(new ByteArrayInputStream(bytes),
223223
"UnsupportedVersion");
224224
fail("exception expected");
225225
} catch (IOException e) {
226226
assertEquals("Error while analyzing UnsupportedVersion.",
227227
e.getMessage());
228-
assertEquals("Unsupported class file major version 60",
228+
assertEquals("Unsupported class file major version 61",
229229
e.getCause().getMessage());
230230
}
231231
}

org.jacoco.core.test/src/org/jacoco/core/instr/ClassFileVersionsTest.java

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
import static org.objectweb.asm.Opcodes.V12;
3030
import static org.objectweb.asm.Opcodes.V13;
3131
import static org.objectweb.asm.Opcodes.V14;
32+
import static org.objectweb.asm.Opcodes.V15;
3233
import static org.objectweb.asm.Opcodes.V1_1;
3334
import static org.objectweb.asm.Opcodes.V1_2;
3435
import static org.objectweb.asm.Opcodes.V1_3;
@@ -129,7 +130,12 @@ public void test_14() throws IOException {
129130

130131
@Test
131132
public void test_15() throws IOException {
132-
testVersion(V14 + 1, true);
133+
testVersion(V15, true);
134+
}
135+
136+
@Test
137+
public void test_16() throws IOException {
138+
testVersion(V15 + 1, true);
133139
}
134140

135141
private void testVersion(int version, boolean frames) throws IOException {

org.jacoco.core.test/src/org/jacoco/core/instr/InstrumenterTest.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ public void setup() throws Exception {
9999
@Test
100100
public void should_not_modify_class_bytes_to_support_next_version()
101101
throws Exception {
102-
final byte[] originalBytes = createClass(Opcodes.V14 + 1);
102+
final byte[] originalBytes = createClass(Opcodes.V15 + 1);
103103
final byte[] bytes = new byte[originalBytes.length];
104104
System.arraycopy(originalBytes, 0, bytes, 0, originalBytes.length);
105105
final long expectedClassId = CRC64.classId(bytes);
@@ -122,14 +122,14 @@ private static byte[] createClass(final int version) {
122122
*/
123123
@Test
124124
public void instrument_should_throw_exception_for_unsupported_class_file_version() {
125-
final byte[] bytes = createClass(Opcodes.V14 + 2);
125+
final byte[] bytes = createClass(Opcodes.V15 + 2);
126126
try {
127127
instrumenter.instrument(bytes, "UnsupportedVersion");
128128
fail("exception expected");
129129
} catch (final IOException e) {
130130
assertEquals("Error while instrumenting UnsupportedVersion.",
131131
e.getMessage());
132-
assertEquals("Unsupported class file major version 60",
132+
assertEquals("Unsupported class file major version 61",
133133
e.getCause().getMessage());
134134
}
135135
}
@@ -224,15 +224,15 @@ public void testSerialization() throws Exception {
224224
*/
225225
@Test
226226
public void instrumentAll_should_throw_exception_for_unsupported_class_file_version() {
227-
final byte[] bytes = createClass(Opcodes.V14 + 2);
227+
final byte[] bytes = createClass(Opcodes.V15 + 2);
228228
try {
229229
instrumenter.instrumentAll(new ByteArrayInputStream(bytes),
230230
new ByteArrayOutputStream(), "UnsupportedVersion");
231231
fail("exception expected");
232232
} catch (final IOException e) {
233233
assertEquals("Error while instrumenting UnsupportedVersion.",
234234
e.getMessage());
235-
assertEquals("Unsupported class file major version 60",
235+
assertEquals("Unsupported class file major version 61",
236236
e.getCause().getMessage());
237237
}
238238
}

org.jacoco.core.test/src/org/jacoco/core/internal/instr/InstrSupportTest.java

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,8 @@ public void setup() {
4343
}
4444

4545
@Test
46-
public void classReaderFor_should_read_java_15_class() {
47-
final byte[] bytes = createJava15Class();
46+
public void classReaderFor_should_read_java_16_class() {
47+
final byte[] bytes = createJava16Class();
4848

4949
final ClassReader classReader = InstrSupport.classReaderFor(bytes);
5050

@@ -53,16 +53,16 @@ public void classReaderFor_should_read_java_15_class() {
5353
public void visit(final int version, final int access,
5454
final String name, final String signature,
5555
final String superName, final String[] interfaces) {
56-
assertEquals(Opcodes.V14 + 1, version);
56+
assertEquals(Opcodes.V15 + 1, version);
5757
}
5858
}, 0);
5959

60-
assertArrayEquals(createJava15Class(), bytes);
60+
assertArrayEquals(createJava16Class(), bytes);
6161
}
6262

63-
private static byte[] createJava15Class() {
63+
private static byte[] createJava16Class() {
6464
final ClassWriter cw = new ClassWriter(0);
65-
cw.visit(Opcodes.V14 + 1, 0, "Foo", null, "java/lang/Object", null);
65+
cw.visit(Opcodes.V15 + 1, 0, "Foo", null, "java/lang/Object", null);
6666
cw.visitEnd();
6767
return cw.toByteArray();
6868
}
@@ -126,7 +126,8 @@ public void needFrames_should_return_true_for_versions_greater_than_or_equal_to_
126126
assertTrue(InstrSupport.needsFrames(Opcodes.V12));
127127
assertTrue(InstrSupport.needsFrames(Opcodes.V13));
128128
assertTrue(InstrSupport.needsFrames(Opcodes.V14));
129-
assertTrue(InstrSupport.needsFrames(Opcodes.V14 + 1));
129+
assertTrue(InstrSupport.needsFrames(Opcodes.V15));
130+
assertTrue(InstrSupport.needsFrames(Opcodes.V15 + 1));
130131

131132
assertTrue(InstrSupport.needsFrames(0x0100));
132133
}

org.jacoco.core/src/org/jacoco/core/internal/instr/InstrSupport.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -273,9 +273,9 @@ public static void push(final MethodVisitor mv, final int value) {
273273
*/
274274
public static ClassReader classReaderFor(final byte[] b) {
275275
final int originalVersion = getMajorVersion(b);
276-
if (originalVersion == Opcodes.V14 + 1) {
276+
if (originalVersion == Opcodes.V15 + 1) {
277277
// temporarily downgrade version to bypass check in ASM
278-
setMajorVersion(Opcodes.V14, b);
278+
setMajorVersion(Opcodes.V15, b);
279279
}
280280
final ClassReader classReader = new ClassReader(b);
281281
setMajorVersion(originalVersion, b);

org.jacoco.doc/docroot/doc/changes.html

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@ <h3>New Features</h3>
2525
<li>JaCoCo now officially supports Java 14.</li>
2626
<li>Experimental support for Java 15 class files
2727
(GitHub <a href="https://github.com/jacoco/jacoco/issues/992">#992</a>).</li>
28+
<li>Experimental support for Java 16 class files
29+
(GitHub <a href="https://github.com/jacoco/jacoco/issues/1059">#1059</a>).</li>
2830
<li>Methods <code>toString</code>, <code>hashCode</code> and <code>equals</code>
2931
generated by compiler for records are filtered out during generation of report
3032
(GitHub <a href="https://github.com/jacoco/jacoco/issues/990">#990</a>).</li>

0 commit comments

Comments
 (0)