Throw dedicated exception when adding a field with an empty name
authorDavid ‘Bombe’ Roden <bombe@pterodactylus.net>
Sun, 15 Mar 2015 12:41:31 +0000 (13:41 +0100)
committerDavid ‘Bombe’ Roden <bombe@pterodactylus.net>
Sun, 15 Mar 2015 12:41:31 +0000 (13:41 +0100)
src/main/java/net/pterodactylus/sone/data/Profile.java

index 9c7da48..4970cf9 100644 (file)
@@ -325,7 +325,9 @@ public class Profile implements Fingerprintable {
         */
        public Field addField(String fieldName) throws IllegalArgumentException {
                checkNotNull(fieldName, "fieldName must not be null");
-               checkArgument(fieldName.length() > 0, "fieldName must not be empty");
+               if (fieldName.length() == 0) {
+                       throw new EmptyFieldName();
+               }
                if (getFieldByName(fieldName) != null) {
                        throw new DuplicateField();
                }
@@ -556,6 +558,13 @@ public class Profile implements Fingerprintable {
        }
 
        /**
+        * Exception that signals the addition of a field with an empty name.
+        *
+        * @author <a href="mailto:bombe@pterodactylus.net">David ‘Bombe’ Roden</a>
+        */
+       public static class EmptyFieldName extends IllegalArgumentException { }
+
+       /**
         * Exception that signals the addition of a field that already exists.
         *
         * @author <a href="mailto:bombe@pterodactylus.net">David ‘Bombe’ Roden</a>