[jboss-jira] [JBoss JIRA] (JBCOMMON-126) NullPointerException when using PropertyMap concurrently

Michael Pradel (JIRA) jira-events at lists.jboss.org
Fri Jul 27 06:34:07 EDT 2012


Michael Pradel created JBCOMMON-126:
---------------------------------------

             Summary: NullPointerException when using PropertyMap concurrently
                 Key: JBCOMMON-126
                 URL: https://issues.jboss.org/browse/JBCOMMON-126
             Project: JBoss Common
          Issue Type: Bug
      Security Level: Public (Everyone can see)
          Components: common-core (2.x)
    Affects Versions: 2.2.18.GA 
         Environment: All environments
            Reporter: Michael Pradel


PropertyMap extends Properties, which is a thread-safe class, but it doesn't preserve its thread safety. This leads to surprising crashes if you have a reference of type Properties (documented as thread-safe) that turns out to be a PropertyMap (not thread-safe).

Here's a simplified example that shows how we hit this bug:

final Properties p = getProps();
p.setProperty("a", "b");
		
Thread t1 = new Thread(new Runnable() {
  public void run() { p.remove("a"); }
});

Thread t2 = new Thread(new Runnable() {
  public void run() { p.clear(); }
});
t1.start();
t2.start();
try { t1.join(); t2.join(); 
} catch (InterruptedException e) {
  e.printStackTrace();
}

Properties getProps() {
  // return new Properties(); // OK
  return new PropertyMap(); // leads to NullPointerException
}


The code runs fine if getProps returns Properties (as it should, because Properties is thread-safe), but raises a NullPointerException if getProps returns a PropertyMap.

Are you aware of this inconsistency? It seems that the safest way of extending Properties is to make methods that override synchronized methods synchronized.

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators: https://issues.jboss.org/secure/ContactAdministrators!default.jspa
For more information on JIRA, see: http://www.atlassian.com/software/jira

        


More information about the jboss-jira mailing list