struts-issues mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Yu Lin (JIRA)" <j...@apache.org>
Subject [jira] [Commented] (WW-3845) atomicity violation bugs because of misusing concurrent collections
Date Fri, 06 Jul 2012 23:10:35 GMT

    [ https://issues.apache.org/jira/browse/WW-3845?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13408432#comment-13408432
] 

Yu Lin commented on WW-3845:
----------------------------

Unfortunately, your patch still has atomicity violation. Whoever is the last thread to put
pair <clz, standardAttributes> will overwrite the value put there by the previous thread.
This destroys the put-if-absent semantics of the original code (You may read my previous explanation
in the bug description).
                
> atomicity violation bugs because of misusing concurrent collections
> -------------------------------------------------------------------
>
>                 Key: WW-3845
>                 URL: https://issues.apache.org/jira/browse/WW-3845
>             Project: Struts 2
>          Issue Type: Bug
>    Affects Versions: 2.3.4
>            Reporter: Yu Lin
>              Labels: patch
>             Fix For: 2.3.5
>
>         Attachments: UIBean.patch, struts-2.3.4.patch
>
>   Original Estimate: 504h
>  Remaining Estimate: 504h
>
> 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 misusages of ConcurrentHashMap in Struts
> 2.3.4, which may result in potential atomicity violation bugs or harm
> the performance.
> The code below is a snapshot of the code in file
> core/src/main/java/org/apache/struts2/components/UIBean.java from line
> 1227 to 1244
> L1227        Set<String> standardAttributes = standardAttributesMap.get(clz);
> L1228        if (standardAttributes == null) {
> L1229            standardAttributes = new HashSet<String>();
> L1230            standardAttributesMap.put(clz, standardAttributes);
>                  ...
> L1244        }
> In the code above, an atomicity violation may occur between lines
> <1228 and 1230>. Suppose a thread T1 executes line 1227 and finds out
> the concurrent hashmap "standardAttributes" dose not contain the key
> "clz". Before it gets to execute line 1230, another thread T2 puts a
> pair <clz, v> in the concurrent hashmap "standardAttributes". 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.
> I found some similar misusages in other files:
> In
> xwork-core/src/main/java/com/opensymphony/xwork2/ognl/OgnlUtil.java,
> there are similar atomicity violations as the above code at lines 242
> and 415. Note that if we change "beanInfoCache.put" to
> "beanInfoCache.putIfAbsent" at line 415, the synchronized key word on
> "beanInfoCache" can be removed so that the performance can be improved.
> Similarly, in
> xwork-core/src/main/java/com/opensymphony/xwork2/util/LocalizedTextUtil.java,
> atomicity violations may occur at line 254, 263 and 707 (thread T2 may
> put a pair <key, value> into the map before thread T1 puts). Second,
> before thread T1 executes line 257 or 266, thread T2 may remove the
> key "key" from concurrent hashmap "bundlesMap". Thus, after T1 resumes
> execution, it will get null value at line 257 or 266, which is also an
> atomicity violation.

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

        

Mime
View raw message