X-Git-Url: https://git.pterodactylus.net/?a=blobdiff_plain;f=src%2Fmain%2Fjava%2Fnet%2Fpterodactylus%2Fsone%2Fdata%2FProfile.java;h=9c7da484a7854e4aabf3f7a04e5d21b2836b0836;hb=b2e3ba7456f47f01552c8e1300e295c48d8fe9a8;hp=5a4fde041052c8c4f0a7228196eb5fba9b3698fa;hpb=6f019de1d4d9742981d851ac3c9097cca8bff58e;p=Sone.git diff --git a/src/main/java/net/pterodactylus/sone/data/Profile.java b/src/main/java/net/pterodactylus/sone/data/Profile.java index 5a4fde0..9c7da48 100644 --- a/src/main/java/net/pterodactylus/sone/data/Profile.java +++ b/src/main/java/net/pterodactylus/sone/data/Profile.java @@ -326,9 +326,11 @@ 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"); - checkState(getFieldByName(fieldName) == null, "fieldName must be unique"); + if (getFieldByName(fieldName) != null) { + throw new DuplicateField(); + } @SuppressWarnings("synthetic-access") - Field field = new Field().setName(fieldName); + Field field = new Field().setName(fieldName).setValue(""); fields.add(field); return 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 { } + }