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.

git-svn-id: https://svn.apache.org/repos/asf/commons/proper/lang/trunk@1075673 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Henri Yandell 2011-03-01 06:31:41 +00:00
parent 15d50cf864
commit 3c4f60d71b
4 changed files with 37 additions and 27 deletions

View File

@ -5195,11 +5195,11 @@ public static int countMatches(String str, String sub) {
* <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 static int countMatches(String str, String sub) {
* @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 static boolean isAlphaSpace(CharSequence cs) {
* <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 static boolean isAlphaSpace(CharSequence cs) {
* @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 static boolean isAlphanumeric(CharSequence cs) {
* 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 static boolean isAsciiPrintable(CharSequence cs) {
* 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 static boolean isAsciiPrintable(CharSequence cs) {
* @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 static boolean isNumeric(CharSequence cs) {
* 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

View File

@ -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>

View File

@ -106,6 +106,12 @@ multi-threaded programming, and org.apache.commons.lang3.text.translate, which p
<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>

View File

@ -35,7 +35,7 @@ public StringUtilsIsTest(String name) {
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 void testIsAlpha() {
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 void testIsAsciiPrintable_String() {
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"));