#130673: Preventing NPE when there is broken Pair impl release61_base
authorJaroslav Tulach <jtulach@netbeans.org>
Fri, 28 Mar 2008 15:03:22 +0100
changeset 359e146b3952b0d
parent 358 b6c302ee1046
child 363 86420af6153d
#130673: Preventing NPE when there is broken Pair impl
openide.util/src/org/openide/util/lookup/AbstractLookup.java
openide.util/test/unit/src/org/openide/util/lookup/AbstractLookupTest.java
     1.1 --- a/openide.util/src/org/openide/util/lookup/AbstractLookup.java	Fri Mar 28 14:55:23 2008 +0100
     1.2 +++ b/openide.util/src/org/openide/util/lookup/AbstractLookup.java	Fri Mar 28 15:03:22 2008 +0100
     1.3 @@ -525,7 +525,7 @@
     1.4      static boolean matches(Template<?> t, Pair<?> item, boolean deepCheck) {
     1.5          String id = t.getId();
     1.6  
     1.7 -        if ((id != null) && !item.getId().equals(id)) {
     1.8 +        if (id != null && !id.equals(item.getId())) {
     1.9              return false;
    1.10          }
    1.11  
     2.1 --- a/openide.util/test/unit/src/org/openide/util/lookup/AbstractLookupTest.java	Fri Mar 28 14:55:23 2008 +0100
     2.2 +++ b/openide.util/test/unit/src/org/openide/util/lookup/AbstractLookupTest.java	Fri Mar 28 15:03:22 2008 +0100
     2.3 @@ -49,6 +49,7 @@
     2.4  import org.netbeans.junit.*;
     2.5  import java.io.Serializable;
     2.6  import org.openide.util.io.NbMarshalledObject;
     2.7 +import org.openide.util.lookup.AbstractLookup.Pair;
     2.8  
     2.9  public class AbstractLookupTest extends AbstractLookupBaseHid implements AbstractLookupBaseHid.Impl {
    2.10      public AbstractLookupTest(java.lang.String testName) {
    2.11 @@ -274,6 +275,46 @@
    2.12          }
    2.13      }
    2.14  
    2.15 +    public void testMatchesIssue130673() {
    2.16 +        class BrokenPairReturningNullID extends Pair<Object> {
    2.17 +            @Override
    2.18 +            protected boolean instanceOf(Class<?> c) {
    2.19 +                return false;
    2.20 +            }
    2.21 +
    2.22 +            @Override
    2.23 +            protected boolean creatorOf(Object obj) {
    2.24 +                return false;
    2.25 +            }
    2.26 +
    2.27 +            @Override
    2.28 +            public Object getInstance() {
    2.29 +                return null;
    2.30 +            }
    2.31 +
    2.32 +            @Override
    2.33 +            public Class<? extends Object> getType() {
    2.34 +                return null;
    2.35 +            }
    2.36 +
    2.37 +            @Override
    2.38 +            public String getId() {
    2.39 +                return null;
    2.40 +            }
    2.41 +
    2.42 +            @Override
    2.43 +            public String getDisplayName() {
    2.44 +                return null;
    2.45 +            }
    2.46 +        }
    2.47 +        BrokenPairReturningNullID broken = new BrokenPairReturningNullID();
    2.48 +        
    2.49 +        
    2.50 +        Lookup.Template<String> t = new Lookup.Template<String>(String.class, "ID", null);
    2.51 +        boolean not = AbstractLookup.matches(t, broken, true);
    2.52 +        assertFalse("Does not match the template, but throws no exception", not);
    2.53 +    }
    2.54 +    
    2.55      private static final class ICP extends AbstractLookup.Pair {
    2.56          private Number s;
    2.57