This is an automated email from the ASF dual-hosted git repository.

panyuepeng pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/flink.git


The following commit(s) were added to refs/heads/master by this push:
     new c71ff20970e [FLINK-21672][test] Amend unit test so it works with IBM 
java (#27515)
c71ff20970e is described below

commit c71ff20970ead5e9e99b8d0a855e8a09f1e4bc98
Author: David Radley <[email protected]>
AuthorDate: Thu Feb 5 15:13:24 2026 +0000

    [FLINK-21672][test] Amend unit test so it works with IBM java (#27515)
    
    Signed-off-by: [email protected] <[email protected]>
---
 .../StickyAllocationAndLocalRecoveryTestJob.java   | 33 ++++++++++++++++++----
 1 file changed, 27 insertions(+), 6 deletions(-)

diff --git 
a/flink-end-to-end-tests/flink-local-recovery-and-allocation-test/src/main/java/org/apache/flink/streaming/tests/StickyAllocationAndLocalRecoveryTestJob.java
 
b/flink-end-to-end-tests/flink-local-recovery-and-allocation-test/src/main/java/org/apache/flink/streaming/tests/StickyAllocationAndLocalRecoveryTestJob.java
index 15bb8c2e7f6..a0b26761231 100644
--- 
a/flink-end-to-end-tests/flink-local-recovery-and-allocation-test/src/main/java/org/apache/flink/streaming/tests/StickyAllocationAndLocalRecoveryTestJob.java
+++ 
b/flink-end-to-end-tests/flink-local-recovery-and-allocation-test/src/main/java/org/apache/flink/streaming/tests/StickyAllocationAndLocalRecoveryTestJob.java
@@ -419,13 +419,34 @@ public class StickyAllocationAndLocalRecoveryTestJob {
     private static int getJvmPid() throws Exception {
         java.lang.management.RuntimeMXBean runtime =
                 java.lang.management.ManagementFactory.getRuntimeMXBean();
-        java.lang.reflect.Field jvm = 
runtime.getClass().getDeclaredField("jvm");
-        jvm.setAccessible(true);
-        sun.management.VMManagement mgmt = (sun.management.VMManagement) 
jvm.get(runtime);
-        java.lang.reflect.Method pidMethod = 
mgmt.getClass().getDeclaredMethod("getProcessId");
-        pidMethod.setAccessible(true);
 
-        return (int) (Integer) pidMethod.invoke(mgmt);
+        // Try to use reflection to access sun.management.VMManagement
+        // This avoids compile-time dependency on internal JDK classes
+        try {
+            java.lang.reflect.Field jvm = 
runtime.getClass().getDeclaredField("jvm");
+            jvm.setAccessible(true);
+            Object mgmt = jvm.get(runtime);
+
+            // Check if the class exists (it may not in some JDK distributions 
like IBM Semeru)
+            if (mgmt != null) {
+                java.lang.reflect.Method pidMethod =
+                        mgmt.getClass().getDeclaredMethod("getProcessId");
+                pidMethod.setAccessible(true);
+                return (int) (Integer) pidMethod.invoke(mgmt);
+            }
+        } catch (NoSuchFieldException | NoSuchMethodException | 
ClassCastException e) {
+            // Fall through to alternative method
+        }
+
+        // Fallback: parse PID from RuntimeMXBean name (format: "pid@hostname")
+        String jvmName = runtime.getName();
+        int atIndex = jvmName.indexOf('@');
+        if (atIndex > 0) {
+            return Integer.parseInt(jvmName.substring(0, atIndex));
+        }
+
+        throw new UnsupportedOperationException(
+                "Unable to determine JVM PID. This JDK distribution may not 
support the required internal APIs.");
     }
 
     /** Records the information required to check sticky scheduling after a 
restart. */

Reply via email to