You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@calcite.apache.org by GitBox <gi...@apache.org> on 2022/10/23 20:53:55 UTC
[GitHub] [calcite-avatica] julianhyde commented on a diff in pull request #183: [CALCITE-5295] Read the values of plugins (such as connect string properties) from ThreadLocal fields
julianhyde commented on code in PR #183:
URL: https://github.com/apache/calcite-avatica/pull/183#discussion_r1002770793
##########
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:
No. If a class `Foo` has a field called `INSTANCE`, it should be of type `Foo`. It would be confusing for a field called `INSTANCE` to be of any other type.
--
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-unsubscribe@calcite.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org