[jira] Created: (BEANUTILS-318) Many threads are stuck in infinite loops in MethodUtils because static WeakHashMap is not thread safe

classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|

[jira] Created: (BEANUTILS-318) Many threads are stuck in infinite loops in MethodUtils because static WeakHashMap is not thread safe

Richard (Jira)
Many threads are stuck in infinite loops in MethodUtils  because static WeakHashMap is not thread safe
------------------------------------------------------------------------------------------------------

                 Key: BEANUTILS-318
                 URL: https://issues.apache.org/jira/browse/BEANUTILS-318
             Project: Commons BeanUtils
          Issue Type: Bug
          Components: Bean / Property Utils
    Affects Versions: 1.7.0
         Environment: Weblogic 9.2 on Linux, but should not be relevant
            Reporter: Sylvain Legault


The problem lies in the class org.apache.commons.beanutils.MethodUtils. This class is keeping a global cache in a non synchronized WeakHashMap. WeakHashMap is not thread safe and required external synchronization. The lack of synchronization can cause corruption and the WeakHashMap.get() method to go into an infinite loop.

Googling "WeakHashMap infinite loop" returns many cases of similar problem with WeakHashMap. The solution is to decorate the WeakHashMap in a synchronized Map as described in this thread:
http://dev.eclipse.org/mhonarc/lists/aspectj-users/msg08824.html

The modification to make the MethodUtils cache thread safe is a one line change.
Before:
private static WeakHashMap cache = new WeakHashMap();

After:
private static Map cache = Collections.synchronizedMap(new WeakHashMap());

Example of thread dump

"ExecuteThread: '0' for queue: 'weblogic.kernel.Default'" id=13 idx=0x3c tid=5905 prio=5 alive, daemon
    at org/apache/commons/beanutils/MethodUtils$MethodDescriptor.equals(MethodUtils.java:828)[optimized]
    at java/util/WeakHashMap.eq(WeakHashMap.java:254)[inlined]
    at java/util/WeakHashMap.get(WeakHashMap.java:345)[optimized]
    at org/apache/commons/beanutils/MethodUtils.getMatchingAccessibleMethod(MethodUtils.java:530)[optimized]
    at org/apache/commons/beanutils/MethodUtils.invokeMethod(MethodUtils.java:209)[inlined]
::::

"ExecuteThread: '1' for queue: 'weblogic.kernel.Default'" id=14 idx=0x40 tid=5906 prio=5 alive, daemon
    at org/apache/commons/beanutils/MethodUtils$MethodDescriptor.equals(MethodUtils.java:833)[optimized]
    at java/util/WeakHashMap.eq(WeakHashMap.java:254)[inlined]
    at java/util/WeakHashMap.get(WeakHashMap.java:345)[optimized]
    at org/apache/commons/beanutils/MethodUtils.getMatchingAccessibleMethod(MethodUtils.java:530)[optimized]
    at org/apache/commons/beanutils/MethodUtils.invokeMethod(MethodUtils.java:209)[inlined]
:::
"ExecuteThread: '2' for queue: 'weblogic.kernel.Default'" id=15 idx=0x44 tid=5907 prio=5 alive, daemon
    at org/apache/commons/beanutils/MethodUtils$MethodDescriptor.equals(MethodUtils.java:833)[optimized]
    at java/util/WeakHashMap.eq(WeakHashMap.java:254)[inlined]
    at java/util/WeakHashMap.get(WeakHashMap.java:345)[optimized]
    at org/apache/commons/beanutils/MethodUtils.getMatchingAccessibleMethod(MethodUtils.java:530)[optimized]
    at org/apache/commons/beanutils/MethodUtils.invokeMethod(MethodUtils.java:209)[inlined]




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

Reply | Threaded
Open this post in threaded view
|

[jira] Updated: (BEANUTILS-318) Many threads are stuck in infinite loops in MethodUtils because static WeakHashMap is not thread safe

