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:
@@ -0,0 +1,20 @@
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/** Which javax.* packages does this JDK still contain, and which Java EE ones are gone? */
|
||||
public class JavaxMap {
|
||||
public static void main(String[] args) {
|
||||
List<String> inJdk = new ArrayList<>();
|
||||
ModuleLayer.boot().modules().forEach(m -> m.getPackages().stream()
|
||||
.filter(p -> p.startsWith("javax.") && m.getDescriptor().exports().stream()
|
||||
.anyMatch(e -> e.source().equals(p) && !e.isQualified()))
|
||||
.forEach(inJdk::add));
|
||||
System.out.println("exported javax.* packages in this JDK: " + inJdk.size());
|
||||
for (String p : new String[] {"javax.sql", "javax.crypto", "javax.net.ssl", "javax.naming",
|
||||
"javax.management", "javax.script", "javax.swing", "javax.xml.parsers", "javax.transaction.xa",
|
||||
"javax.annotation.processing", "javax.xml.bind", "javax.xml.ws", "javax.jws", "javax.activation",
|
||||
"javax.annotation", "javax.transaction", "javax.servlet", "javax.persistence", "javax.validation"}) {
|
||||
System.out.printf(" %-28s %s%n", p, inJdk.contains(p) ? "in the JDK, keep javax" : "not in the JDK");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
import org.objectweb.asm.ClassReader;
|
||||
|
||||
/** Reads its own class file, which javac 25 writes as major version 69. */
|
||||
public class AsmRead {
|
||||
public static void main(String[] args) throws Exception {
|
||||
ClassReader r = new ClassReader(AsmRead.class.getResourceAsStream("AsmRead.class"));
|
||||
System.out.println("parsed " + r.getClassName());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
public class Hello {
|
||||
public static void main(String[] args) {
|
||||
System.out.println("hello from a Java 25 class");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
@lombok.Getter
|
||||
@lombok.AllArgsConstructor
|
||||
public class LombokBean {
|
||||
private final String name;
|
||||
|
||||
public static void main(String[] args) {
|
||||
System.out.println("getter says " + new LombokBean("ankur").getName());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
public class MockDemo {
|
||||
public static class PriceService {
|
||||
public int price() { return 100; }
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
PriceService s = mock(PriceService.class);
|
||||
when(s.price()).thenReturn(42);
|
||||
System.out.println("mocked price " + s.price());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
package app;
|
||||
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
|
||||
/** A minimal Spring Boot 2.7 (javax era) app: component scanning reads class files with ASM. */
|
||||
@SpringBootApplication
|
||||
public class DemoApp {
|
||||
public static void main(String[] args) {
|
||||
SpringApplication.run(DemoApp.class, args).close();
|
||||
System.out.println("context started");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
package app;
|
||||
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
@Component
|
||||
public class Greeter { }
|
||||
@@ -0,0 +1,17 @@
|
||||
<?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>boot27-classpath</artifactId>
|
||||
<version>1.0</version>
|
||||
<packaging>pom</packaging>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter</artifactId>
|
||||
<version>2.7.18</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</project>
|
||||
@@ -0,0 +1,27 @@
|
||||
<?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>mixed-namespaces</artifactId>
|
||||
<version>1.0</version>
|
||||
<properties>
|
||||
<maven.compiler.release>25</maven.compiler.release>
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
</properties>
|
||||
<dependencies>
|
||||
<!-- A half-finished migration: old annotations still on the beans ... -->
|
||||
<dependency>
|
||||
<groupId>javax.xml.bind</groupId>
|
||||
<artifactId>jaxb-api</artifactId>
|
||||
<version>2.3.1</version>
|
||||
</dependency>
|
||||
<!-- ... but the new jakarta runtime doing the work. -->
|
||||
<dependency>
|
||||
<groupId>org.glassfish.jaxb</groupId>
|
||||
<artifactId>jaxb-runtime</artifactId>
|
||||
<version>4.0.9</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</project>
|
||||
@@ -0,0 +1,16 @@
|
||||
import java.io.StringWriter;
|
||||
import jakarta.xml.bind.JAXBContext;
|
||||
import javax.xml.bind.annotation.XmlRootElement;
|
||||
|
||||
public class Mixed {
|
||||
@XmlRootElement(name = "order")
|
||||
public static class Order {
|
||||
public String id = "A-1";
|
||||
}
|
||||
|
||||
public static void main(String[] args) throws Exception {
|
||||
StringWriter out = new StringWriter();
|
||||
JAXBContext.newInstance(Order.class).createMarshaller().marshal(new Order(), out);
|
||||
System.out.println(out);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,67 @@
|
||||
import java.io.FileInputStream;
|
||||
import java.security.KeyStore;
|
||||
import java.security.Security;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import javax.net.ssl.KeyManagerFactory;
|
||||
import javax.net.ssl.SSLContext;
|
||||
import javax.net.ssl.SSLParameters;
|
||||
import javax.net.ssl.SSLServerSocket;
|
||||
import javax.net.ssl.SSLSocket;
|
||||
import javax.net.ssl.TrustManagerFactory;
|
||||
|
||||
/** Prints the TLS and keystore defaults of the running JDK and tries three handshakes.
|
||||
* Usage: java CryptoDefaults keystore.p12 (store password "changeit"). Compiles on JDK 8. */
|
||||
public class CryptoDefaults {
|
||||
public static void main(String[] args) throws Exception {
|
||||
System.out.println("java.version = " + System.getProperty("java.version"));
|
||||
System.out.println("keystore.type = " + KeyStore.getDefaultType());
|
||||
SSLParameters p = SSLContext.getDefault().getDefaultSSLParameters();
|
||||
System.out.println("protocols = " + Arrays.toString(p.getProtocols()));
|
||||
List<String> rsaKx = new ArrayList<String>();
|
||||
for (String s : p.getCipherSuites()) if (s.startsWith("TLS_RSA_")) rsaKx.add(s);
|
||||
System.out.println("cipher suites = " + p.getCipherSuites().length + " enabled, "
|
||||
+ rsaKx.size() + " of them TLS_RSA_*");
|
||||
for (String key : new String[] {"jdk.tls.disabledAlgorithms", "jdk.jar.disabledAlgorithms"}) {
|
||||
System.out.println(key + " =");
|
||||
for (String item : Security.getProperty(key).split(",")) System.out.println(" " + item.trim());
|
||||
}
|
||||
|
||||
KeyStore ks = KeyStore.getInstance("PKCS12");
|
||||
try (FileInputStream in = new FileInputStream(args[0])) { ks.load(in, "changeit".toCharArray()); }
|
||||
KeyManagerFactory kmf = KeyManagerFactory.getInstance(KeyManagerFactory.getDefaultAlgorithm());
|
||||
kmf.init(ks, "changeit".toCharArray());
|
||||
TrustManagerFactory tmf = TrustManagerFactory.getInstance(TrustManagerFactory.getDefaultAlgorithm());
|
||||
tmf.init(ks);
|
||||
SSLContext ctx = SSLContext.getInstance("TLS");
|
||||
ctx.init(kmf.getKeyManagers(), tmf.getTrustManagers(), null);
|
||||
|
||||
handshake(ctx, "TLSv1.2 default suites", "TLSv1.2", null);
|
||||
handshake(ctx, "TLSv1.1 only", "TLSv1.1", null);
|
||||
handshake(ctx, "TLS_RSA_WITH_AES_128_GCM_SHA256", "TLSv1.2", "TLS_RSA_WITH_AES_128_GCM_SHA256");
|
||||
}
|
||||
|
||||
static void handshake(SSLContext ctx, String label, String protocol, String suite) throws Exception {
|
||||
final SSLServerSocket server = (SSLServerSocket) ctx.getServerSocketFactory().createServerSocket(0);
|
||||
server.setEnabledProtocols(new String[] {"TLSv1.2", "TLSv1.1"});
|
||||
server.setEnabledCipherSuites(server.getSupportedCipherSuites());
|
||||
Thread t = new Thread(() -> {
|
||||
try (SSLSocket s = (SSLSocket) server.accept()) { s.startHandshake(); s.getOutputStream().write(1); }
|
||||
catch (Exception ignored) { }
|
||||
});
|
||||
t.start();
|
||||
try (SSLSocket c = (SSLSocket) ctx.getSocketFactory().createSocket("localhost", server.getLocalPort())) {
|
||||
c.setEnabledProtocols(new String[] {protocol});
|
||||
if (suite != null) c.setEnabledCipherSuites(new String[] {suite});
|
||||
c.startHandshake();
|
||||
c.getInputStream().read();
|
||||
System.out.println("[ok] " + label + " -> " + c.getSession().getProtocol() + " " + c.getSession().getCipherSuite());
|
||||
} catch (Exception e) {
|
||||
System.out.println("[FAIL] " + label + " -> " + e.getClass().getName() + ": " + e.getMessage());
|
||||
} finally {
|
||||
t.join(3000);
|
||||
server.close();
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user