X-Git-Url: https://git.pterodactylus.net/?p=Sone.git;a=blobdiff_plain;f=src%2Fmain%2Fjava%2Fnet%2Fpterodactylus%2Fsone%2Fdata%2FProfile.java;fp=src%2Fmain%2Fjava%2Fnet%2Fpterodactylus%2Fsone%2Fdata%2FProfile.java;h=1f80248ebc864c7169dc9e406b56a8b29d4d35fe;hp=4bf26cc7b5d99abc88b849e957f01b4ddc786055;hb=28667abdadc0573ac106542f1fd42ab5775ec415;hpb=be1d948bbb2f9ff8ed5836d651b09ae658baed83 diff --git a/src/main/java/net/pterodactylus/sone/data/Profile.java b/src/main/java/net/pterodactylus/sone/data/Profile.java index 4bf26cc..1f80248 100644 --- a/src/main/java/net/pterodactylus/sone/data/Profile.java +++ b/src/main/java/net/pterodactylus/sone/data/Profile.java @@ -326,7 +326,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"); - checkArgument(getFieldByName(fieldName) == null, "fieldName must be unique"); + if (getFieldByName(fieldName) != null) { + throw new DuplicateField(); + } @SuppressWarnings("synthetic-access") Field field = new Field().setName(fieldName); fields.add(field); @@ -553,4 +555,11 @@ public class Profile implements Fingerprintable { } + /** + * Exception that signals the addition of a field that already exists. + * + * @author David ‘Bombe’ Roden + */ + public static class DuplicateField extends IllegalArgumentException { } + }