You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@river.apache.org by "Bob Scheifler (JIRA)" <ji...@apache.org> on 2007/07/30 19:01:52 UTC

[jira] Created: (RIVER-153) SDM - investigate possible NPE's in various places due to null filteredItem

SDM - investigate possible NPE's in various places due to null filteredItem
---------------------------------------------------------------------------

                 Key: RIVER-153
                 URL: https://issues.apache.org/jira/browse/RIVER-153
             Project: River
          Issue Type: Bug
          Components: net_jini_lookup
    Affects Versions: jtsk_2.0
            Reporter: Bob Scheifler
            Priority: Minor


Bugtraq ID [4985633|http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=4985633]

While code reviewing the fix for bug 4972100 (SDM NPE in getServiceItems 
when blocking lookup called before filter is applied), rws observed a 
number of other places in the SDM where filteredItem might possibly be 
null, which would result in a NullPointerException. (See the Comments
section.)

Because a NPE caused by the conditions described above has neither been
reported by users, nor has it been observed in the SDM tests, the code
needs to be analyzed further to determine if this actually is a bug, and
whether such a situation can be reproduced.

Comments

From: Bob.Scheifler@Sun.com
To: brian.t.murphy@sun.com
Subject: Re: Code Review Request - SDM NPE in getServiceItems (4972100)

> itemReg.filteredItem.service is accessed at line 1527, in the method
> LookupCache.discard(). 

> I couldn't establish that itemReg.filteredItem would ever be null
> when that method is called.

Attached is a simple program to cause it.

>From initial scan I think NPE is also possible at line 1035,
and use of null values is possible at lines 1216, 1921, and 1923.
I haven't looked for possibilities at higher line numbers (ran
out of time today).

- Bob

import net.jini.core.lookup.*;
import net.jini.discovery.*;
import net.jini.lookup.*;

public class CacheTest {
    static LookupCache cache;
    static Object lock = new Object();

    public static class Filter implements ServiceItemFilter {
        public boolean check(ServiceItem item) {
            item.service = null;
            synchronized (lock) {
                System.out.println("notifying");
                lock.notifyAll();
            }
            return true;
        }
    }

    public static void main(String[] args) throws Exception {
        System.setSecurityManager(new SecurityManager());
        ServiceDiscoveryManager sdm =
            new ServiceDiscoveryManager(
                new LookupDiscoveryManager(args, null, null),
                null);
        synchronized (lock) {
            cache = sdm.createLookupCache(null, new Filter(), null);
            System.out.println("waiting");
            lock.wait();
        }
        try {
            Thread.sleep(5000);
        } catch (Exception e) {
        }
        System.out.println("discarding");
        cache.discard("");
    }
}

-------------------------------------------------------------------------------
Note:  the program above causes the NPE because it simulates behavior
       by the user that some might consider out of the ordinary. That is,
       When discard is called, it is called using an object (the String "")
       that is not in the cache. One might expect the user to only call
       discard using a reference to an object that it previously discovered;
       in which case, the NPE could not be reproduced. Nevertheless, the
       code should be changed to protect against "operator error".
-------------------------------------------------------------------------------

From: Bob.Scheifler@Sun.com
To: brian.t.murphy@sun.com
Subject: Re: Code Review Request - SDM NPE in getServiceItems (4972100)

>>and use of null values is possible at lines 1216

I haven't worked through the paths in detail, but my
concern is that a concurrent call to itemMatchMatchChange
taking place while this thread is at line 1213 can cause
itemReg.filteredItem to become null.

- Bob



-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.