From 226764bf51b113e36a3b2657ec3257ebca5fab29 Mon Sep 17 00:00:00 2001 From: adripo <26493496+adripo@users.noreply.github.com> Date: Thu, 30 Oct 2025 21:55:33 +0000 Subject: [PATCH] feat(jdk14): add demo for JEP 367 - Remove the Pack200 Tools and API --- .../org/javademos/init/Java14DemoLoader.java | 2 + .../javademos/java14/jep367/Pack200Demo.java | 40 +++++++++++++++++++ src/main/resources/JDK14Info.json | 8 ++++ 3 files changed, 50 insertions(+) create mode 100644 src/main/java/org/javademos/java14/jep367/Pack200Demo.java diff --git a/src/main/java/org/javademos/init/Java14DemoLoader.java b/src/main/java/org/javademos/init/Java14DemoLoader.java index 514ad8c..f3eb259 100644 --- a/src/main/java/org/javademos/init/Java14DemoLoader.java +++ b/src/main/java/org/javademos/init/Java14DemoLoader.java @@ -10,6 +10,7 @@ import org.javademos.java14.jep359.RecordsPreviewDemo; import org.javademos.java14.jep361.SwitchExpressionsDemo; import org.javademos.java14.jep365.ZGarbageCollectorOnWindows; +import org.javademos.java14.jep367.Pack200Demo; import org.javademos.java14.jep368.TextBlockSecondPreviewDemo; import org.javademos.java14.jep370.ForeignMemoryAccessDemo; @@ -25,6 +26,7 @@ public void loadDemos(Map demos) { demos.put(359, new RecordsPreviewDemo()); demos.put(361, new SwitchExpressionsDemo()); demos.put(365, new ZGarbageCollectorOnWindows()); + demos.put(367, new Pack200Demo()); demos.put(368, new TextBlockSecondPreviewDemo()); demos.put(370, new ForeignMemoryAccessDemo()); } diff --git a/src/main/java/org/javademos/java14/jep367/Pack200Demo.java b/src/main/java/org/javademos/java14/jep367/Pack200Demo.java new file mode 100644 index 0000000..363dae5 --- /dev/null +++ b/src/main/java/org/javademos/java14/jep367/Pack200Demo.java @@ -0,0 +1,40 @@ +package org.javademos.java14.jep367; + +import org.javademos.commons.IDemo; + +/// Demo for JDK 14 feature JEP 367 - Remove the Pack200 Tools and API. +/// +/// JEP 367 removed the Pack200 API and tools from the JDK. This demo documents the +/// removal and shows a small runtime check that the `java.util.jar.Pack200` class is +/// no longer available on the classpath of modern JDKs. Since Pack200 was removed, +/// attempting to reference the API may fail at runtime (NoClassDefFoundError) when +/// running on a JDK that no longer contains it. +/// +/// JEP link: https://openjdk.org/jeps/367 +/// +/// @author adripo +public class Pack200Demo implements IDemo { + + @Override + public void demo() { + info(367); + + System.out.println("Checking availability of Pack200 classes at runtime..."); + + try { + // Try to load the Pack200 class reflectively. On JDKs where Pack200 + // has been removed this will throw ClassNotFoundException. + Class.forName("java.util.jar.Pack200"); + // If the class is present, show a short note: + System.out.println("java.util.jar.Pack200 is present on this JVM. Pack200 APIs are available."); + } catch (ClassNotFoundException | NoClassDefFoundError ex) { + // Expected on JDKs that removed Pack200 (JDK 14 removal) + System.out.println("Pack200 classes are NOT available on this JVM (removed by JEP 367)."); + System.out.println("If you still need Pack200 functionality consider using an external library or alternate packaging/compression."); + System.out.println("Pack200 was deprecated for removal earlier and removed by JEP 367 in JDK 14."); + } + + System.out.println(); + } + +} diff --git a/src/main/resources/JDK14Info.json b/src/main/resources/JDK14Info.json index 79f5e59..b9be40d 100644 --- a/src/main/resources/JDK14Info.json +++ b/src/main/resources/JDK14Info.json @@ -39,6 +39,14 @@ "link": true, "code": false }, + { + "jep": 367, + "jdk": 14, + "name": "JEP 367 - Remove the Pack200 Tools and API", + "dscr": "Removes the Pack200 tools and API from the JDK. This entry documents the removal and points users to alternatives.", + "link": false, + "code": true + }, { "jep": 368, "jdk": 14,