You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@flink.apache.org by di...@apache.org on 2023/01/09 09:49:39 UTC

[flink] branch release-1.15 updated: [FLINK-30308][python] Fix ClassLeakCleaner to work with Java 11.0.16+ and 17.0.4+

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

dianfu pushed a commit to branch release-1.15
in repository https://gitbox.apache.org/repos/asf/flink.git


The following commit(s) were added to refs/heads/release-1.15 by this push:
     new 01127bc254c [FLINK-30308][python] Fix ClassLeakCleaner to work with Java 11.0.16+ and 17.0.4+
01127bc254c is described below

commit 01127bc254ccceb4ed32afe3c130fe86cc9b3d96
Author: Dian Fu <di...@apache.org>
AuthorDate: Mon Jan 9 11:55:41 2023 +0800

    [FLINK-30308][python] Fix ClassLeakCleaner to work with Java 11.0.16+ and 17.0.4+
    
    This closes #21619.
---
 .../streaming/api/utils/ClassLeakCleaner.java      | 28 ++++++++++++----------
 1 file changed, 15 insertions(+), 13 deletions(-)

diff --git a/flink-python/src/main/java/org/apache/flink/streaming/api/utils/ClassLeakCleaner.java b/flink-python/src/main/java/org/apache/flink/streaming/api/utils/ClassLeakCleaner.java
index 42427ca8d31..f84b69d58cf 100644
--- a/flink-python/src/main/java/org/apache/flink/streaming/api/utils/ClassLeakCleaner.java
+++ b/flink-python/src/main/java/org/apache/flink/streaming/api/utils/ClassLeakCleaner.java
@@ -55,20 +55,22 @@ public class ClassLeakCleaner {
             throws ReflectiveOperationException, SecurityException, ClassCastException {
         Field f = target.getDeclaredField(mapName);
         f.setAccessible(true);
-        Map<?, ?> map = (Map<?, ?>) f.get(null);
-        Iterator<?> keys = map.keySet().iterator();
-        while (keys.hasNext()) {
-            Object key = keys.next();
-            if (key instanceof Reference) {
-                Object clazz = ((Reference<?>) key).get();
-                if (clazz instanceof Class) {
-                    ClassLoader cl = ((Class<?>) clazz).getClassLoader();
-                    while (cl != null) {
-                        if (cl == classLoader) {
-                            keys.remove();
-                            break;
+        Object map = f.get(null);
+        if (map instanceof Map) {
+            Iterator<?> keys = ((Map<?, ?>) map).keySet().iterator();
+            while (keys.hasNext()) {
+                Object key = keys.next();
+                if (key instanceof Reference) {
+                    Object clazz = ((Reference<?>) key).get();
+                    if (clazz instanceof Class) {
+                        ClassLoader cl = ((Class<?>) clazz).getClassLoader();
+                        while (cl != null) {
+                            if (cl == classLoader) {
+                                keys.remove();
+                                break;
+                            }
+                            cl = cl.getParent();
                         }
-                        cl = cl.getParent();
                     }
                 }
             }