#71744: I managed to get similar UnsupportedOpEx and prevent it to happen. However I had to do different tricks to similate it - hopefully the root cause will be the same b3_0_0_root generic_67888_root issue73042_base
authorjtulach@netbeans.org
Thu, 09 Mar 2006 07:20:46 +0000
changeset 13099bf3b6ecd3f
parent 129 fccb092d4adb
child 131 6e8c01adc7c1
#71744: I managed to get similar UnsupportedOpEx and prevent it to happen. However I had to do different tricks to similate it - hopefully the root cause will be the same
openide.util/src/org/openide/util/lookup/InheritanceTree.java
openide.util/test/unit/src/org/openide/util/lookup/AbstractLookupTest.java
openide.util/test/unit/src/org/openide/util/lookup/InheritanceTreeTest.java
     1.1 --- a/openide.util/src/org/openide/util/lookup/InheritanceTree.java	Tue Mar 07 06:12:43 2006 +0000
     1.2 +++ b/openide.util/src/org/openide/util/lookup/InheritanceTree.java	Thu Mar 09 07:20:46 2006 +0000
     1.3 @@ -1081,7 +1081,11 @@
     1.4          /** Marks this item as being deserialized.
     1.5           */
     1.6          public void markDeserialized() {
     1.7 -            items = (items == null) ? Collections.EMPTY_LIST : Collections.synchronizedList(items);
     1.8 +            if (items == null || items == Collections.EMPTY_LIST) {
     1.9 +                items = Collections.EMPTY_LIST;
    1.10 +            } else {
    1.11 +                items = Collections.synchronizedList(items);
    1.12 +            }
    1.13          }
    1.14  
    1.15          /** Getter for the type associated with this node.
     2.1 --- a/openide.util/test/unit/src/org/openide/util/lookup/AbstractLookupTest.java	Tue Mar 07 06:12:43 2006 +0000
     2.2 +++ b/openide.util/test/unit/src/org/openide/util/lookup/AbstractLookupTest.java	Thu Mar 09 07:20:46 2006 +0000
     2.3 @@ -20,6 +20,7 @@
     2.4  import junit.framework.*;
     2.5  import org.netbeans.junit.*;
     2.6  import java.io.Serializable;
     2.7 +import org.openide.util.io.NbMarshalledObject;
     2.8  
     2.9  public class AbstractLookupTest extends AbstractLookupBaseHid implements AbstractLookupBaseHid.Impl {
    2.10      public AbstractLookupTest(java.lang.String testName) {
    2.11 @@ -210,4 +211,72 @@
    2.12          lookup.toAdd = null; // this will add integer
    2.13          assertEquals ("Two classes now", 2, res.allClasses ().size ());
    2.14      }
    2.15 +
    2.16 +    public void testInconsistentAfterDeserIssue71744() throws Exception {
    2.17 +        InheritanceTree inhTree = new InheritanceTree();
    2.18 +
    2.19 +        AbstractLookup al = new AbstractLookup(new AbstractLookup.Content(), inhTree);
    2.20 +        {
    2.21 +
    2.22 +            Collection r = al.lookup(new Lookup.Template(Integer.class)).allInstances();
    2.23 +            assertEquals("None", 0, r.size());
    2.24 +        }
    2.25 +
    2.26 +        ICP item = new ICP(new Integer(10));
    2.27 +        al.addPair(item);
    2.28 +        al.removePair(item);
    2.29 +
    2.30 +        NbMarshalledObject mar = new NbMarshalledObject(al);
    2.31 +
    2.32 +        AbstractLookup newLookup = (AbstractLookup)mar.get();
    2.33 +
    2.34 +        newLookup.lookup(Number.class);
    2.35 +
    2.36 +
    2.37 +        newLookup.addPair(new ICP(new Long(20)));
    2.38 +
    2.39 +        {
    2.40 +
    2.41 +            Collection r = newLookup.lookup(new Lookup.Template(Number.class)).allInstances();
    2.42 +            assertEquals("one", 1, r.size());
    2.43 +/*
    2.44 +            Iterator it = r.iterator();
    2.45 +            assertEquals(new Integer(10), it.next());
    2.46 +            assertEquals(new Long(20), it.next());*/
    2.47 +        }
    2.48 +    }
    2.49 +
    2.50 +    private static final class ICP extends AbstractLookup.Pair {
    2.51 +        private Number s;
    2.52 +
    2.53 +        public ICP (Number s) {
    2.54 +            this.s = s;
    2.55 +        }
    2.56 +
    2.57 +
    2.58 +        protected boolean instanceOf(Class c) {
    2.59 +            return c.isInstance(s);
    2.60 +        }
    2.61 +
    2.62 +        protected boolean creatorOf(Object obj) {
    2.63 +            return s == obj;
    2.64 +        }
    2.65 +
    2.66 +        public Object getInstance() {
    2.67 +            return s;
    2.68 +        }
    2.69 +
    2.70 +        public Class getType() {
    2.71 +            return s.getClass();
    2.72 +        }
    2.73 +
    2.74 +        public String getId() {
    2.75 +            return s.toString();
    2.76 +        }
    2.77 +
    2.78 +        public String getDisplayName() {
    2.79 +            return getId();
    2.80 +        }
    2.81 +
    2.82 +    }
    2.83  }
     3.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     3.2 +++ b/openide.util/test/unit/src/org/openide/util/lookup/InheritanceTreeTest.java	Thu Mar 09 07:20:46 2006 +0000
     3.3 @@ -0,0 +1,49 @@
     3.4 +/*
     3.5 + *                 Sun Public License Notice
     3.6 + * 
     3.7 + * The contents of this file are subject to the Sun Public License
     3.8 + * Version 1.0 (the "License"). You may not use this file except in
     3.9 + * compliance with the License. A copy of the License is available at
    3.10 + * http://www.sun.com/
    3.11 + * 
    3.12 + * The Original Code is NetBeans. The Initial Developer of the Original
    3.13 + * Code is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
    3.14 + * Microsystems, Inc. All Rights Reserved.
    3.15 + */
    3.16 +package org.openide.util.lookup;
    3.17 +
    3.18 +import junit.framework.TestCase;
    3.19 +import junit.framework.*;
    3.20 +import org.openide.util.Lookup;
    3.21 +import org.openide.util.lookup.AbstractLookup.ReferenceIterator;
    3.22 +import org.openide.util.lookup.AbstractLookup.ReferenceToResult;
    3.23 +import java.io.*;
    3.24 +import java.lang.ref.WeakReference;
    3.25 +import java.util.*;
    3.26 +
    3.27 +/**
    3.28 + *
    3.29 + * @author Jaroslav Tulach
    3.30 + */
    3.31 +public class InheritanceTreeTest extends TestCase {
    3.32 +    
    3.33 +    public InheritanceTreeTest(String testName) {
    3.34 +        super(testName);
    3.35 +    }
    3.36 +
    3.37 +    protected void setUp() throws Exception {
    3.38 +    }
    3.39 +
    3.40 +    protected void tearDown() throws Exception {
    3.41 +    }
    3.42 +
    3.43 +    public void testDeserOfNode() {
    3.44 +        InheritanceTree inh = new InheritanceTree();
    3.45 +        InheritanceTree.Node n = new InheritanceTree.Node(String.class);
    3.46 +        n.markDeserialized();
    3.47 +        n.markDeserialized();
    3.48 +
    3.49 +        n.assignItem(inh, new InstanceContent.SimpleItem("Ahoj"));
    3.50 +    }
    3.51 +    
    3.52 +}