From 889260611cb0061fed473445b06bbe0502829558 Mon Sep 17 00:00:00 2001 From: Bryan Keller Date: Sat, 20 Jan 2024 17:27:42 -0800 Subject: [PATCH] reflection cleanup --- .../iceberg/connect/data/Utilities.java | 19 ++++++++----------- 1 file changed, 8 insertions(+), 11 deletions(-) diff --git a/kafka-connect/kafka-connect/src/main/java/org/apache/iceberg/connect/data/Utilities.java b/kafka-connect/kafka-connect/src/main/java/org/apache/iceberg/connect/data/Utilities.java index 0a68cdfa9264..abf9b24153c4 100644 --- a/kafka-connect/kafka-connect/src/main/java/org/apache/iceberg/connect/data/Utilities.java +++ b/kafka-connect/kafka-connect/src/main/java/org/apache/iceberg/connect/data/Utilities.java @@ -25,7 +25,6 @@ import static org.apache.iceberg.TableProperties.WRITE_TARGET_FILE_SIZE_BYTES_DEFAULT; import java.io.IOException; -import java.lang.reflect.InvocationTargetException; import java.net.URL; import java.nio.file.Files; import java.nio.file.Path; @@ -39,6 +38,7 @@ import org.apache.iceberg.Table; import org.apache.iceberg.catalog.Catalog; import org.apache.iceberg.common.DynClasses; +import org.apache.iceberg.common.DynConstructors; import org.apache.iceberg.common.DynMethods; import org.apache.iceberg.common.DynMethods.BoundMethod; import org.apache.iceberg.connect.IcebergSinkConfig; @@ -74,11 +74,11 @@ public static Catalog loadCatalog(IcebergSinkConfig config) { // use reflection here to avoid requiring Hadoop as a dependency private static Object loadHadoopConfig(IcebergSinkConfig config) { Class configClass = - DynClasses.builder().impl("org.apache.hadoop.hdfs.HdfsConfiguration").orNull().build(); - if (configClass == null) { - configClass = - DynClasses.builder().impl("org.apache.hadoop.conf.Configuration").orNull().build(); - } + DynClasses.builder() + .impl("org.apache.hadoop.hdfs.HdfsConfiguration") + .impl("org.apache.hadoop.conf.Configuration") + .orNull() + .build(); if (configClass == null) { LOG.info("Hadoop not found on classpath, not creating Hadoop config"); @@ -86,7 +86,7 @@ private static Object loadHadoopConfig(IcebergSinkConfig config) { } try { - Object result = configClass.getDeclaredConstructor().newInstance(); + Object result = DynConstructors.builder().hiddenImpl(configClass).build().newInstance(); BoundMethod addResourceMethod = DynMethods.builder("addResource").impl(configClass, URL.class).build(result); BoundMethod setMethod = @@ -113,10 +113,7 @@ private static Object loadHadoopConfig(IcebergSinkConfig config) { LOG.info("Hadoop config initialized: {}", configClass.getName()); return result; - } catch (InstantiationException - | IllegalAccessException - | NoSuchMethodException - | InvocationTargetException e) { + } catch (Exception e) { LOG.warn( "Hadoop found on classpath but could not create config, proceeding without config", e); }