Leon A created GROOVY-10142:
-------------------------------
Summary: Infinite loop when clearing tye Parameterized Type Cache
Key: GROOVY-10142
URL: https://issues.apache.org/jira/browse/GROOVY-10142
Project: Groovy
Issue Type: Bug
Components: Static compilation, Static Type Checker
Affects Versions: 3.0.8
Reporter: Leon A
I have application that essential makes concurrent calls to a method similar to
the one below
{code:java}
Script compileConcurrently(String source) {
Script = (Script) groovyClassLoader.parseClass(source).newInstance();
GenericsUtils.clearParameterizedTypeCache();
StaticTypeCheckingSupport.clearExtensionMethodCache();
return script;
}{code}
I am running into an issue where one thread gets stuck in an infinite loop in
theĀ GenericsUtils::clearParameterizedTypeCache method while other threads are
waiting in GroovyClassLoader::parseClass
I see PARAMETERIZED_TYPE_CACHE is backed by an access-ordered LinkedHashMap
guarded with ReadWriteLock. I think the root cause is concurrent
LinkedHashMap::get calls modifies the order of the map entries and creates a
loop.
See
[LinkedHashMap|https://docs.oracle.com/javase/8/docs/api/java/util/LinkedHashMap.html]
api docs
{noformat}
Note that this implementation is not synchronized. If multiple threads access a
linked hash map concurrently, and at least one of the threads modifies the map
structurally, it must be synchronized externally. This is typically
accomplished by synchronizing on some object that naturally encapsulates the
map. If no such object exists, the map should be "wrapped" using the
Collections.synchronizedMap method. This is best done at creation time, to
prevent accidental unsynchronized access to the map:
Map m = Collections.synchronizedMap(new LinkedHashMap(...));
A structural modification is any operation that adds or deletes one or more
mappings or, in the case of access-ordered linked hash maps, affects iteration
order. In insertion-ordered linked hash maps, merely changing the value
associated with a key that is already contained in the map is not a structural
modification. In access-ordered linked hash maps, merely querying the map with
get is a structural modification. )
{noformat}
--
This message was sent by Atlassian Jira
(v8.3.4#803005)