River
  1. River
  2. RIVER-153

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

    Details

    • Type: Bug Bug
    • Status: Open
    • Priority: Minor Minor
    • Resolution: Unresolved
    • Affects Version/s: jtsk_2.0
    • Fix Version/s: None
    • Component/s: net_jini_lookup
    • Labels:
      None
    • Bugtraq ID:
      4985633

      Description

      Bugtraq 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

        Activity

        There are no comments yet on this issue.

          People

          • Assignee:
            Unassigned
            Reporter:
            Bob Scheifler
          • Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

            • Created:
              Updated:

              Development