From a26e4c0e06107f290e573f51ef46f374cea8f826 Mon Sep 17 00:00:00 2001 From: Akshat Jain Date: Fri, 13 Dec 2024 19:54:21 +0530 Subject: [PATCH] Cleanup unreachable Java 8 code flows (#17559) --- .../indexing/common/task/HadoopTask.java | 11 +-- .../indexing/overlord/ForkingTaskRunner.java | 4 +- .../indexing/common/task/HadoopTaskTest.java | 10 +- pom.xml | 3 + .../java/util/common/ByteBufferUtils.java | 59 ++--------- .../druid/java/util/common/Cleaners.java | 23 +---- .../java/util/common/DefineClassUtils.java | 99 +------------------ .../java/org/apache/druid/utils/JvmUtils.java | 5 - .../org/apache/druid/utils/RuntimeInfo.java | 2 +- 9 files changed, 18 insertions(+), 198 deletions(-) diff --git a/indexing-service/src/main/java/org/apache/druid/indexing/common/task/HadoopTask.java b/indexing-service/src/main/java/org/apache/druid/indexing/common/task/HadoopTask.java index 201024540e16..a15b77b90d18 100644 --- a/indexing-service/src/main/java/org/apache/druid/indexing/common/task/HadoopTask.java +++ b/indexing-service/src/main/java/org/apache/druid/indexing/common/task/HadoopTask.java @@ -173,16 +173,7 @@ public static ClassLoader buildClassLoader(final List hadoopDependencyCo localClassLoaderURLs.addAll(Arrays.asList(hadoopLoader.getURLs())); } - ClassLoader parent = null; - if (JvmUtils.isIsJava9Compatible()) { - try { - // See also https://docs.oracle.com/en/java/javase/11/migrate/index.html#JSMIG-GUID-A868D0B9-026F-4D46-B979-901834343F9E - parent = (ClassLoader) ClassLoader.class.getMethod("getPlatformClassLoader").invoke(null); - } - catch (IllegalAccessException | InvocationTargetException | NoSuchMethodException e) { - throw new RuntimeException(e); - } - } + ClassLoader parent = ClassLoader.getPlatformClassLoader(); final ClassLoader classLoader = new URLClassLoader( localClassLoaderURLs.toArray(new URL[0]), parent diff --git a/indexing-service/src/main/java/org/apache/druid/indexing/overlord/ForkingTaskRunner.java b/indexing-service/src/main/java/org/apache/druid/indexing/overlord/ForkingTaskRunner.java index 7e4dd6c39c22..1a34c76e33fb 100644 --- a/indexing-service/src/main/java/org/apache/druid/indexing/overlord/ForkingTaskRunner.java +++ b/indexing-service/src/main/java/org/apache/druid/indexing/overlord/ForkingTaskRunner.java @@ -244,9 +244,7 @@ public TaskStatus call() command.add(config.getJavaCommand()); - if (JvmUtils.majorVersion() >= 11) { - command.addAll(STRONG_ENCAPSULATION_PROPERTIES); - } + command.addAll(STRONG_ENCAPSULATION_PROPERTIES); command.add("-cp"); command.add(taskClasspath); diff --git a/indexing-service/src/test/java/org/apache/druid/indexing/common/task/HadoopTaskTest.java b/indexing-service/src/test/java/org/apache/druid/indexing/common/task/HadoopTaskTest.java index 130258e85d4c..741208dd0db4 100644 --- a/indexing-service/src/test/java/org/apache/druid/indexing/common/task/HadoopTaskTest.java +++ b/indexing-service/src/test/java/org/apache/druid/indexing/common/task/HadoopTaskTest.java @@ -30,7 +30,6 @@ import org.apache.druid.java.util.common.StringUtils; import org.apache.druid.java.util.common.granularity.Granularity; import org.apache.druid.timeline.DataSegment; -import org.apache.druid.utils.JvmUtils; import org.easymock.EasyMock; import org.joda.time.Interval; import org.junit.Assert; @@ -131,13 +130,8 @@ public TaskStatus runTask(TaskToolbox toolbox) public static void assertClassLoaderIsSingular(ClassLoader classLoader) { - if (JvmUtils.isIsJava9Compatible()) { - // See also https://docs.oracle.com/en/java/javase/11/migrate/index.html#JSMIG-GUID-A868D0B9-026F-4D46-B979-901834343F9E - Assert.assertEquals("PlatformClassLoader", classLoader.getParent().getClass().getSimpleName()); - } else { - // This is a check against the current HadoopTask which creates a single URLClassLoader with null parent - Assert.assertNull(classLoader.getParent()); - } + // See also https://docs.oracle.com/en/java/javase/11/migrate/index.html#JSMIG-GUID-A868D0B9-026F-4D46-B979-901834343F9E + Assert.assertEquals("PlatformClassLoader", classLoader.getParent().getClass().getSimpleName()); Assert.assertFalse(classLoader.getClass().getSimpleName().equals("ApplicationClassLoader")); Assert.assertTrue(classLoader instanceof URLClassLoader); diff --git a/pom.xml b/pom.xml index 3ee7600d5437..3f80196334aa 100644 --- a/pom.xml +++ b/pom.xml @@ -1666,6 +1666,9 @@ sun.misc.Unsafe java.lang.invoke.MethodHandle + + java.lang.ClassLoader