libenchao commented on code in PR #183:
URL: https://github.com/apache/calcite-avatica/pull/183#discussion_r1002613948


##########
core/src/main/java/org/apache/calcite/avatica/AvaticaUtils.java:
##########
@@ -222,15 +223,22 @@ public static <T> T instantiatePlugin(Class<T> 
pluginClass,
         final Class<T> clazz = (Class) Class.forName(left);
         final Field field;
         field = clazz.getField(right);
-        return pluginClass.cast(field.get(null));
+        final Object fieldValue = field.get(null);
+        if (fieldValue instanceof ThreadLocal) {
+          value = ((ThreadLocal<?>) fieldValue).get();
+        } else {
+          value = fieldValue;
+        }
+        return pluginClass.cast(value);
       }
       //noinspection unchecked
       final Class<T> clazz = (Class) Class.forName(className);
       try {
         // We assume that if there is an INSTANCE field it is static and
         // has the right type.
         final Field field = clazz.getField("INSTANCE");
-        return pluginClass.cast(field.get(null));
+        value = field.get(null);
+        return pluginClass.cast(value);

Review Comment:
   In this branch, `value` could also be a `ThreadLocal`?



##########
core/src/main/java/org/apache/calcite/avatica/AvaticaUtils.java:
##########
@@ -211,6 +211,7 @@ public static <T> T instantiatePlugin(Class<T> pluginClass,
       String className) {
     String right = null;
     String left = null;
+    Object value = null;

Review Comment:
   Does`AvaticaUtils#instantiatePlugin` and `ConnectionConfigImpl#getPlugin`'s 
java doc need to explicitly say that the 'INSTANCE' could be a `ThreadLocal`?



-- 
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: commits-unsubscr...@calcite.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org

Reply via email to