Don’t allow changing an image’s title into an empty string.
[Sone.git] / src / main / java / net / pterodactylus / sone / data / ImageImpl.java
index 447bb82..df901b0 100644 (file)
@@ -204,6 +204,9 @@ public class ImageImpl implements Image {
                                checkState(!sone.isPresent() || (ImageImpl.this.sone == null) || sone.get().equals(ImageImpl.this.sone), "can not change Sone once set");
                                checkState(!creationTime.isPresent() || ((ImageImpl.this.creationTime == 0) || (ImageImpl.this.creationTime == creationTime.get())), "can not change creation time once set");
                                checkState(!key.isPresent() || (ImageImpl.this.key == null) || key.get().equals(ImageImpl.this.key), "can not change key once set");
+                               if (title.isPresent() && title.get().trim().isEmpty()) {
+                                       throw new ImageTitleMustNotBeEmpty();
+                               }
                                checkState(!width.isPresent() || (ImageImpl.this.width == 0) || width.get().equals(ImageImpl.this.width), "can not change width once set");
                                checkState(!height.isPresent() || (ImageImpl.this.height == 0) || height.get().equals(ImageImpl.this.height), "can not change height once set");
 
@@ -234,6 +237,8 @@ public class ImageImpl implements Image {
                };
        }
 
+       public static class ImageTitleMustNotBeEmpty extends IllegalStateException { }
+
        //
        // FINGERPRINTABLE METHODS
        //