EVALUATION
problems are in the fiollowing code:
Component [] tmpComponent = (Component[])f.get("component", EMPTY_ARRAY);
component = new java.util.ArrayList<Component>();
component.addAll(Arrays.asList(tmpComponent));
sometimes we may have null as value of "component" field in the stream and we have
NPE in Arrays.asList()
Another problem is that tmpComponents may contain nulls (remove() may just set null to
array and reduce ncomponents field).
So, to fix the latter problem we should check value of ncomponents and add only first "ncomponents" elements.
And the same change fixes the former problems because iftmpComponent is null, ncomponents == 0, and so we add nothing.
|
SUGGESTED FIX
--- old/src/share/classes/java/awt/Container.java 2008-05-07 15:56:50.000000000 +0400
+++ new/src/share/classes/java/awt/Container.java 2008-05-07 15:56:50.000000000 +0400
@@ -3565,8 +3565,11 @@
{
ObjectInputStream.GetField f = s.readFields();
Component [] tmpComponent = (Component[])f.get("component", EMPTY_ARRAY);
- component = new java.util.ArrayList<Component>();
- component.addAll(Arrays.asList(tmpComponent));
+ int ncomponents = (Integer) f.get("ncomponents", 0);
+ component = new java.util.ArrayList<Component>(ncomponents);
+ for (int i = 0; i < ncomponents; ++i) {
+ component.add(tmpComponent[i]);
+ }
layoutMgr = (LayoutManager)f.get("layoutMgr", null);
dispatcher = (LightweightDispatcher)f.get("dispatcher", null);
// Old stream. Doesn't contain maxSize among Component's fields.
|