From 672b01793bd142b3b0ecb3676885de4a9a922809 Mon Sep 17 00:00:00 2001 From: linqichen178 <342752196@qq.com> Date: Sat, 20 Sep 2025 15:59:26 +0800 Subject: [PATCH 1/3] [fix Bug] NullPointException when readHadoopXml apache/paimon#6282 --- .../org/apache/paimon/utils/HadoopUtils.java | 18 +++++++++++------ .../paimon/utils/HadoopUtilsITCase.java | 20 +++++++++++++++++++ 2 files changed, 32 insertions(+), 6 deletions(-) diff --git a/paimon-common/src/main/java/org/apache/paimon/utils/HadoopUtils.java b/paimon-common/src/main/java/org/apache/paimon/utils/HadoopUtils.java index be25fce4d2d7..2f69c9b5d285 100644 --- a/paimon-common/src/main/java/org/apache/paimon/utils/HadoopUtils.java +++ b/paimon-common/src/main/java/org/apache/paimon/utils/HadoopUtils.java @@ -221,13 +221,19 @@ public static void readHadoopXml(String xml, Configuration conf) { } for (int i = 0; i < propertyNodes.getLength(); i++) { Node propertyNode = propertyNodes.item(i); - if (propertyNode.getNodeType() == 1) { + if (1 == propertyNode.getNodeType()) { Element propertyElement = (Element) propertyNode; - String key = propertyElement.getElementsByTagName("name").item(0).getTextContent(); - String value = - propertyElement.getElementsByTagName("value").item(0).getTextContent(); - if (!StringUtils.isNullOrWhitespaceOnly(value)) { - conf.set(key, value); + if (null != propertyElement.getElementsByTagName("name") + && null != propertyElement.getElementsByTagName("name").item(0) + && null != propertyElement.getElementsByTagName("value") + && null != propertyElement.getElementsByTagName("value").item(0)) { + String key = + propertyElement.getElementsByTagName("name").item(0).getTextContent(); + String value = + propertyElement.getElementsByTagName("value").item(0).getTextContent(); + if (!StringUtils.isNullOrWhitespaceOnly(value)) { + conf.set(key, value); + } } } } diff --git a/paimon-common/src/test/java/org/apache/paimon/utils/HadoopUtilsITCase.java b/paimon-common/src/test/java/org/apache/paimon/utils/HadoopUtilsITCase.java index 312ea96fef15..2fa50244b6fe 100644 --- a/paimon-common/src/test/java/org/apache/paimon/utils/HadoopUtilsITCase.java +++ b/paimon-common/src/test/java/org/apache/paimon/utils/HadoopUtilsITCase.java @@ -70,4 +70,24 @@ public FileIO load(Path path) { return LocalFileIO.create(); } } + + @Test + public void testReadHadoopXml() { + String xml = + "" + + "paimon.test.key0" + + "" + + "" + + "paimon.test.key1" + + "" + + "" + + "" + + "paimon.test.key2" + + "test.value" + + "" + + ""; + Configuration conf = new Configuration(); + HadoopUtils.readHadoopXml(xml, conf); + assertThat(conf.get("paimon.test.key2")).isEqualTo("test.value"); + } } From f4d964117abb840eada2709aa94dc5e779270353 Mon Sep 17 00:00:00 2001 From: linqichen178 <342752196@qq.com> Date: Mon, 22 Sep 2025 21:39:23 +0800 Subject: [PATCH 2/3] Revert "[fix Bug] NullPointException when readHadoopXml apache/paimon#6282" This reverts commit 672b01793bd142b3b0ecb3676885de4a9a922809. --- .../org/apache/paimon/utils/HadoopUtils.java | 18 ++++++----------- .../paimon/utils/HadoopUtilsITCase.java | 20 ------------------- 2 files changed, 6 insertions(+), 32 deletions(-) diff --git a/paimon-common/src/main/java/org/apache/paimon/utils/HadoopUtils.java b/paimon-common/src/main/java/org/apache/paimon/utils/HadoopUtils.java index 2f69c9b5d285..be25fce4d2d7 100644 --- a/paimon-common/src/main/java/org/apache/paimon/utils/HadoopUtils.java +++ b/paimon-common/src/main/java/org/apache/paimon/utils/HadoopUtils.java @@ -221,19 +221,13 @@ public static void readHadoopXml(String xml, Configuration conf) { } for (int i = 0; i < propertyNodes.getLength(); i++) { Node propertyNode = propertyNodes.item(i); - if (1 == propertyNode.getNodeType()) { + if (propertyNode.getNodeType() == 1) { Element propertyElement = (Element) propertyNode; - if (null != propertyElement.getElementsByTagName("name") - && null != propertyElement.getElementsByTagName("name").item(0) - && null != propertyElement.getElementsByTagName("value") - && null != propertyElement.getElementsByTagName("value").item(0)) { - String key = - propertyElement.getElementsByTagName("name").item(0).getTextContent(); - String value = - propertyElement.getElementsByTagName("value").item(0).getTextContent(); - if (!StringUtils.isNullOrWhitespaceOnly(value)) { - conf.set(key, value); - } + String key = propertyElement.getElementsByTagName("name").item(0).getTextContent(); + String value = + propertyElement.getElementsByTagName("value").item(0).getTextContent(); + if (!StringUtils.isNullOrWhitespaceOnly(value)) { + conf.set(key, value); } } } diff --git a/paimon-common/src/test/java/org/apache/paimon/utils/HadoopUtilsITCase.java b/paimon-common/src/test/java/org/apache/paimon/utils/HadoopUtilsITCase.java index 2fa50244b6fe..312ea96fef15 100644 --- a/paimon-common/src/test/java/org/apache/paimon/utils/HadoopUtilsITCase.java +++ b/paimon-common/src/test/java/org/apache/paimon/utils/HadoopUtilsITCase.java @@ -70,24 +70,4 @@ public FileIO load(Path path) { return LocalFileIO.create(); } } - - @Test - public void testReadHadoopXml() { - String xml = - "" - + "paimon.test.key0" - + "" - + "" - + "paimon.test.key1" - + "" - + "" - + "" - + "paimon.test.key2" - + "test.value" - + "" - + ""; - Configuration conf = new Configuration(); - HadoopUtils.readHadoopXml(xml, conf); - assertThat(conf.get("paimon.test.key2")).isEqualTo("test.value"); - } } From 498e5b9d5c0baec94c123de805a9dbab7c922433 Mon Sep 17 00:00:00 2001 From: linqichen178 <342752196@qq.com> Date: Mon, 22 Sep 2025 21:51:11 +0800 Subject: [PATCH 3/3] [core] fix Bug-NullPointException when readHadoopXml for issue#6282 --- .../org/apache/paimon/utils/HadoopUtils.java | 18 +++++++++++------ .../paimon/utils/HadoopUtilsITCase.java | 20 +++++++++++++++++++ 2 files changed, 32 insertions(+), 6 deletions(-) diff --git a/paimon-common/src/main/java/org/apache/paimon/utils/HadoopUtils.java b/paimon-common/src/main/java/org/apache/paimon/utils/HadoopUtils.java index be25fce4d2d7..a37c64dbb847 100644 --- a/paimon-common/src/main/java/org/apache/paimon/utils/HadoopUtils.java +++ b/paimon-common/src/main/java/org/apache/paimon/utils/HadoopUtils.java @@ -221,13 +221,19 @@ public static void readHadoopXml(String xml, Configuration conf) { } for (int i = 0; i < propertyNodes.getLength(); i++) { Node propertyNode = propertyNodes.item(i); - if (propertyNode.getNodeType() == 1) { + if (1 == propertyNode.getNodeType()) { Element propertyElement = (Element) propertyNode; - String key = propertyElement.getElementsByTagName("name").item(0).getTextContent(); - String value = - propertyElement.getElementsByTagName("value").item(0).getTextContent(); - if (!StringUtils.isNullOrWhitespaceOnly(value)) { - conf.set(key, value); + if (null != propertyElement.getElementsByTagName("name") + && null != propertyElement.getElementsByTagName("name").item(0) + && null != propertyElement.getElementsByTagName("value") + && null != propertyElement.getElementsByTagName("value").item(0)) { + String name = + propertyElement.getElementsByTagName("name").item(0).getTextContent(); + String value = + propertyElement.getElementsByTagName("value").item(0).getTextContent(); + if (!StringUtils.isNullOrWhitespaceOnly(value)) { + conf.set(name, value); + } } } } diff --git a/paimon-common/src/test/java/org/apache/paimon/utils/HadoopUtilsITCase.java b/paimon-common/src/test/java/org/apache/paimon/utils/HadoopUtilsITCase.java index 312ea96fef15..2fa50244b6fe 100644 --- a/paimon-common/src/test/java/org/apache/paimon/utils/HadoopUtilsITCase.java +++ b/paimon-common/src/test/java/org/apache/paimon/utils/HadoopUtilsITCase.java @@ -70,4 +70,24 @@ public FileIO load(Path path) { return LocalFileIO.create(); } } + + @Test + public void testReadHadoopXml() { + String xml = + "" + + "paimon.test.key0" + + "" + + "" + + "paimon.test.key1" + + "" + + "" + + "" + + "paimon.test.key2" + + "test.value" + + "" + + ""; + Configuration conf = new Configuration(); + HadoopUtils.readHadoopXml(xml, conf); + assertThat(conf.get("paimon.test.key2")).isEqualTo("test.value"); + } }