From c6557d237277367bea61c52eaffbd74c0b877416 Mon Sep 17 00:00:00 2001 From: cychiu Date: Wed, 22 Jul 2026 16:25:16 +0900 Subject: [PATCH 1/3] HDDS-8082. Add testXmlValuesHaveNoEmbeddedNewlines to ConfigurationFieldsTests --- .../hadoop/conf/ConfigurationFieldsTests.java | 38 +++++++++++++++++++ 1 file changed, 38 insertions(+) diff --git a/hadoop-ozone/integration-test/src/test/java/org/apache/hadoop/conf/ConfigurationFieldsTests.java b/hadoop-ozone/integration-test/src/test/java/org/apache/hadoop/conf/ConfigurationFieldsTests.java index 41fffe6e1373..8241dacbc699 100644 --- a/hadoop-ozone/integration-test/src/test/java/org/apache/hadoop/conf/ConfigurationFieldsTests.java +++ b/hadoop-ozone/integration-test/src/test/java/org/apache/hadoop/conf/ConfigurationFieldsTests.java @@ -20,6 +20,7 @@ import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertNotNull; import static org.junit.jupiter.api.Assertions.assertNull; +import static org.junit.jupiter.api.Assertions.assertTrue; import java.lang.reflect.Field; import java.lang.reflect.Modifier; @@ -135,6 +136,14 @@ public abstract class ConfigurationFieldsTests { @SuppressWarnings("checkstyle:visibilitymodifier") protected Set filtersForDefaultValueCollisionCheck = new HashSet<>(); + /** + * A set of property keys that are allowed to contain a newline. + * Entries are skipped by {@link #testXmlValuesHaveNoEmbeddedNewlines}; keep + * this empty unless a value genuinely requires a line break, otherwise the + * embedded newline corrupts the runtime string (see HDDS-8046). + */ + protected Set xmlPropsAllowedToContainNewline = new HashSet<>(); + /** * Abstract method to be used by subclasses for initializing base * members. @@ -668,6 +677,35 @@ public void testDefaultValueCollision() { LOG.info("Checked {} default values for collision.", valuesChecked); } + } + + /** + * Verifies no default value in the XML embeds a line break, which would + * corrupt the runtime string (see HDDS-8046). Legitimate cases opt out via + * {@link #xmlPropsAllowedToContainNewline}. + */ + @Test + public void testXmlValuesHaveNoEmbeddedNewlines() { + Set xmlValuesWithNewlines = new HashSet<>(); + for (Map.Entry entry : xmlKeyValueMap.entrySet()) { + String value = entry.getValue(); + if (value == null) { + continue; + } + if (xmlPropsAllowedToContainNewline.contains(entry.getKey())) { + LOG.info("XML Property: {} AllowedToContainNewline", entry.getKey()); + continue; + } + if (value.indexOf('\n') != -1 || value.indexOf('\r') != -1) { + xmlValuesWithNewlines.add(entry.getKey()); + } + } + assertTrue(xmlValuesWithNewlines.isEmpty(), + "These properties in " + xmlFilename + " have an embedded line break in " + + "their , which corrupts the runtime string: " + xmlValuesWithNewlines + + " Put the value on a single line. If the newline is genuinely required, " + + "add the property to xmlPropsAllowedToContainNewline (in " + + "initializeMemberVariables) with a reason + Jira. See HDDS-8082."); } } From 51c3a8bab8da0a837620182f07081004fc42b14c Mon Sep 17 00:00:00 2001 From: cychiu Date: Thu, 23 Jul 2026 09:28:09 +0900 Subject: [PATCH 2/3] Fix: Read raw XML directly in testXmlValuesHaveNoEmbeddedNewlines --- .../hadoop/conf/ConfigurationFieldsTests.java | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/hadoop-ozone/integration-test/src/test/java/org/apache/hadoop/conf/ConfigurationFieldsTests.java b/hadoop-ozone/integration-test/src/test/java/org/apache/hadoop/conf/ConfigurationFieldsTests.java index 8241dacbc699..a6679a25f778 100644 --- a/hadoop-ozone/integration-test/src/test/java/org/apache/hadoop/conf/ConfigurationFieldsTests.java +++ b/hadoop-ozone/integration-test/src/test/java/org/apache/hadoop/conf/ConfigurationFieldsTests.java @@ -682,12 +682,20 @@ public void testDefaultValueCollision() { /** * Verifies no default value in the XML embeds a line break, which would * corrupt the runtime string (see HDDS-8046). Legitimate cases opt out via - * {@link #xmlPropsAllowedToContainNewline}. + * {@link #xmlPropsAllowedToContainNewline}. Unlike the comparison tests, this + * reads the raw XML directly so it is not narrowed by + * {@code xmlPropsToSkipCompare}/{@code xmlPrefixToSkipCompare}: every property + * is checked, and the only exemption is {@link #xmlPropsAllowedToContainNewline}. */ @Test public void testXmlValuesHaveNoEmbeddedNewlines() { - Set xmlValuesWithNewlines = new HashSet<>(); - for (Map.Entry entry : xmlKeyValueMap.entrySet()) { + assertNotNull(xmlFilename); + Configuration conf = new Configuration(false); + conf.setAllowNullValueProperties(true); + conf.addResource(xmlFilename); + + Set xmlValuesWithNewlines = new TreeSet<>(); + for (Map.Entry entry : conf) { String value = entry.getValue(); if (value == null) { continue; @@ -703,7 +711,7 @@ public void testXmlValuesHaveNoEmbeddedNewlines() { assertTrue(xmlValuesWithNewlines.isEmpty(), "These properties in " + xmlFilename + " have an embedded line break in " - + "their , which corrupts the runtime string: " + xmlValuesWithNewlines + + "their , which corrupts the runtime string: " + xmlValuesWithNewlines + " Put the value on a single line. If the newline is genuinely required, " + "add the property to xmlPropsAllowedToContainNewline (in " + "initializeMemberVariables) with a reason + Jira. See HDDS-8082."); From 3f72dc8631127868d5643844007dad0fa2909ce9 Mon Sep 17 00:00:00 2001 From: cychiu Date: Sun, 26 Jul 2026 20:41:08 +0900 Subject: [PATCH 3/3] fix: use assertThat instead of assertTrue --- .../org/apache/hadoop/conf/ConfigurationFieldsTests.java | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/hadoop-ozone/integration-test/src/test/java/org/apache/hadoop/conf/ConfigurationFieldsTests.java b/hadoop-ozone/integration-test/src/test/java/org/apache/hadoop/conf/ConfigurationFieldsTests.java index a6679a25f778..918278966284 100644 --- a/hadoop-ozone/integration-test/src/test/java/org/apache/hadoop/conf/ConfigurationFieldsTests.java +++ b/hadoop-ozone/integration-test/src/test/java/org/apache/hadoop/conf/ConfigurationFieldsTests.java @@ -17,10 +17,10 @@ package org.apache.hadoop.conf; +import static org.assertj.core.api.Assertions.assertThat; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertNotNull; import static org.junit.jupiter.api.Assertions.assertNull; -import static org.junit.jupiter.api.Assertions.assertTrue; import java.lang.reflect.Field; import java.lang.reflect.Modifier; @@ -709,11 +709,12 @@ public void testXmlValuesHaveNoEmbeddedNewlines() { } } - assertTrue(xmlValuesWithNewlines.isEmpty(), + assertThat(xmlValuesWithNewlines).withFailMessage( "These properties in " + xmlFilename + " have an embedded line break in " + "their , which corrupts the runtime string: " + xmlValuesWithNewlines + " Put the value on a single line. If the newline is genuinely required, " + "add the property to xmlPropsAllowedToContainNewline (in " - + "initializeMemberVariables) with a reason + Jira. See HDDS-8082."); + + "initializeMemberVariables) with a reason + Jira. See HDDS-8082.") + .isEmpty(); } }