glassfish
  1. glassfish
  2. GLASSFISH-18968

Possible atomicity violations because of misusing ConcurrentHashMap

    Details

    • Type: Bug Bug
    • Status: Open
    • Priority: Major Major
    • Resolution: Unresolved
    • Affects Version/s: 3.1.2
    • Fix Version/s: None
    • Component/s: amx
    • Labels:
      None

      Description

      My name is Yu Lin. I'm a Ph.D. student in the CS department at
      UIUC. I'm currently doing research on mining Java concurrent library
      misusages. I found some possible misuses of ConcurrentHashMap in amx
      component of GlassFish 3.1.2, which may result in potential atomicity
      violation bugs.

      The code below is a snapshot of the code in file
      common/amx-core-impl/src/main/java/org/glassfish/admin/amx/impl/mbean/PathnamesImpl.java
      from line 85 to 164

      L85 public ObjectName resolvePath(final String path) {
      L86 ObjectName result = mPathnameCache.get(path);
      L87 if (result != null)

      { L88 return result; L89 }

      ... // create "objectName"
      L159 if (objectName != null)

      { L160 //cdebug( "Matched " + path + " to " + objectName); L161 mPathnameCache.put(path, objectName); L162 }

      L164 return objectName;
      L165 }

      In the code above, there might be an atomicity violation: suppose a
      thread T1 executes line 86 and finds out the concurrent hashmap
      "mPathnameCache" does not contain the key "path". Before it
      gets to execute line 161, another thread T2 puts a pair <path, v>
      in the map "mPathnameCache". Now thread T1 resumes execution and
      it will overwrite the value written by thread T2. Thus, the code no
      longer preserves the "put-if-absent" semantics, and thread T2 will
      return an "objectName" that is not in the map "mPathnameCache". May this
      thread interleaving happen? Will it result in buggy behavior?

      Similar problem can be found in
      common/amx-core/src/main/java/org/glassfish/admin/amx/core/proxy/ProxyFactory.java
      line 434.

      This issue is related to GLASSFISH-18964. I attach a patch to fix the problem.

        Activity

        jacklondongood created issue -

          People

          • Assignee:
            prasads
            Reporter:
            jacklondongood
          • Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

            • Created:
              Updated: