commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From brit...@apache.org
Subject [03/12] [text] Check for null inputs
Date Sun, 19 Apr 2015 15:14:52 GMT
Check for null inputs


Project: http://git-wip-us.apache.org/repos/asf/commons-text/repo
Commit: http://git-wip-us.apache.org/repos/asf/commons-text/commit/9a0cc85a
Tree: http://git-wip-us.apache.org/repos/asf/commons-text/tree/9a0cc85a
Diff: http://git-wip-us.apache.org/repos/asf/commons-text/diff/9a0cc85a

Branch: refs/heads/SANDBOX-498
Commit: 9a0cc85ad01dcf1f468736984cdd5dec0a7a3bf3
Parents: df7e7a7
Author: Benedikt Ritter <britter@apache.org>
Authored: Sun Apr 19 16:06:09 2015 +0200
Committer: Benedikt Ritter <britter@apache.org>
Committed: Sun Apr 19 16:06:09 2015 +0200

----------------------------------------------------------------------
 .../java/org/apache/commons/text/names/HumanNameParser.java  | 8 ++++++--
 .../org/apache/commons/text/names/HumanNameParserTest.java   | 6 ++++++
 2 files changed, 12 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/commons-text/blob/9a0cc85a/src/main/java/org/apache/commons/text/names/HumanNameParser.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/commons/text/names/HumanNameParser.java b/src/main/java/org/apache/commons/text/names/HumanNameParser.java
index bf8f9ed..fa2433a 100644
--- a/src/main/java/org/apache/commons/text/names/HumanNameParser.java
+++ b/src/main/java/org/apache/commons/text/names/HumanNameParser.java
@@ -19,6 +19,7 @@ package org.apache.commons.text.names;
 
 import java.util.Arrays;
 import java.util.List;
+import java.util.Objects;
 
 import org.apache.commons.lang3.StringUtils;
 
@@ -194,10 +195,13 @@ public class HumanNameParser {
     /**
      * Consumes the string and creates the name parts.
      *
-     * @param nameStr the name to parse.
-     * @throws NameParseException if the parser fails to retrieve the name parts
+     * @param nameStr the name to parse. Must not be null.
+     * @throws NameParseException if the parser fails to retrieve the name parts.
+     * @throws NullPointerException if nameStr is null.
      */
     public void parse(String nameStr) {
+        Objects.requireNonNull(nameStr, "Parameter 'nameStr' must not be null.");
+
         Name name = new Name(nameStr);
         String suffixes = StringUtils.join(this.suffixes, "\\.*|") + "\\.*";
         String prefixes = StringUtils.join(this.prefixes, " |") + " ";

http://git-wip-us.apache.org/repos/asf/commons-text/blob/9a0cc85a/src/test/java/org/apache/commons/text/names/HumanNameParserTest.java
----------------------------------------------------------------------
diff --git a/src/test/java/org/apache/commons/text/names/HumanNameParserTest.java b/src/test/java/org/apache/commons/text/names/HumanNameParserTest.java
index 478d19c..d43d2be 100644
--- a/src/test/java/org/apache/commons/text/names/HumanNameParserTest.java
+++ b/src/test/java/org/apache/commons/text/names/HumanNameParserTest.java
@@ -50,6 +50,12 @@ public class HumanNameParserTest {
         }
     }
 
+    @Test(expected = NullPointerException.class)
+    public void shouldThrowNullPointerException_WhenNullIsParsed() throws Exception {
+        HumanNameParser parser = new HumanNameParser();
+        parser.parse(null);
+    }
+
     @Test
     public void testInputs() {
         for (CSVRecord record : parser) {


Mime
View raw message