jdk/src/java.desktop/share/classes/javax/swing/ImageIcon.java
changeset 26037 508779ce6619
parent 26001 991e1be0b235
parent 25859 3317bb8137f4
child 32865 f9cb6e427f9e
--- a/jdk/src/java.desktop/share/classes/javax/swing/ImageIcon.java	Mon Aug 18 14:03:21 2014 +0100
+++ b/jdk/src/java.desktop/share/classes/javax/swing/ImageIcon.java	Tue Aug 19 10:32:16 2014 -0700
@@ -490,12 +490,33 @@
     private void readObject(ObjectInputStream s)
         throws ClassNotFoundException, IOException
     {
-        s.defaultReadObject();
+        ObjectInputStream.GetField f = s.readFields();
+
+        imageObserver = (ImageObserver) f.get("imageObserver", null);
+        description = (String) f.get("description", null);
+        width = f.get("width", -1);
+        height = f.get("height", -1);
+        accessibleContext = (AccessibleImageIcon) f.get("accessibleContext", null);
 
         int w = s.readInt();
         int h = s.readInt();
         int[] pixels = (int[])(s.readObject());
 
+        if (pixels == null && (w != -1 || h != -1)) {
+            throw new IllegalStateException("Inconsistent width and height"
+                    + " for null image [" + w + ", " + h + "]");
+        }
+
+        if (pixels != null && (w < 0 || h < 0)) {
+            throw new IllegalStateException("Inconsistent width and height"
+                    + " for image [" + w + ", " + h + "]");
+        }
+
+        if (w != getIconWidth() || h != getIconHeight()) {
+            throw new IllegalStateException("Inconsistent width and height"
+                    + " for image [" + w + ", " + h + "]");
+        }
+
         if (pixels != null) {
             Toolkit tk = Toolkit.getDefaultToolkit();
             ColorModel cm = ColorModel.getRGBdefault();