#41 be explicit that height/width cannot be negative
authorKevin Lamonte <kevin.lamonte@gmail.com>
Thu, 1 Aug 2019 21:35:25 +0000 (16:35 -0500)
committerKevin Lamonte <kevin.lamonte@gmail.com>
Thu, 1 Aug 2019 21:35:25 +0000 (16:35 -0500)
src/jexer/TWidget.java

index c9e0dedc2b652e60a308b5f7a7104d739fd7242c..8a49c816ac1ceb8ab847cadeef41f25b3cc30d9f 100644 (file)
@@ -204,6 +204,13 @@ public abstract class TWidget implements Comparable<TWidget> {
     protected TWidget(final TWidget parent, final boolean enabled,
         final int x, final int y, final int width, final int height) {
 
+        if (width < 0) {
+            throw new IllegalArgumentException("width cannot be negative");
+        }
+        if (height < 0) {
+            throw new IllegalArgumentException("height cannot be negative");
+        }
+
         this.enabled = enabled;
         this.parent = parent;
         this.window = parent.window;
@@ -234,6 +241,13 @@ public abstract class TWidget implements Comparable<TWidget> {
     protected final void setupForTWindow(final TWindow window,
         final int x, final int y, final int width, final int height) {
 
+        if (width < 0) {
+            throw new IllegalArgumentException("width cannot be negative");
+        }
+        if (height < 0) {
+            throw new IllegalArgumentException("height cannot be negative");
+        }
+
         this.parent = window;
         this.window = window;
         this.x      = x;