From 8ab419f60829a14b5222affcc759ff4a6995d637 Mon Sep 17 00:00:00 2001 From: =?utf8?q?David=20=E2=80=98Bombe=E2=80=99=20Roden?= Date: Sun, 15 Mar 2015 13:41:31 +0100 Subject: [PATCH] Throw dedicated exception when adding a field with an empty name --- src/main/java/net/pterodactylus/sone/data/Profile.java | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/src/main/java/net/pterodactylus/sone/data/Profile.java b/src/main/java/net/pterodactylus/sone/data/Profile.java index 9c7da48..4970cf9 100644 --- a/src/main/java/net/pterodactylus/sone/data/Profile.java +++ b/src/main/java/net/pterodactylus/sone/data/Profile.java @@ -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 David ‘Bombe’ Roden + */ + public static class EmptyFieldName extends IllegalArgumentException { } + + /** * Exception that signals the addition of a field that already exists. * * @author David ‘Bombe’ Roden -- 2.7.4