diff --git a/src/main/java/org/codehaus/plexus/util/StringUtils.java b/src/main/java/org/codehaus/plexus/util/StringUtils.java index 2e6a2f3f..0f8518de 100644 --- a/src/main/java/org/codehaus/plexus/util/StringUtils.java +++ b/src/main/java/org/codehaus/plexus/util/StringUtils.java @@ -156,9 +156,7 @@ public static String deleteWhitespace( String str ) } /** - *
* Checks if a String is non null
and is not empty (length > 0
).
- *
null
or empty.
*
- * Checks if a (trimmed) String is null
or empty.
- *
- * Note: In future releases, this method will no longer trim the input string such that it works - * complementary to {@link #isNotEmpty(String)}. Code that wants to test for whitespace-only strings should be - * migrated to use {@link #isBlank(String)} instead. - *
+ * Note: In releases prior 3.5.0, this method trimmed the input string such that it worked + * the same as {@link #isBlank(String)}. Since release 3.5.0 it no longer returns {@code true} for strings + * containing only whitespace characters. * * @param str the String to check - * @returntrue
if the String is null
, or length zero once trimmed
+ * @return true
if the String is null
, or length zero
*/
public static boolean isEmpty( String str )
{
- return ( ( str == null ) || ( str.trim().isEmpty() ) );
+ return ( ( str == null ) || ( str.isEmpty() ) );
}
/**
diff --git a/src/test/java/org/codehaus/plexus/util/StringUtilsTest.java b/src/test/java/org/codehaus/plexus/util/StringUtilsTest.java
index acabdb9b..b7bd6d72 100644
--- a/src/test/java/org/codehaus/plexus/util/StringUtilsTest.java
+++ b/src/test/java/org/codehaus/plexus/util/StringUtilsTest.java
@@ -43,7 +43,7 @@ public void testIsEmpty()
{
assertEquals( true, StringUtils.isEmpty( null ) );
assertEquals( true, StringUtils.isEmpty( "" ) );
- assertEquals( true, StringUtils.isEmpty( " " ) );
+ assertEquals( false, StringUtils.isEmpty( " " ) );
assertEquals( false, StringUtils.isEmpty( "foo" ) );
assertEquals( false, StringUtils.isEmpty( " foo " ) );
}
@@ -61,6 +61,16 @@ public void testIsNotEmpty()
assertEquals( true, StringUtils.isNotEmpty( " foo " ) );
}
+ @Test
+ public void testIsNotEmptyNegatesIsEmpty()
+ {
+ assertEquals( !StringUtils.isEmpty( null ), StringUtils.isNotEmpty( null ) );
+ assertEquals( !StringUtils.isEmpty( "" ), StringUtils.isNotEmpty( "" ) );
+ assertEquals( !StringUtils.isEmpty( " " ), StringUtils.isNotEmpty( " " ) );
+ assertEquals( !StringUtils.isEmpty( "foo" ), StringUtils.isNotEmpty( "foo" ) );
+ assertEquals( !StringUtils.isEmpty( " foo " ), StringUtils.isNotEmpty( " foo " ) );
+ }
+
/**
* testIsBlank.
*/