From 5f625ef662d3129a657b32c836d5bb57dd80ba1c Mon Sep 17 00:00:00 2001 From: Evgeny Mandrikov Date: Fri, 13 Dec 2019 12:04:45 +0100 Subject: [PATCH 1/8] (WIP) for tests use our Pack200Streams instead of java.util.jar.Pack200 To avoid compilation errors with JDK 14, where Pack200 not available. --- .../org/jacoco/core/analysis/AnalyzerTest.java | 8 ++------ .../jacoco/core/instr/InstrumenterTest.java | 18 ++++-------------- .../core/internal/ContentTypeDetectorTest.java | 7 +------ 3 files changed, 7 insertions(+), 26 deletions(-) diff --git a/org.jacoco.core.test/src/org/jacoco/core/analysis/AnalyzerTest.java b/org.jacoco.core.test/src/org/jacoco/core/analysis/AnalyzerTest.java index eed79a442c..72cd57c47a 100644 --- a/org.jacoco.core.test/src/org/jacoco/core/analysis/AnalyzerTest.java +++ b/org.jacoco.core.test/src/org/jacoco/core/analysis/AnalyzerTest.java @@ -31,13 +31,12 @@ import java.util.HashMap; import java.util.HashSet; import java.util.Map; -import java.util.jar.JarInputStream; -import java.util.jar.Pack200; import java.util.zip.GZIPOutputStream; import java.util.zip.ZipEntry; import java.util.zip.ZipOutputStream; import org.jacoco.core.data.ExecutionDataStore; +import org.jacoco.core.internal.Pack200Streams; import org.jacoco.core.internal.data.CRC64; import org.jacoco.core.test.TargetLoader; import org.junit.Before; @@ -303,10 +302,7 @@ public void testAnalyzeAll_Pack200() throws IOException { final ByteArrayOutputStream pack200buffer = new ByteArrayOutputStream(); GZIPOutputStream gzipOutput = new GZIPOutputStream(pack200buffer); - Pack200.newPacker() - .pack(new JarInputStream( - new ByteArrayInputStream(zipbuffer.toByteArray())), - gzipOutput); + Pack200Streams.pack(zipbuffer.toByteArray(), gzipOutput); gzipOutput.finish(); final int count = analyzer.analyzeAll( diff --git a/org.jacoco.core.test/src/org/jacoco/core/instr/InstrumenterTest.java b/org.jacoco.core.test/src/org/jacoco/core/instr/InstrumenterTest.java index e67138a723..1f83c0ca9e 100644 --- a/org.jacoco.core.test/src/org/jacoco/core/instr/InstrumenterTest.java +++ b/org.jacoco.core.test/src/org/jacoco/core/instr/InstrumenterTest.java @@ -26,9 +26,6 @@ import java.io.OutputStream; import java.io.Serializable; import java.util.Arrays; -import java.util.jar.JarInputStream; -import java.util.jar.JarOutputStream; -import java.util.jar.Pack200; import java.util.zip.GZIPInputStream; import java.util.zip.GZIPOutputStream; import java.util.zip.ZipEntry; @@ -36,6 +33,7 @@ import java.util.zip.ZipOutputStream; import org.jacoco.core.analysis.AnalyzerTest; +import org.jacoco.core.internal.Pack200Streams; import org.jacoco.core.internal.data.CRC64; import org.jacoco.core.internal.instr.InstrSupport; import org.jacoco.core.runtime.IExecutionDataAccessorGenerator; @@ -406,10 +404,7 @@ public void testInstrumentAll_Pack200() throws IOException { ByteArrayOutputStream pack200buffer = new ByteArrayOutputStream(); GZIPOutputStream gzipOutput = new GZIPOutputStream(pack200buffer); - Pack200.newPacker() - .pack(new JarInputStream( - new ByteArrayInputStream(jarbuffer.toByteArray())), - gzipOutput); + Pack200Streams.pack(jarbuffer.toByteArray(), gzipOutput); gzipOutput.finish(); ByteArrayOutputStream out = new ByteArrayOutputStream(); @@ -417,15 +412,10 @@ public void testInstrumentAll_Pack200() throws IOException { new ByteArrayInputStream(pack200buffer.toByteArray()), out, "Test"); - jarbuffer.reset(); - Pack200.newUnpacker() - .unpack(new GZIPInputStream( - new ByteArrayInputStream(out.toByteArray())), - new JarOutputStream(jarbuffer)); - assertEquals(1, count); ZipInputStream zipin = new ZipInputStream( - new ByteArrayInputStream(jarbuffer.toByteArray())); + Pack200Streams.unpack(new GZIPInputStream( + new ByteArrayInputStream(out.toByteArray())))); assertEquals("Test.class", zipin.getNextEntry().getName()); assertNull(zipin.getNextEntry()); } diff --git a/org.jacoco.core.test/src/org/jacoco/core/internal/ContentTypeDetectorTest.java b/org.jacoco.core.test/src/org/jacoco/core/internal/ContentTypeDetectorTest.java index 094c18a17e..2e78ddb49d 100644 --- a/org.jacoco.core.test/src/org/jacoco/core/internal/ContentTypeDetectorTest.java +++ b/org.jacoco.core.test/src/org/jacoco/core/internal/ContentTypeDetectorTest.java @@ -19,8 +19,6 @@ import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; -import java.util.jar.JarInputStream; -import java.util.jar.Pack200; import java.util.zip.GZIPOutputStream; import java.util.zip.ZipEntry; import java.util.zip.ZipOutputStream; @@ -225,10 +223,7 @@ public void testPack200File() throws IOException { zip.close(); final ByteArrayOutputStream pack200buffer = new ByteArrayOutputStream(); - Pack200.newPacker() - .pack(new JarInputStream( - new ByteArrayInputStream(zipbuffer.toByteArray())), - pack200buffer); + Pack200Streams.pack(zipbuffer.toByteArray(), pack200buffer); initData(pack200buffer.toByteArray()); assertEquals(ContentTypeDetector.PACK200FILE, detector.getType()); assertContent(); From 6272d30222eb30bc014d0e3b0bad8d47cda8cc80 Mon Sep 17 00:00:00 2001 From: Evgeny Mandrikov Date: Fri, 13 Dec 2019 13:04:48 +0100 Subject: [PATCH 2/8] (WIP) add unit tests to prevent regressions Instrumenter and Analyzer provide location information when Pack200 streams throw IOException on error. --- .../core/internal/Pack200StreamsTest.java | 36 +++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/org.jacoco.core.test/src/org/jacoco/core/internal/Pack200StreamsTest.java b/org.jacoco.core.test/src/org/jacoco/core/internal/Pack200StreamsTest.java index 2b1d9f10aa..a9cbfc445c 100644 --- a/org.jacoco.core.test/src/org/jacoco/core/internal/Pack200StreamsTest.java +++ b/org.jacoco.core.test/src/org/jacoco/core/internal/Pack200StreamsTest.java @@ -61,6 +61,17 @@ public void testPack() throws IOException { assertNull(zipin.getNextEntry()); } + @Test + public void pack_should_throw_IOException_when_can_not_write_to_OutputStream() { + final OutputStream outputStream = new BrokenOutputStream(); + try { + Pack200Streams.pack(new byte[0], outputStream); + fail("expected exception"); + } catch (IOException e) { + assertEquals("fake broken output stream", e.getMessage()); + } + } + @Test public void testUnpack() throws IOException { ByteArrayOutputStream jarbuffer = new ByteArrayOutputStream(); @@ -83,6 +94,17 @@ public void testUnpack() throws IOException { assertNull(zipin.getNextEntry()); } + @Test + public void unpack_should_throw_IOException_when_can_not_read_from_InputStream() { + final InputStream inputStream = new BrokenInputStream(); + try { + Pack200Streams.unpack(inputStream); + fail("expected exception"); + } catch (IOException e) { + assertEquals("fake broken input stream", e.getMessage()); + } + } + static class NoCloseInputStream extends FilterInputStream { public NoCloseInputStream(InputStream in) { super(in); @@ -105,4 +127,18 @@ public void close() throws IOException { } } + private static class BrokenInputStream extends InputStream { + @Override + public int read() throws IOException { + throw new IOException("fake broken input stream"); + } + } + + private static class BrokenOutputStream extends OutputStream { + @Override + public void write(int b) throws IOException { + throw new IOException("fake broken output stream"); + } + } + } From a6dc17a186edd4974391b7c708d75469570773af Mon Sep 17 00:00:00 2001 From: Evgeny Mandrikov Date: Fri, 13 Dec 2019 13:17:50 +0100 Subject: [PATCH 3/8] (WIP) use reflection in Pack200StreamsTest To avoid compilation errors with JDK 14, where Pack200 not available. --- .../core/internal/Pack200StreamsTest.java | 22 ++++++++++++------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/org.jacoco.core.test/src/org/jacoco/core/internal/Pack200StreamsTest.java b/org.jacoco.core.test/src/org/jacoco/core/internal/Pack200StreamsTest.java index a9cbfc445c..05b39497fe 100644 --- a/org.jacoco.core.test/src/org/jacoco/core/internal/Pack200StreamsTest.java +++ b/org.jacoco.core.test/src/org/jacoco/core/internal/Pack200StreamsTest.java @@ -25,7 +25,6 @@ import java.io.OutputStream; import java.util.jar.JarInputStream; import java.util.jar.JarOutputStream; -import java.util.jar.Pack200; import java.util.zip.ZipEntry; import java.util.zip.ZipInputStream; import java.util.zip.ZipOutputStream; @@ -39,7 +38,7 @@ public class Pack200StreamsTest { @Test - public void testPack() throws IOException { + public void pack_should_pack() throws Exception { ByteArrayOutputStream jarbuffer = new ByteArrayOutputStream(); ZipOutputStream zipout = new ZipOutputStream(jarbuffer); zipout.putNextEntry(new ZipEntry("Test.class")); @@ -51,9 +50,13 @@ public void testPack() throws IOException { new NoCloseOutputStream(pack200buffer)); jarbuffer.reset(); - Pack200.newUnpacker().unpack( - new ByteArrayInputStream(pack200buffer.toByteArray()), - new JarOutputStream(jarbuffer)); + final Object unpacker = Class.forName("java.util.jar.Pack200") + .getMethod("newUnpacker").invoke(null); + Class.forName("java.util.jar.Pack200$Unpacker") + .getMethod("unpack", InputStream.class, JarOutputStream.class) + .invoke(unpacker, + new ByteArrayInputStream(pack200buffer.toByteArray()), + new JarOutputStream(jarbuffer)); ZipInputStream zipin = new ZipInputStream( new ByteArrayInputStream(jarbuffer.toByteArray())); @@ -73,7 +76,7 @@ public void pack_should_throw_IOException_when_can_not_write_to_OutputStream() { } @Test - public void testUnpack() throws IOException { + public void unpack_should_unpack() throws Exception { ByteArrayOutputStream jarbuffer = new ByteArrayOutputStream(); ZipOutputStream zipout = new ZipOutputStream(jarbuffer); zipout.putNextEntry(new ZipEntry("Test.class")); @@ -81,8 +84,11 @@ public void testUnpack() throws IOException { zipout.finish(); ByteArrayOutputStream pack200buffer = new ByteArrayOutputStream(); - Pack200.newPacker() - .pack(new JarInputStream( + final Object packer = Class.forName("java.util.jar.Pack200") + .getMethod("newPacker").invoke(null); + Class.forName("java.util.jar.Pack200$Packer") + .getMethod("pack", JarInputStream.class, OutputStream.class) + .invoke(packer, new JarInputStream( new ByteArrayInputStream(jarbuffer.toByteArray())), pack200buffer); From d8316f4bb16b2aa1adfe9d2a4cb152bc0ff97263 Mon Sep 17 00:00:00 2001 From: Evgeny Mandrikov Date: Fri, 13 Dec 2019 14:45:33 +0100 Subject: [PATCH 4/8] (WIP) add unit tests for the case when Pack200 not available in JDK --- .../core/internal/Pack200StreamsTest.java | 38 +++++++++++++++++++ 1 file changed, 38 insertions(+) diff --git a/org.jacoco.core.test/src/org/jacoco/core/internal/Pack200StreamsTest.java b/org.jacoco.core.test/src/org/jacoco/core/internal/Pack200StreamsTest.java index 05b39497fe..f3481e942e 100644 --- a/org.jacoco.core.test/src/org/jacoco/core/internal/Pack200StreamsTest.java +++ b/org.jacoco.core.test/src/org/jacoco/core/internal/Pack200StreamsTest.java @@ -14,6 +14,7 @@ import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNull; +import static org.junit.Assert.assertTrue; import static org.junit.Assert.fail; import java.io.ByteArrayInputStream; @@ -31,6 +32,7 @@ import org.jacoco.core.test.TargetLoader; import org.junit.Test; +import org.junit.internal.AssumptionViolatedException; /** * Unit tests for {@link Pack200Streams}. @@ -75,6 +77,24 @@ public void pack_should_throw_IOException_when_can_not_write_to_OutputStream() { } } + @Test + public void pack_should_throw_IOException_when_Pack200_not_available_in_JDK() { + try { + Class.forName("java.util.jar.Pack200"); + throw new AssumptionViolatedException( + "this test requires JDK without Pack200"); + } catch (ClassNotFoundException ignore) { + } + + try { + Pack200Streams.pack(new byte[0], new ByteArrayOutputStream()); + fail("expected exception"); + } catch (IOException e) { + assertNull(e.getMessage()); + assertTrue(e.getCause() instanceof ClassNotFoundException); + } + } + @Test public void unpack_should_unpack() throws Exception { ByteArrayOutputStream jarbuffer = new ByteArrayOutputStream(); @@ -111,6 +131,24 @@ public void unpack_should_throw_IOException_when_can_not_read_from_InputStream() } } + @Test + public void unpack_should_throw_IOException_when_Pack200_not_available_in_JDK() { + try { + Class.forName("java.util.jar.Pack200"); + throw new AssumptionViolatedException( + "this test requires JDK without Pack200"); + } catch (ClassNotFoundException ignore) { + } + + try { + Pack200Streams.unpack(new ByteArrayInputStream(new byte[0])); + fail("expected exception"); + } catch (IOException e) { + assertNull(e.getMessage()); + assertTrue(e.getCause() instanceof ClassNotFoundException); + } + } + static class NoCloseInputStream extends FilterInputStream { public NoCloseInputStream(InputStream in) { super(in); From 18e4263d68cfda0dc82ef1080bfdb70d11c13fcf Mon Sep 17 00:00:00 2001 From: Evgeny Mandrikov Date: Fri, 13 Dec 2019 15:06:49 +0100 Subject: [PATCH 5/8] (WIP) use reflection in Pack200Streams To avoid compilation errors with JDK 14, where Pack200 not available. --- .../core/internal/Pack200StreamsTest.java | 7 +++- .../jacoco/core/internal/Pack200Streams.java | 41 +++++++++++++++++-- 2 files changed, 43 insertions(+), 5 deletions(-) diff --git a/org.jacoco.core.test/src/org/jacoco/core/internal/Pack200StreamsTest.java b/org.jacoco.core.test/src/org/jacoco/core/internal/Pack200StreamsTest.java index f3481e942e..b0b2303239 100644 --- a/org.jacoco.core.test/src/org/jacoco/core/internal/Pack200StreamsTest.java +++ b/org.jacoco.core.test/src/org/jacoco/core/internal/Pack200StreamsTest.java @@ -73,7 +73,9 @@ public void pack_should_throw_IOException_when_can_not_write_to_OutputStream() { Pack200Streams.pack(new byte[0], outputStream); fail("expected exception"); } catch (IOException e) { - assertEquals("fake broken output stream", e.getMessage()); + assertTrue(e.getCause() instanceof IOException); + assertEquals("fake broken output stream", + e.getCause().getMessage()); } } @@ -127,7 +129,8 @@ public void unpack_should_throw_IOException_when_can_not_read_from_InputStream() Pack200Streams.unpack(inputStream); fail("expected exception"); } catch (IOException e) { - assertEquals("fake broken input stream", e.getMessage()); + assertTrue(e.getCause() instanceof IOException); + assertEquals("fake broken input stream", e.getCause().getMessage()); } } diff --git a/org.jacoco.core/src/org/jacoco/core/internal/Pack200Streams.java b/org.jacoco.core/src/org/jacoco/core/internal/Pack200Streams.java index 96b0596006..a5dcd9a8f0 100644 --- a/org.jacoco.core/src/org/jacoco/core/internal/Pack200Streams.java +++ b/org.jacoco.core/src/org/jacoco/core/internal/Pack200Streams.java @@ -18,9 +18,9 @@ import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; +import java.lang.reflect.InvocationTargetException; import java.util.jar.JarInputStream; import java.util.jar.JarOutputStream; -import java.util.jar.Pack200; /** * Internal wrapper for the weird Pack200 Java API to allow usage with streams. @@ -40,7 +40,22 @@ public static InputStream unpack(final InputStream input) throws IOException { final ByteArrayOutputStream buffer = new ByteArrayOutputStream(); final JarOutputStream jar = new JarOutputStream(buffer); - Pack200.newUnpacker().unpack(new NoCloseInput(input), jar); + try { + final Object unpacker = Class.forName("java.util.jar.Pack200") + .getMethod("newUnpacker").invoke(null); + Class.forName("java.util.jar.Pack200$Unpacker") + .getMethod("unpack", InputStream.class, + JarOutputStream.class) + .invoke(unpacker, new NoCloseInput(input), jar); + } catch (ClassNotFoundException e) { + throw newIOException(e); + } catch (NoSuchMethodException e) { + throw newIOException(e); + } catch (IllegalAccessException e) { + throw newIOException(e); + } catch (InvocationTargetException e) { + throw newIOException(e.getCause()); + } jar.finish(); return new ByteArrayInputStream(buffer.toByteArray()); } @@ -59,7 +74,27 @@ public static void pack(final byte[] source, final OutputStream output) throws IOException { final JarInputStream jar = new JarInputStream( new ByteArrayInputStream(source)); - Pack200.newPacker().pack(jar, output); + try { + final Object packer = Class.forName("java.util.jar.Pack200") + .getMethod("newPacker").invoke(null); + Class.forName("java.util.jar.Pack200$Packer") + .getMethod("pack", JarInputStream.class, OutputStream.class) + .invoke(packer, jar, output); + } catch (ClassNotFoundException e) { + throw newIOException(e); + } catch (NoSuchMethodException e) { + throw newIOException(e); + } catch (IllegalAccessException e) { + throw newIOException(e); + } catch (InvocationTargetException e) { + throw newIOException(e.getCause()); + } + } + + private static IOException newIOException(final Throwable cause) { + final IOException exception = new IOException(); + exception.initCause(cause); + return exception; } private static class NoCloseInput extends FilterInputStream { From 0b373ff02ee4f78ef910f9c2db49974d25a2de2a Mon Sep 17 00:00:00 2001 From: Evgeny Mandrikov Date: Fri, 13 Dec 2019 15:40:28 +0100 Subject: [PATCH 6/8] (WIP) tests that require Pack200 should be disabled on JDKs without it --- .../jacoco/core/analysis/AnalyzerTest.java | 8 ++++++ .../jacoco/core/instr/InstrumenterTest.java | 8 ++++++ .../internal/ContentTypeDetectorTest.java | 8 ++++++ .../core/internal/Pack200StreamsTest.java | 28 +++++++++++++++++++ 4 files changed, 52 insertions(+) diff --git a/org.jacoco.core.test/src/org/jacoco/core/analysis/AnalyzerTest.java b/org.jacoco.core.test/src/org/jacoco/core/analysis/AnalyzerTest.java index 72cd57c47a..ea1d71438c 100644 --- a/org.jacoco.core.test/src/org/jacoco/core/analysis/AnalyzerTest.java +++ b/org.jacoco.core.test/src/org/jacoco/core/analysis/AnalyzerTest.java @@ -42,6 +42,7 @@ import org.junit.Before; import org.junit.Rule; import org.junit.Test; +import org.junit.internal.AssumptionViolatedException; import org.junit.rules.TemporaryFolder; import org.objectweb.asm.ClassWriter; import org.objectweb.asm.Opcodes; @@ -293,6 +294,13 @@ public void testAnalyzeAll_BrokenGZ() { @Test public void testAnalyzeAll_Pack200() throws IOException { + try { + Class.forName("java.util.jar.Pack200"); + } catch (ClassNotFoundException e) { + throw new AssumptionViolatedException( + "this test requires JDK with Pack200"); + } + final ByteArrayOutputStream zipbuffer = new ByteArrayOutputStream(); final ZipOutputStream zip = new ZipOutputStream(zipbuffer); zip.putNextEntry( diff --git a/org.jacoco.core.test/src/org/jacoco/core/instr/InstrumenterTest.java b/org.jacoco.core.test/src/org/jacoco/core/instr/InstrumenterTest.java index 1f83c0ca9e..1288a8ea73 100644 --- a/org.jacoco.core.test/src/org/jacoco/core/instr/InstrumenterTest.java +++ b/org.jacoco.core.test/src/org/jacoco/core/instr/InstrumenterTest.java @@ -40,6 +40,7 @@ import org.jacoco.core.test.TargetLoader; import org.junit.Before; import org.junit.Test; +import org.junit.internal.AssumptionViolatedException; import org.objectweb.asm.ClassWriter; import org.objectweb.asm.MethodVisitor; import org.objectweb.asm.Opcodes; @@ -396,6 +397,13 @@ public void testInstrumentAll_BrokenGZ() { @Test public void testInstrumentAll_Pack200() throws IOException { + try { + Class.forName("java.util.jar.Pack200"); + } catch (ClassNotFoundException e) { + throw new AssumptionViolatedException( + "this test requires JDK with Pack200"); + } + ByteArrayOutputStream jarbuffer = new ByteArrayOutputStream(); ZipOutputStream zipout = new ZipOutputStream(jarbuffer); zipout.putNextEntry(new ZipEntry("Test.class")); diff --git a/org.jacoco.core.test/src/org/jacoco/core/internal/ContentTypeDetectorTest.java b/org.jacoco.core.test/src/org/jacoco/core/internal/ContentTypeDetectorTest.java index 2e78ddb49d..6759412c51 100644 --- a/org.jacoco.core.test/src/org/jacoco/core/internal/ContentTypeDetectorTest.java +++ b/org.jacoco.core.test/src/org/jacoco/core/internal/ContentTypeDetectorTest.java @@ -25,6 +25,7 @@ import org.jacoco.core.test.TargetLoader; import org.junit.Test; +import org.junit.internal.AssumptionViolatedException; /** * Unit tests for {@link ContentTypeDetector}. @@ -216,6 +217,13 @@ public void testZipFile() throws IOException { @Test public void testPack200File() throws IOException { + try { + Class.forName("java.util.jar.Pack200"); + } catch (ClassNotFoundException e) { + throw new AssumptionViolatedException( + "this test requires JDK with Pack200"); + } + final ByteArrayOutputStream zipbuffer = new ByteArrayOutputStream(); final ZipOutputStream zip = new ZipOutputStream(zipbuffer); zip.putNextEntry(new ZipEntry("hello.txt")); diff --git a/org.jacoco.core.test/src/org/jacoco/core/internal/Pack200StreamsTest.java b/org.jacoco.core.test/src/org/jacoco/core/internal/Pack200StreamsTest.java index b0b2303239..9a8e0e63e8 100644 --- a/org.jacoco.core.test/src/org/jacoco/core/internal/Pack200StreamsTest.java +++ b/org.jacoco.core.test/src/org/jacoco/core/internal/Pack200StreamsTest.java @@ -41,6 +41,13 @@ public class Pack200StreamsTest { @Test public void pack_should_pack() throws Exception { + try { + Class.forName("java.util.jar.Pack200"); + } catch (ClassNotFoundException e) { + throw new AssumptionViolatedException( + "this test requires JDK with Pack200"); + } + ByteArrayOutputStream jarbuffer = new ByteArrayOutputStream(); ZipOutputStream zipout = new ZipOutputStream(jarbuffer); zipout.putNextEntry(new ZipEntry("Test.class")); @@ -68,6 +75,13 @@ public void pack_should_pack() throws Exception { @Test public void pack_should_throw_IOException_when_can_not_write_to_OutputStream() { + try { + Class.forName("java.util.jar.Pack200"); + } catch (ClassNotFoundException e) { + throw new AssumptionViolatedException( + "this test requires JDK with Pack200"); + } + final OutputStream outputStream = new BrokenOutputStream(); try { Pack200Streams.pack(new byte[0], outputStream); @@ -99,6 +113,13 @@ public void pack_should_throw_IOException_when_Pack200_not_available_in_JDK() { @Test public void unpack_should_unpack() throws Exception { + try { + Class.forName("java.util.jar.Pack200"); + } catch (ClassNotFoundException e) { + throw new AssumptionViolatedException( + "this test requires JDK with Pack200"); + } + ByteArrayOutputStream jarbuffer = new ByteArrayOutputStream(); ZipOutputStream zipout = new ZipOutputStream(jarbuffer); zipout.putNextEntry(new ZipEntry("Test.class")); @@ -124,6 +145,13 @@ public void unpack_should_unpack() throws Exception { @Test public void unpack_should_throw_IOException_when_can_not_read_from_InputStream() { + try { + Class.forName("java.util.jar.Pack200"); + } catch (ClassNotFoundException e) { + throw new AssumptionViolatedException( + "this test requires JDK with Pack200"); + } + final InputStream inputStream = new BrokenInputStream(); try { Pack200Streams.unpack(inputStream); From 3825b05a8b3837824d2194befe7d2fc652f8e976 Mon Sep 17 00:00:00 2001 From: Evgeny Mandrikov Date: Tue, 17 Dec 2019 22:37:43 +0100 Subject: [PATCH 7/8] (WIP) suppress false-positive Eclipse warnings --- .../src/org/jacoco/core/internal/Pack200Streams.java | 2 ++ 1 file changed, 2 insertions(+) diff --git a/org.jacoco.core/src/org/jacoco/core/internal/Pack200Streams.java b/org.jacoco.core/src/org/jacoco/core/internal/Pack200Streams.java index a5dcd9a8f0..5750570646 100644 --- a/org.jacoco.core/src/org/jacoco/core/internal/Pack200Streams.java +++ b/org.jacoco.core/src/org/jacoco/core/internal/Pack200Streams.java @@ -36,6 +36,7 @@ public final class Pack200Streams { * @throws IOException * in case of errors with the streams */ + @SuppressWarnings("resource") public static InputStream unpack(final InputStream input) throws IOException { final ByteArrayOutputStream buffer = new ByteArrayOutputStream(); @@ -70,6 +71,7 @@ public static InputStream unpack(final InputStream input) * @throws IOException * in case of errors with the streams */ + @SuppressWarnings("resource") public static void pack(final byte[] source, final OutputStream output) throws IOException { final JarInputStream jar = new JarInputStream( From 049d3f122fd3ab416bab96fe732634fb69903718 Mon Sep 17 00:00:00 2001 From: Evgeny Mandrikov Date: Tue, 17 Dec 2019 22:48:06 +0100 Subject: [PATCH 8/8] (WIP) update changelog --- org.jacoco.doc/docroot/doc/changes.html | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/org.jacoco.doc/docroot/doc/changes.html b/org.jacoco.doc/docroot/doc/changes.html index 37ac81c5e9..be195d9cad 100644 --- a/org.jacoco.doc/docroot/doc/changes.html +++ b/org.jacoco.doc/docroot/doc/changes.html @@ -20,6 +20,13 @@

Change History

Snapshot Build @qualified.bundle.version@ (@build.date@)

+

Non-functional Changes

+
    +
  • Support for Pack200 was removed in JDK 14. JaCoCo will now throw a detailed + exception when Pack200 archives are processed with the latest JDKs + (GitHub #984).
  • +
+

Release 0.8.5 (2019/10/11)

New Features