You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@iceberg.apache.org by GitBox <gi...@apache.org> on 2022/01/17 04:05:21 UTC

[GitHub] [iceberg] yittg commented on a change in pull request #3906: Fix context classloader usage for avro reader

yittg commented on a change in pull request #3906:
URL: https://github.com/apache/iceberg/pull/3906#discussion_r785623253



##########
File path: core/src/main/java/org/apache/iceberg/avro/Avro.java
##########
@@ -553,15 +558,20 @@ public static ReadBuilder read(InputFile file) {
   public static class ReadBuilder {
     private final InputFile file;
     private final Map<String, String> renames = Maps.newLinkedHashMap();
-    private ClassLoader loader = Thread.currentThread().getContextClassLoader();
+    private ClassLoader loader = null;
     private NameMapping nameMapping;
     private boolean reuseContainers = false;
     private org.apache.iceberg.Schema schema = null;
     private Function<Schema, DatumReader<?>> createReaderFunc = null;
     private BiFunction<org.apache.iceberg.Schema, Schema, DatumReader<?>> createReaderBiFunc = null;
     private final Function<Schema, DatumReader<?>> defaultCreateReaderFunc = readSchema -> {
       GenericAvroReader<?> reader = new GenericAvroReader<>(readSchema);
-      reader.setClassLoader(loader);
+      ClassLoader classLoader = loader;
+      if (classLoader == null) {
+        LOG.warn("Classloader for avro reader not set, use the thread context classloader.");
+        classLoader = Thread.currentThread().getContextClassLoader();
+      }
+      reader.setClassLoader(classLoader);

Review comment:
       @rdblue I'm not sure if we should just requireNonNull(loader) here.




-- 
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: issues-unsubscribe@iceberg.apache.org

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



---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org