AlbumenJ commented on code in PR #14489:
URL: https://github.com/apache/dubbo/pull/14489#discussion_r1713110819
##########
dubbo-common/src/main/java/org/apache/dubbo/common/utils/ClassUtils.java:
##########
@@ -492,6 +492,49 @@ public static boolean isPresent(String className,
ClassLoader classLoader) {
return true;
}
+ /**
+ * Test the specified class name is present, array class is not supported
+ */
+ public static boolean isPresent(String className) {
+ try {
+ loadClass(className);
+ return true;
+ } catch (Throwable ignored) {
+ return false;
+ }
+ }
+
+ /**
+ * Load the {@link Class} by the specified name, array class is not
supported
+ */
+ public static Class<?> loadClass(String className) throws
ClassNotFoundException {
+ ClassLoader cl = null;
+ if (!className.startsWith("org.apache.dubbo")) {
+ try {
+ cl = Thread.currentThread().getContextClassLoader();
+ } catch (Throwable ignored) {
+ }
+ }
+ if (cl == null) {
+ cl = ClassUtils.class.getClassLoader();
+ }
+ return cl.loadClass(className);
+ }
+
+ public static void runWith(ClassLoader classLoader, Runnable runnable) {
+ Thread thread = Thread.currentThread();
+ ClassLoader tccl = thread.getContextClassLoader();
+ if (classLoader == null || classLoader.equals(tccl)) {
+ runnable.run();
Review Comment:
```suggestion
return runnable.run();
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]