Add java8-to-25 module: legacy Java 8 app run on JDK 8, 17 and 25, tool coverage, JVM flags, libraries, OpenRewrite and the fixed version

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_017ic4b6vDJ5fWY5uEZaJFNi
This commit is contained in:
Claude
2026-12-03 23:45:00 +05:30
parent 3502fd7804
commit 94f8a0e003
82 changed files with 2152 additions and 0 deletions
+51
View File
@@ -0,0 +1,51 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.ankurm</groupId>
<artifactId>fixed-app</artifactId>
<version>1.0</version>
<properties>
<maven.compiler.release>25</maven.compiler.release>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<dependencies>
<!-- JAXB: API plus an implementation. Both left the JDK in Java 11. -->
<dependency>
<groupId>jakarta.xml.bind</groupId>
<artifactId>jakarta.xml.bind-api</artifactId>
<version>4.0.5</version>
</dependency>
<dependency>
<groupId>org.glassfish.jaxb</groupId>
<artifactId>jaxb-runtime</artifactId>
<version>4.0.9</version>
<scope>runtime</scope>
</dependency>
<!-- JAX-WS: jaxws-rt brings the API (jakarta.xml.ws, jakarta.jws) and the runtime. -->
<dependency>
<groupId>com.sun.xml.ws</groupId>
<artifactId>jaxws-rt</artifactId>
<version>4.0.5</version>
</dependency>
<!-- Nashorn, now a standalone OpenJDK project. -->
<dependency>
<groupId>org.openjdk.nashorn</groupId>
<artifactId>nashorn-core</artifactId>
<version>15.7</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.16.0</version>
</plugin>
</plugins>
</build>
</project>
@@ -0,0 +1,29 @@
package com.ankurm.fixed;
import java.util.concurrent.Callable;
/** Same steps as the legacy App, fixed for Java 25. */
public final class App {
public static void main(String[] args) {
System.out.println("running on java.version " + System.getProperty("java.version"));
step("jaxb", () -> OrderXml.toXml(new Order("A-1", 12)));
step("jaxws", SoapCheck::publishAndReadWsdl);
step("base64", () -> Tokens.encode("ankur".getBytes("UTF-8")));
step("nashorn", () -> Rules.discount(12));
step("version", () -> "major=" + JavaVersion.major());
step("classloader", () -> "classpath found=" + PluginScanner.classpathEntries());
step("reflection", () -> "list size=" + Peek.sized(32).size() + " (capacity no longer read)");
step("securitymanager", Guard::runIsolated);
step("thread.stop", Watchdog::kill);
System.out.println(Report.lines());
System.exit(0);
}
private static void step(String name, Callable<Object> work) {
try {
System.out.println("[ok] " + name + ": " + work.call());
} catch (Throwable t) {
System.out.println("[FAIL] " + name + ": " + t);
}
}
}
@@ -0,0 +1,22 @@
package com.ankurm.fixed;
import java.nio.file.Paths;
/**
* There is no in-JVM replacement for the Security Manager. One option for untrusted or
* badly behaved code is a separate process: its exit cannot take the host down.
*/
public final class Guard {
public static String runIsolated() throws Exception {
String java = Paths.get(System.getProperty("java.home"), "bin", "java").toString();
Process child = new ProcessBuilder(java, "-cp", System.getProperty("java.class.path"),
Plugin.class.getName()).inheritIO().start();
return "child exit code " + child.waitFor() + ", host still running";
}
public static final class Plugin {
public static void main(String[] args) {
System.exit(3);
}
}
}
@@ -0,0 +1,8 @@
package com.ankurm.fixed;
/** Ask the runtime instead of parsing a string. Runtime.version() exists since Java 9. */
public final class JavaVersion {
public static int major() {
return Runtime.version().feature();
}
}
@@ -0,0 +1,20 @@
package com.ankurm.fixed;
import jakarta.xml.bind.annotation.XmlAccessType;
import jakarta.xml.bind.annotation.XmlAccessorType;
import jakarta.xml.bind.annotation.XmlRootElement;
/** Same bean; only the import prefix changed, javax.xml.bind to jakarta.xml.bind. */
@XmlRootElement(name = "order")
@XmlAccessorType(XmlAccessType.FIELD)
public class Order {
public String id;
public int quantity;
public Order() { }
public Order(String id, int quantity) {
this.id = id;
this.quantity = quantity;
}
}
@@ -0,0 +1,15 @@
package com.ankurm.fixed;
import java.io.StringWriter;
import jakarta.xml.bind.JAXBContext;
import jakarta.xml.bind.Marshaller;
public final class OrderXml {
public static String toXml(Order order) throws Exception {
Marshaller m = JAXBContext.newInstance(Order.class).createMarshaller();
m.setProperty(Marshaller.JAXB_FRAGMENT, Boolean.TRUE);
StringWriter out = new StringWriter();
m.marshal(order, out);
return out.toString();
}
}
@@ -0,0 +1,13 @@
package com.ankurm.fixed;
import java.util.ArrayList;
/**
* There is no public API for an ArrayList's internal capacity, so the fix is to stop asking.
* If your code needs the number, it has to own it.
*/
public final class Peek {
public static ArrayList<String> sized(int capacity) {
return new ArrayList<>(capacity);
}
}
@@ -0,0 +1,11 @@
package com.ankurm.fixed;
import java.io.File;
/** The class path is a system property; the loader's type is an implementation detail. */
public final class PluginScanner {
public static int classpathEntries() {
String[] entries = System.getProperty("java.class.path").split(File.pathSeparator);
return entries.length > 0 ? 1 : 0;
}
}
@@ -0,0 +1,32 @@
package com.ankurm.fixed;
import java.nio.charset.StandardCharsets;
import java.text.DecimalFormat;
import java.text.DecimalFormatSymbols;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.Locale;
/** Pin every format that another system reads. Do not rely on locale data staying put. */
public final class Report {
public static String lines() {
LocalDateTime when = LocalDateTime.of(2026, 3, 5, 14, 30);
DateTimeFormatter us = DateTimeFormatter.ofPattern("MMM d, yyyy h:mm a", Locale.US);
DateTimeFormatter de = DateTimeFormatter.ofPattern("EEEE, d. MMMM yyyy", Locale.GERMANY);
DecimalFormat inr = new DecimalFormat("'Rs.'#,##0.00", DecimalFormatSymbols.getInstance(Locale.US));
return "date(en_US) = " + escape(us.format(when)) + "\n"
+ "date(de_DE) = " + escape(de.format(when)) + "\n"
+ "money(en_IN) = " + escape(inr.format(1234567.5)) + "\n"
+ "charset used = " + StandardCharsets.UTF_8 + "\n"
+ "rupee as bytes = " + "₹".getBytes(StandardCharsets.UTF_8).length + " byte(s)";
}
static String escape(String s) {
StringBuilder b = new StringBuilder();
for (char ch : s.toCharArray()) {
if (ch < 127) b.append(ch);
else b.append(String.format("\\u%04X", (int) ch));
}
return b.toString();
}
}
@@ -0,0 +1,13 @@
package com.ankurm.fixed;
import javax.script.ScriptEngine;
import javax.script.ScriptEngineManager;
/** Unchanged code: the engine now comes from the nashorn-core dependency. */
public final class Rules {
public static Object discount(int quantity) throws Exception {
ScriptEngine js = new ScriptEngineManager().getEngineByName("nashorn");
js.put("quantity", quantity);
return js.eval("quantity > 10 ? 'BULK' : 'RETAIL'");
}
}
@@ -0,0 +1,19 @@
package com.ankurm.fixed;
import java.io.InputStream;
import java.net.URL;
import java.util.Scanner;
import jakarta.xml.ws.Endpoint;
public final class SoapCheck {
public static String publishAndReadWsdl() throws Exception {
String address = "http://127.0.0.1:18099/status";
Endpoint endpoint = Endpoint.publish(address, new StatusService());
try (InputStream in = new URL(address + "?wsdl").openStream()) {
String wsdl = new Scanner(in, "UTF-8").useDelimiter("\\A").next();
return wsdl.contains("name=\"StatusServiceService\"") ? "WSDL served" : "unexpected WSDL";
} finally {
endpoint.stop();
}
}
}
@@ -0,0 +1,13 @@
package com.ankurm.fixed;
import jakarta.jws.WebMethod;
import jakarta.jws.WebService;
/** Same service; javax.jws became jakarta.jws. */
@WebService
public class StatusService {
@WebMethod
public String status() {
return "UP";
}
}
@@ -0,0 +1,10 @@
package com.ankurm.fixed;
import java.util.Base64;
public final class Tokens {
/** getMimeEncoder() wraps at 76 characters like sun.misc did; getEncoder() does not wrap. */
public static String encode(byte[] raw) {
return Base64.getMimeEncoder().encodeToString(raw);
}
}
@@ -0,0 +1,22 @@
package com.ankurm.fixed;
/** Cooperative cancellation: interrupt, and the worker must honour the interrupt. */
public final class Watchdog {
public static String kill() throws InterruptedException {
Thread worker = new Thread(() -> {
while (!Thread.currentThread().isInterrupted()) {
try {
Thread.sleep(50);
} catch (InterruptedException e) {
Thread.currentThread().interrupt(); // restore the flag so the loop ends
}
}
});
worker.setDaemon(true);
worker.start();
Thread.sleep(100);
worker.interrupt();
worker.join(1000);
return worker.isAlive() ? "still alive" : "stopped";
}
}