From 13fa6699a3f4f57efbcd9d6b7a56175db0fd13de Mon Sep 17 00:00:00 2001 From: Sergey Nuyanzin Date: Mon, 25 May 2026 14:16:50 +0200 Subject: [PATCH] [FLINK-38503] Adapt `DefaultClusterClientServiceLoader` to java 25 --- .../DefaultClusterClientServiceLoader.java | 21 +++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/flink-clients/src/main/java/org/apache/flink/client/deployment/DefaultClusterClientServiceLoader.java b/flink-clients/src/main/java/org/apache/flink/client/deployment/DefaultClusterClientServiceLoader.java index 8c33243c1d578..dc95df92c8b12 100644 --- a/flink-clients/src/main/java/org/apache/flink/client/deployment/DefaultClusterClientServiceLoader.java +++ b/flink-clients/src/main/java/org/apache/flink/client/deployment/DefaultClusterClientServiceLoader.java @@ -52,14 +52,21 @@ public ClusterClientFactory getClusterClientFactory( final List compatibleFactories = new ArrayList<>(); final Iterator factories = loader.iterator(); - while (factories.hasNext()) { + while (true) { try { + // hasNext might lead to error in java 24, 25 + // for more details take a look at https://bugs.openjdk.org/browse/JDK-8196182 + // and https://bugs.openjdk.org/browse/JDK-8350481 + if (!factories.hasNext()) { + break; + } final ClusterClientFactory factory = factories.next(); if (factory != null && factory.isCompatibleWith(configuration)) { compatibleFactories.add(factory); } } catch (Throwable e) { - if (e.getCause() instanceof NoClassDefFoundError) { + if (e instanceof NoClassDefFoundError + || e.getCause() instanceof NoClassDefFoundError) { LOG.info("Could not load factory due to missing dependencies."); } else { throw e; @@ -98,8 +105,14 @@ public Stream getApplicationModeTargetNames() { final List result = new ArrayList<>(); final Iterator it = loader.iterator(); - while (it.hasNext()) { + while (true) { try { + // hasNext might lead to error in java 24, 25 + // for more details take a look at https://bugs.openjdk.org/browse/JDK-8196182 + // and https://bugs.openjdk.org/browse/JDK-8350481 + if (!it.hasNext()) { + break; + } final ClusterClientFactory clientFactory = it.next(); final Optional applicationName = clientFactory.getApplicationTargetName(); @@ -107,7 +120,7 @@ public Stream getApplicationModeTargetNames() { result.add(applicationName.get()); } - } catch (ServiceConfigurationError e) { + } catch (ServiceConfigurationError | NoClassDefFoundError e) { // cannot be loaded, most likely because Hadoop is not // in the classpath, we can ignore it for now. }