Skip to content

Commit 55ddfa4

Browse files
committed
style: fix formatting in StringUtils and StringUtilsTest, update toCommaDelimitedString to return null when inputs are null, adjust tests for correct null handling, and ensure spotless compliance
1 parent c393896 commit 55ddfa4

2 files changed

Lines changed: 13 additions & 11 deletions

File tree

dubbo-common/src/main/java/org/apache/dubbo/common/utils/StringUtils.java

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1242,14 +1242,17 @@ public static byte decodeHexByte(CharSequence s, int pos) {
12421242
}
12431243

12441244
/**
1245-
* Create the common-delimited {@link String} by one or more {@link String} members
1245+
* Creates a comma-delimited string from one or more string values.
12461246
*
1247-
* @param one one {@link String}
1248-
* @param others others {@link String}
1249-
* @return <code>null</code> if <code>one</code> or <code>others</code> is <code>null</code>
1247+
* @param one the first string value
1248+
* @param others additional string values
1249+
* @return a combined comma-delimited string, or <code>null</code> if {@code one} or {@code others} is {@code null}
12501250
* @since 2.7.8
12511251
*/
12521252
public static String toCommaDelimitedString(String one, String... others) {
1253+
if (one == null || others == null) {
1254+
return null;
1255+
}
12531256
String another = arrayToDelimitedString(others, COMMA_SEPARATOR);
12541257
return isEmpty(another) ? one : one + COMMA_SEPARATOR + another;
12551258
}

dubbo-common/src/test/java/org/apache/dubbo/common/utils/StringUtilsTest.java

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@
3535
import static org.apache.dubbo.common.utils.StringUtils.splitToList;
3636
import static org.apache.dubbo.common.utils.StringUtils.splitToSet;
3737
import static org.apache.dubbo.common.utils.StringUtils.startsWithIgnoreCase;
38-
import static org.apache.dubbo.common.utils.StringUtils.toCommaDelimitedString;
3938
import static org.hamcrest.MatcherAssert.assertThat;
4039
import static org.hamcrest.Matchers.containsString;
4140
import static org.hamcrest.Matchers.equalTo;
@@ -478,22 +477,22 @@ private void assertEqualsWithoutSpaces(String expect, String actual) {
478477
*/
479478
@Test
480479
void testToCommaDelimitedString() {
481-
String value = toCommaDelimitedString(null);
480+
String value = StringUtils.toCommaDelimitedString(null);
482481
assertNull(value);
483482

484-
value = toCommaDelimitedString(null, null);
483+
value = StringUtils.toCommaDelimitedString(null, (String) null);
485484
assertNull(value);
486485

487-
value = toCommaDelimitedString("");
486+
value = StringUtils.toCommaDelimitedString("");
488487
assertEquals("", value);
489488

490-
value = toCommaDelimitedString("one");
489+
value = StringUtils.toCommaDelimitedString("one");
491490
assertEquals("one", value);
492491

493-
value = toCommaDelimitedString("one", "two");
492+
value = StringUtils.toCommaDelimitedString("one", "two");
494493
assertEquals("one,two", value);
495494

496-
value = toCommaDelimitedString("one", "two", "three");
495+
value = StringUtils.toCommaDelimitedString("one", "two", "three");
497496
assertEquals("one,two,three", value);
498497
}
499498

0 commit comments

Comments
 (0)