Richard (Jira)

     [ https://issues.apache.org/jira/browse/BEANUTILS-318?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Niall Pemberton updated BEANUTILS-318:
--------------------------------------

    Fix Version/s: 1.8.0

> Many threads are stuck in infinite loops in MethodUtils  because static WeakHashMap is not thread safe
> ------------------------------------------------------------------------------------------------------
>
>                 Key: BEANUTILS-318
>                 URL: https://issues.apache.org/jira/browse/BEANUTILS-318
>             Project: Commons BeanUtils
>          Issue Type: Bug
>          Components: Bean / Property Utils
>    Affects Versions: 1.7.0
>         Environment: Weblogic 9.2 on Linux, but should not be relevant
>            Reporter: Sylvain Legault
>             Fix For: 1.8.0
>
>
> The problem lies in the class org.apache.commons.beanutils.MethodUtils. This class is keeping a global cache in a non synchronized WeakHashMap. WeakHashMap is not thread safe and required external synchronization. The lack of synchronization can cause corruption and the WeakHashMap.get() method to go into an infinite loop.
> Googling "WeakHashMap infinite loop" returns many cases of similar problem with WeakHashMap. The solution is to decorate the WeakHashMap in a synchronized Map as described in this thread:
> http://dev.eclipse.org/mhonarc/lists/aspectj-users/msg08824.html
> The modification to make the MethodUtils cache thread safe is a one line change.
> Before:
> private static WeakHashMap cache = new WeakHashMap();
> After:
> private static Map cache = Collections.synchronizedMap(new WeakHashMap());
> Example of thread dump
> "ExecuteThread: '0' for queue: 'weblogic.kernel.Default'" id=13 idx=0x3c tid=5905 prio=5 alive, daemon
>     at org/apache/commons/beanutils/MethodUtils$MethodDescriptor.equals(MethodUtils.java:828)[optimized]
>     at java/util/WeakHashMap.eq(WeakHashMap.java:254)[inlined]
>     at java/util/WeakHashMap.get(WeakHashMap.java:345)[optimized]
>     at org/apache/commons/beanutils/MethodUtils.getMatchingAccessibleMethod(MethodUtils.java:530)[optimized]
>     at org/apache/commons/beanutils/MethodUtils.invokeMethod(MethodUtils.java:209)[inlined]
> ::::
> "ExecuteThread: '1' for queue: 'weblogic.kernel.Default'" id=14 idx=0x40 tid=5906 prio=5 alive, daemon
>     at org/apache/commons/beanutils/MethodUtils$MethodDescriptor.equals(MethodUtils.java:833)[optimized]
>     at java/util/WeakHashMap.eq(WeakHashMap.java:254)[inlined]
>     at java/util/WeakHashMap.get(WeakHashMap.java:345)[optimized]
>     at org/apache/commons/beanutils/MethodUtils.getMatchingAccessibleMethod(MethodUtils.java:530)[optimized]
>     at org/apache/commons/beanutils/MethodUtils.invokeMethod(MethodUtils.java:209)[inlined]
> :::
> "ExecuteThread: '2' for queue: 'weblogic.kernel.Default'" id=15 idx=0x44 tid=5907 prio=5 alive, daemon
>     at org/apache/commons/beanutils/MethodUtils$MethodDescriptor.equals(MethodUtils.java:833)[optimized]
>     at java/util/WeakHashMap.eq(WeakHashMap.java:254)[inlined]
>     at java/util/WeakHashMap.get(WeakHashMap.java:345)[optimized]
>     at org/apache/commons/beanutils/MethodUtils.getMatchingAccessibleMethod(MethodUtils.java:530)[optimized]
>     at org/apache/commons/beanutils/MethodUtils.invokeMethod(MethodUtils.java:209)[inlined]

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

Reply | Threaded
Open this post in threaded view
|

[jira] Commented: (BEANUTILS-318) Many threads are stuck in infinite loops in MethodUtils because static WeakHashMap is not thread safe

Richard (Jira)
In reply to this post by Richard (Jira)

    [ https://issues.apache.org/jira/browse/BEANUTILS-318?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12605065#action_12605065 ]

Sylvain Legault commented on BEANUTILS-318:
-------------------------------------------

Just to be sure, for me this problem is a different problem than BEANUTILS-291.

Thanks
Sylvain

> Many threads are stuck in infinite loops in MethodUtils  because static WeakHashMap is not thread safe
> ------------------------------------------------------------------------------------------------------
>
>                 Key: BEANUTILS-318
>                 URL: https://issues.apache.org/jira/browse/BEANUTILS-318
>             Project: Commons BeanUtils
>          Issue Type: Bug
>          Components: Bean / Property Utils
>    Affects Versions: 1.7.0
>         Environment: Weblogic 9.2 on Linux, but should not be relevant
>            Reporter: Sylvain Legault
>             Fix For: 1.8.0
>
>
> The problem lies in the class org.apache.commons.beanutils.MethodUtils. This class is keeping a global cache in a non synchronized WeakHashMap. WeakHashMap is not thread safe and required external synchronization. The lack of synchronization can cause corruption and the WeakHashMap.get() method to go into an infinite loop.
> Googling "WeakHashMap infinite loop" returns many cases of similar problem with WeakHashMap. The solution is to decorate the WeakHashMap in a synchronized Map as described in this thread:
> http://dev.eclipse.org/mhonarc/lists/aspectj-users/msg08824.html
> The modification to make the MethodUtils cache thread safe is a one line change.
> Before:
> private static WeakHashMap cache = new WeakHashMap();
> After:
> private static Map cache = Collections.synchronizedMap(new WeakHashMap());
> Example of thread dump
> "ExecuteThread: '0' for queue: 'weblogic.kernel.Default'" id=13 idx=0x3c tid=5905 prio=5 alive, daemon
>     at org/apache/commons/beanutils/MethodUtils$MethodDescriptor.equals(MethodUtils.java:828)[optimized]
>     at java/util/WeakHashMap.eq(WeakHashMap.java:254)[inlined]
>     at java/util/WeakHashMap.get(WeakHashMap.java:345)[optimized]
>     at org/apache/commons/beanutils/MethodUtils.getMatchingAccessibleMethod(MethodUtils.java:530)[optimized]
>     at org/apache/commons/beanutils/MethodUtils.invokeMethod(MethodUtils.java:209)[inlined]
> ::::
> "ExecuteThread: '1' for queue: 'weblogic.kernel.Default'" id=14 idx=0x40 tid=5906 prio=5 alive, daemon
>     at org/apache/commons/beanutils/MethodUtils$MethodDescriptor.equals(MethodUtils.java:833)[optimized]
>     at java/util/WeakHashMap.eq(WeakHashMap.java:254)[inlined]
>     at java/util/WeakHashMap.get(WeakHashMap.java:345)[optimized]
>     at org/apache/commons/beanutils/MethodUtils.getMatchingAccessibleMethod(MethodUtils.java:530)[optimized]
>     at org/apache/commons/beanutils/MethodUtils.invokeMethod(MethodUtils.java:209)[inlined]
> :::
> "ExecuteThread: '2' for queue: 'weblogic.kernel.Default'" id=15 idx=0x44 tid=5907 prio=5 alive, daemon
>     at org/apache/commons/beanutils/MethodUtils$MethodDescriptor.equals(MethodUtils.java:833)[optimized]
>     at java/util/WeakHashMap.eq(WeakHashMap.java:254)[inlined]
>     at java/util/WeakHashMap.get(WeakHashMap.java:345)[optimized]
>     at org/apache/commons/beanutils/MethodUtils.getMatchingAccessibleMethod(MethodUtils.java:530)[optimized]
>     at org/apache/commons/beanutils/MethodUtils.invokeMethod(MethodUtils.java:209)[inlined]

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

Reply | Threaded
Open this post in threaded view
|

[jira] Resolved: (BEANUTILS-318) Many threads are stuck in infinite loops in MethodUtils because static WeakHashMap is not thread safe

Richard (Jira)
In reply to this post by Richard (Jira)

     [ https://issues.apache.org/jira/browse/BEANUTILS-318?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Niall Pemberton resolved BEANUTILS-318.
---------------------------------------

    Resolution: Fixed
      Assignee: Niall Pemberton

Thanks for pointing this out - I fixed this using the new WeakFastHashMap implementation which is thread safe:

http://svn.apache.org/viewvc?view=rev&revision=687091

> Many threads are stuck in infinite loops in MethodUtils  because static WeakHashMap is not thread safe
> ------------------------------------------------------------------------------------------------------
>
>                 Key: BEANUTILS-318
>                 URL: https://issues.apache.org/jira/browse/BEANUTILS-318
>             Project: Commons BeanUtils
>          Issue Type: Bug
>          Components: Bean / Property Utils
>    Affects Versions: 1.7.0
>         Environment: Weblogic 9.2 on Linux, but should not be relevant
>            Reporter: Sylvain Legault
>            Assignee: Niall Pemberton
>             Fix For: 1.8.0
>
>
> The problem lies in the class org.apache.commons.beanutils.MethodUtils. This class is keeping a global cache in a non synchronized WeakHashMap. WeakHashMap is not thread safe and required external synchronization. The lack of synchronization can cause corruption and the WeakHashMap.get() method to go into an infinite loop.
> Googling "WeakHashMap infinite loop" returns many cases of similar problem with WeakHashMap. The solution is to decorate the WeakHashMap in a synchronized Map as described in this thread:
> http://dev.eclipse.org/mhonarc/lists/aspectj-users/msg08824.html
> The modification to make the MethodUtils cache thread safe is a one line change.
> Before:
> private static WeakHashMap cache = new WeakHashMap();
> After:
> private static Map cache = Collections.synchronizedMap(new WeakHashMap());
> Example of thread dump
> "ExecuteThread: '0' for queue: 'weblogic.kernel.Default'" id=13 idx=0x3c tid=5905 prio=5 alive, daemon
>     at org/apache/commons/beanutils/MethodUtils$MethodDescriptor.equals(MethodUtils.java:828)[optimized]
>     at java/util/WeakHashMap.eq(WeakHashMap.java:254)[inlined]
>     at java/util/WeakHashMap.get(WeakHashMap.java:345)[optimized]
>     at org/apache/commons/beanutils/MethodUtils.getMatchingAccessibleMethod(MethodUtils.java:530)[optimized]
>     at org/apache/commons/beanutils/MethodUtils.invokeMethod(MethodUtils.java:209)[inlined]
> ::::
> "ExecuteThread: '1' for queue: 'weblogic.kernel.Default'" id=14 idx=0x40 tid=5906 prio=5 alive, daemon
>     at org/apache/commons/beanutils/MethodUtils$MethodDescriptor.equals(MethodUtils.java:833)[optimized]
>     at java/util/WeakHashMap.eq(WeakHashMap.java:254)[inlined]
>     at java/util/WeakHashMap.get(WeakHashMap.java:345)[optimized]
>     at org/apache/commons/beanutils/MethodUtils.getMatchingAccessibleMethod(MethodUtils.java:530)[optimized]
>     at org/apache/commons/beanutils/MethodUtils.invokeMethod(MethodUtils.java:209)[inlined]
> :::
> "ExecuteThread: '2' for queue: 'weblogic.kernel.Default'" id=15 idx=0x44 tid=5907 prio=5 alive, daemon
>     at org/apache/commons/beanutils/MethodUtils$MethodDescriptor.equals(MethodUtils.java:833)[optimized]
>     at java/util/WeakHashMap.eq(WeakHashMap.java:254)[inlined]
>     at java/util/WeakHashMap.get(WeakHashMap.java:345)[optimized]
>     at org/apache/commons/beanutils/MethodUtils.getMatchingAccessibleMethod(MethodUtils.java:530)[optimized]
>     at org/apache/commons/beanutils/MethodUtils.invokeMethod(MethodUtils.java:209)[inlined]

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

Reply | Threaded
Open this post in threaded view
|

[jira] Commented: (BEANUTILS-318) Many threads are stuck in infinite loops in MethodUtils because static WeakHashMap is not thread safe

Richard (Jira)
In reply to this post by Richard (Jira)

    [ https://issues.apache.org/jira/browse/BEANUTILS-318?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12847517#action_12847517 ]

Andrew Sunde commented on BEANUTILS-318:
----------------------------------------

See:   https://issues.apache.org/jira/browse/BEANUTILS-373

Similar issue reopened.

> Many threads are stuck in infinite loops in MethodUtils  because static WeakHashMap is not thread safe
> ------------------------------------------------------------------------------------------------------
>
>                 Key: BEANUTILS-318
>                 URL: https://issues.apache.org/jira/browse/BEANUTILS-318
>             Project: Commons BeanUtils
>          Issue Type: Bug
>          Components: Bean / Property Utils
>    Affects Versions: 1.7.0
>         Environment: Weblogic 9.2 on Linux, but should not be relevant
>            Reporter: Sylvain Legault
>            Assignee: Niall Pemberton
>             Fix For: 1.8.0
>
>
> The problem lies in the class org.apache.commons.beanutils.MethodUtils. This class is keeping a global cache in a non synchronized WeakHashMap. WeakHashMap is not thread safe and required external synchronization. The lack of synchronization can cause corruption and the WeakHashMap.get() method to go into an infinite loop.
> Googling "WeakHashMap infinite loop" returns many cases of similar problem with WeakHashMap. The solution is to decorate the WeakHashMap in a synchronized Map as described in this thread:
> http://dev.eclipse.org/mhonarc/lists/aspectj-users/msg08824.html
> The modification to make the MethodUtils cache thread safe is a one line change.
> Before:
> private static WeakHashMap cache = new WeakHashMap();
> After:
> private static Map cache = Collections.synchronizedMap(new WeakHashMap());
> Example of thread dump
> "ExecuteThread: '0' for queue: 'weblogic.kernel.Default'" id=13 idx=0x3c tid=5905 prio=5 alive, daemon
>     at org/apache/commons/beanutils/MethodUtils$MethodDescriptor.equals(MethodUtils.java:828)[optimized]
>     at java/util/WeakHashMap.eq(WeakHashMap.java:254)[inlined]
>     at java/util/WeakHashMap.get(WeakHashMap.java:345)[optimized]
>     at org/apache/commons/beanutils/MethodUtils.getMatchingAccessibleMethod(MethodUtils.java:530)[optimized]
>     at org/apache/commons/beanutils/MethodUtils.invokeMethod(MethodUtils.java:209)[inlined]
> ::::
> "ExecuteThread: '1' for queue: 'weblogic.kernel.Default'" id=14 idx=0x40 tid=5906 prio=5 alive, daemon
>     at org/apache/commons/beanutils/MethodUtils$MethodDescriptor.equals(MethodUtils.java:833)[optimized]
>     at java/util/WeakHashMap.eq(WeakHashMap.java:254)[inlined]
>     at java/util/WeakHashMap.get(WeakHashMap.java:345)[optimized]
>     at org/apache/commons/beanutils/MethodUtils.getMatchingAccessibleMethod(MethodUtils.java:530)[optimized]
>     at org/apache/commons/beanutils/MethodUtils.invokeMethod(MethodUtils.java:209)[inlined]
> :::
> "ExecuteThread: '2' for queue: 'weblogic.kernel.Default'" id=15 idx=0x44 tid=5907 prio=5 alive, daemon
>     at org/apache/commons/beanutils/MethodUtils$MethodDescriptor.equals(MethodUtils.java:833)[optimized]
>     at java/util/WeakHashMap.eq(WeakHashMap.java:254)[inlined]
>     at java/util/WeakHashMap.get(WeakHashMap.java:345)[optimized]
>     at org/apache/commons/beanutils/MethodUtils.getMatchingAccessibleMethod(MethodUtils.java:530)[optimized]
>     at org/apache/commons/beanutils/MethodUtils.invokeMethod(MethodUtils.java:209)[inlined]

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