commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bay...@apache.org
Subject svn commit: r1075673 - in /commons/proper/lang/trunk/src: main/java/org/apache/commons/lang3/StringUtils.java site/changes/changes.xml site/xdoc/article3_0.xml test/java/org/apache/commons/lang3/StringUtilsIsTest.java
Date Tue, 01 Mar 2011 06:31:42 GMT
Author: bayard
Date: Tue Mar  1 06:31:41 2011
New Revision: 1075673

URL: http://svn.apache.org/viewvc?rev=1075673&view=rev
Log:
Resolving LANG-428 - Changing StringUtils.isAlpha, isAlphanumeric and isNumeric to return
false when passed an empty String. Documenting this in the changes report and in the upgrade
article. Also fixing a Javadoc c+p error in isNumericSpace and isAlphanumericSpace. 

Modified:
    commons/proper/lang/trunk/src/main/java/org/apache/commons/lang3/StringUtils.java
    commons/proper/lang/trunk/src/site/changes/changes.xml
    commons/proper/lang/trunk/src/site/xdoc/article3_0.xml
    commons/proper/lang/trunk/src/test/java/org/apache/commons/lang3/StringUtilsIsTest.java

Modified: commons/proper/lang/trunk/src/main/java/org/apache/commons/lang3/StringUtils.java
URL: http://svn.apache.org/viewvc/commons/proper/lang/trunk/src/main/java/org/apache/commons/lang3/StringUtils.java?rev=1075673&r1=1075672&r2=1075673&view=diff
==============================================================================
--- commons/proper/lang/trunk/src/main/java/org/apache/commons/lang3/StringUtils.java (original)
+++ commons/proper/lang/trunk/src/main/java/org/apache/commons/lang3/StringUtils.java Tue
Mar  1 06:31:41 2011
@@ -5195,11 +5195,11 @@ public class StringUtils {
      * <p>Checks if the CharSequence contains only unicode letters.</p>
      *
      * <p><code>null</code> will return <code>false</code>.
-     * An empty CharSequence (length()=0) will return <code>true</code>.</p>
+     * An empty CharSequence (length()=0) will return <code>false</code>.</p>
      *
      * <pre>
      * StringUtils.isAlpha(null)   = false
-     * StringUtils.isAlpha("")     = true
+     * StringUtils.isAlpha("")     = false
      * StringUtils.isAlpha("  ")   = false
      * StringUtils.isAlpha("abc")  = true
      * StringUtils.isAlpha("ab2c") = false
@@ -5209,9 +5209,10 @@ public class StringUtils {
      * @param cs  the CharSequence to check, may be null
      * @return <code>true</code> if only contains letters, and is non-null
      * @since 3.0 Changed signature from isAlpha(String) to isAlpha(CharSequence)
+     * @since 3.0 Changed "" to return false and not true
      */
     public static boolean isAlpha(CharSequence cs) {
-        if (cs == null) {
+        if (cs == null || cs.length() == 0) {
             return false;
         }
         int sz = cs.length();
@@ -5262,11 +5263,11 @@ public class StringUtils {
      * <p>Checks if the CharSequence contains only unicode letters or digits.</p>
      *
      * <p><code>null</code> will return <code>false</code>.
-     * An empty CharSequence (length()=0) will return <code>true</code>.</p>
+     * An empty CharSequence (length()=0) will return <code>false</code>.</p>
      *
      * <pre>
      * StringUtils.isAlphanumeric(null)   = false
-     * StringUtils.isAlphanumeric("")     = true
+     * StringUtils.isAlphanumeric("")     = false
      * StringUtils.isAlphanumeric("  ")   = false
      * StringUtils.isAlphanumeric("abc")  = true
      * StringUtils.isAlphanumeric("ab c") = false
@@ -5278,9 +5279,10 @@ public class StringUtils {
      * @return <code>true</code> if only contains letters or digits,
      *  and is non-null
      * @since 3.0 Changed signature from isAlphanumeric(String) to isAlphanumeric(CharSequence)
+     * @since 3.0 Changed "" to return false and not true
      */
     public static boolean isAlphanumeric(CharSequence cs) {
-        if (cs == null) {
+        if (cs == null || cs.length() == 0) {
             return false;
         }
         int sz = cs.length();
@@ -5300,13 +5302,13 @@ public class StringUtils {
      * An empty CharSequence (length()=0) will return <code>true</code>.</p>
      *
      * <pre>
-     * StringUtils.isAlphanumeric(null)   = false
-     * StringUtils.isAlphanumeric("")     = true
-     * StringUtils.isAlphanumeric("  ")   = true
-     * StringUtils.isAlphanumeric("abc")  = true
-     * StringUtils.isAlphanumeric("ab c") = true
-     * StringUtils.isAlphanumeric("ab2c") = true
-     * StringUtils.isAlphanumeric("ab-c") = false
+     * StringUtils.isAlphanumericSpace(null)   = false
+     * StringUtils.isAlphanumericSpace("")     = true
+     * StringUtils.isAlphanumericSpace("  ")   = true
+     * StringUtils.isAlphanumericSpace("abc")  = true
+     * StringUtils.isAlphanumericSpace("ab c") = true
+     * StringUtils.isAlphanumericSpace("ab2c") = true
+     * StringUtils.isAlphanumericSpace("ab-c") = false
      * </pre>
      *
      * @param cs  the CharSequence to check, may be null
@@ -5371,11 +5373,11 @@ public class StringUtils {
      * A decimal point is not a unicode digit and returns false.</p>
      *
      * <p><code>null</code> will return <code>false</code>.
-     * An empty CharSequence (length()=0) will return <code>true</code>.</p>
+     * An empty CharSequence (length()=0) will return <code>false</code>.</p>
      *
      * <pre>
      * StringUtils.isNumeric(null)   = false
-     * StringUtils.isNumeric("")     = true
+     * StringUtils.isNumeric("")     = false
      * StringUtils.isNumeric("  ")   = false
      * StringUtils.isNumeric("123")  = true
      * StringUtils.isNumeric("12 3") = false
@@ -5387,9 +5389,10 @@ public class StringUtils {
      * @param cs  the CharSequence to check, may be null
      * @return <code>true</code> if only contains digits, and is non-null
      * @since 3.0 Changed signature from isNumeric(String) to isNumeric(CharSequence)
+     * @since 3.0 Changed "" to return false and not true
      */
     public static boolean isNumeric(CharSequence cs) {
-        if (cs == null) {
+        if (cs == null || cs.length() == 0) {
             return false;
         }
         int sz = cs.length();
@@ -5410,14 +5413,14 @@ public class StringUtils {
      * An empty CharSequence (length()=0) will return <code>true</code>.</p>
      *
      * <pre>
-     * StringUtils.isNumeric(null)   = false
-     * StringUtils.isNumeric("")     = true
-     * StringUtils.isNumeric("  ")   = true
-     * StringUtils.isNumeric("123")  = true
-     * StringUtils.isNumeric("12 3") = true
-     * StringUtils.isNumeric("ab2c") = false
-     * StringUtils.isNumeric("12-3") = false
-     * StringUtils.isNumeric("12.3") = false
+     * StringUtils.isNumericSpace(null)   = false
+     * StringUtils.isNumericSpace("")     = true
+     * StringUtils.isNumericSpace("  ")   = true
+     * StringUtils.isNumericSpace("123")  = true
+     * StringUtils.isNumericSpace("12 3") = true
+     * StringUtils.isNumericSpace("ab2c") = false
+     * StringUtils.isNumericSpace("12-3") = false
+     * StringUtils.isNumericSpace("12.3") = false
      * </pre>
      *
      * @param cs  the CharSequence to check, may be null

Modified: commons/proper/lang/trunk/src/site/changes/changes.xml
URL: http://svn.apache.org/viewvc/commons/proper/lang/trunk/src/site/changes/changes.xml?rev=1075673&r1=1075672&r2=1075673&view=diff
==============================================================================
--- commons/proper/lang/trunk/src/site/changes/changes.xml (original)
+++ commons/proper/lang/trunk/src/site/changes/changes.xml Tue Mar  1 06:31:41 2011
@@ -22,6 +22,7 @@
   <body>
 
   <release version="3.0" date="Unreleased" description="Backwards incompatible update
of Commons Lang to Java 5">
+    <action type="fix" issue="LANG-428">StringUtils.isAlpha, isAlphanumeric and isNumeric
now return false for ""</action>
     <action type="add" issue="LANG-678">Add support for ConcurrentMap.putIfAbsent()</action>
     <action type="add" issue="LANG-676">Documented potential NPE if auto-boxing occurs
for some BooleanUtils methods</action>
     <action type="fix" issue="LANG-677">DateUtils.isSameLocalTime compares using 12
hour clock and not 24 hour</action>

Modified: commons/proper/lang/trunk/src/site/xdoc/article3_0.xml
URL: http://svn.apache.org/viewvc/commons/proper/lang/trunk/src/site/xdoc/article3_0.xml?rev=1075673&r1=1075672&r2=1075673&view=diff
==============================================================================
--- commons/proper/lang/trunk/src/site/xdoc/article3_0.xml (original)
+++ commons/proper/lang/trunk/src/site/xdoc/article3_0.xml Tue Mar  1 06:31:41 2011
@@ -106,6 +106,12 @@ multi-threaded programming, and org.apac
 <p>See the <a href="changes-report.html#3.0">3.0 changes report</a> for
the list of fixed bugs and other enhancements. </p>
 </section>
 
+<section name="Other Notable Changes">
+<ul>
+<li>StringUtils.isAlpha, isNumeric and isAlphanumeric now all return false when passed
an empty String. Previously they returned true. </li>
+</ul>
+</section>
+
 <!--
 <section name="What next???"> TODO: Add Beta info.
 <p>Hopefully that was all of interest. Don't forget to download <a href="http://commons.apache.org/lang/download_lang.cgi">Lang
3.0</a>, or, for the Maven repository users, upgrade your &lt;version&gt; tag
to 3.0 and your groupId to org.apache.commons. Please feel free to raise any questions you
might have on the <a href="mail-lists.html">mailing lists</a>, and report bugs
or enhancements in the <a href="issue-tracking.html">issue tracker</a>.</p>

Modified: commons/proper/lang/trunk/src/test/java/org/apache/commons/lang3/StringUtilsIsTest.java
URL: http://svn.apache.org/viewvc/commons/proper/lang/trunk/src/test/java/org/apache/commons/lang3/StringUtilsIsTest.java?rev=1075673&r1=1075672&r2=1075673&view=diff
==============================================================================
--- commons/proper/lang/trunk/src/test/java/org/apache/commons/lang3/StringUtilsIsTest.java
(original)
+++ commons/proper/lang/trunk/src/test/java/org/apache/commons/lang3/StringUtilsIsTest.java
Tue Mar  1 06:31:41 2011
@@ -35,7 +35,7 @@ public class StringUtilsIsTest extends T
 
     public void testIsAlpha() {
         assertEquals(false, StringUtils.isAlpha(null));
-        assertEquals(true, StringUtils.isAlpha(""));
+        assertEquals(false, StringUtils.isAlpha(""));
         assertEquals(false, StringUtils.isAlpha(" "));
         assertEquals(true, StringUtils.isAlpha("a"));
         assertEquals(true, StringUtils.isAlpha("A"));
@@ -49,7 +49,7 @@ public class StringUtilsIsTest extends T
 
     public void testIsAlphanumeric() {
         assertEquals(false, StringUtils.isAlphanumeric(null));
-        assertEquals(true, StringUtils.isAlphanumeric(""));
+        assertEquals(false, StringUtils.isAlphanumeric(""));
         assertEquals(false, StringUtils.isAlphanumeric(" "));
         assertEquals(true, StringUtils.isAlphanumeric("a"));
         assertEquals(true, StringUtils.isAlphanumeric("A"));
@@ -131,7 +131,7 @@ public class StringUtilsIsTest extends T
   
     public void testIsNumeric() {
         assertEquals(false, StringUtils.isNumeric(null));
-        assertEquals(true, StringUtils.isNumeric(""));
+        assertEquals(false, StringUtils.isNumeric(""));
         assertEquals(false, StringUtils.isNumeric(" "));
         assertEquals(false, StringUtils.isNumeric("a"));
         assertEquals(false, StringUtils.isNumeric("A"));



Mime
View raw message