From d5e3c53e740da3b6507149597aca7a01a539e926 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Xavier=20L=C3=A9aut=C3=A9?= Date: Sat, 24 Aug 2019 21:59:14 -0400 Subject: [PATCH] workaround for Guava 16 bug using Java 9 and above --- .../java/org/apache/druid/guice/FirehoseModuleTest.java | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/server/src/test/java/org/apache/druid/guice/FirehoseModuleTest.java b/server/src/test/java/org/apache/druid/guice/FirehoseModuleTest.java index c6fec214601..e4f034032e0 100644 --- a/server/src/test/java/org/apache/druid/guice/FirehoseModuleTest.java +++ b/server/src/test/java/org/apache/druid/guice/FirehoseModuleTest.java @@ -28,11 +28,14 @@ import com.fasterxml.jackson.databind.jsontype.NamedType; import com.google.common.reflect.ClassPath; import org.apache.druid.data.input.FirehoseFactory; import org.apache.druid.segment.realtime.firehose.ClippedFirehoseFactory; +import org.apache.druid.utils.JvmUtils; import org.junit.Assert; import org.junit.Test; import java.io.IOException; import java.lang.reflect.Modifier; +import java.net.URL; +import java.net.URLClassLoader; import java.util.Collection; import java.util.Set; import java.util.function.Predicate; @@ -79,8 +82,10 @@ public class FirehoseModuleTest @SuppressWarnings("UnstableApiUsage") // for ClassPath private static Set getFirehoseFactoryClassesInPackage(String packageName) throws IOException { - ClassLoader loader = Thread.currentThread().getContextClassLoader(); - ClassPath classPath = ClassPath.from(loader); + // workaround for Guava 16, which can only parse the classpath from URLClassLoaders + // requires Guava 28 or later to work properly with the system class loader in Java 9 and above + URLClassLoader classloader = new URLClassLoader(JvmUtils.systemClassPath().toArray(new URL[0])); + ClassPath classPath = ClassPath.from(classloader); return classPath.getTopLevelClasses(packageName).stream() .map(ClassPath.ClassInfo::load) .filter(IS_FIREHOSE_FACTORY)