codeconsole opened a new pull request, #3279: URL: https://github.com/apache/groovy/pull/3279
https://issues.apache.org/jira/browse/GROOVY-12744 ## Problem Node metadata lives in a `ListHashMap` wrapped in `Collections.synchronizedMap` (GROOVY-11966). The wrapper creates its `entrySet()`, `keySet()` and `values()` views on first use and keeps returning them. With up to three entries, `ListHashMap` returned those views from a copy of its arrays, not from the map itself. So after the first `getNodeMetaData()` or `copyNodeMetaData(node)`, every later read or copy of that node returned the old entries. Entries added since were missing, removed ones were still there, and replaced values kept their old value. In the core test suite this happens during static compilation. Copies of map-style `ConstructorCallExpression`s and of a `PropertyExpression` took a `DIRECT_METHOD_CALL_TARGET` from an earlier type-checking pass. In every case found, the old and new targets have the same signature, so no wrong bytecode was found. ## Fix `ListHashMap.entrySet()`, `keySet()` and `values()` now return views backed by the map, as the `Map` contract requires: `size()`, `contains` and each new iterator see the map's current entries. Each iterator still works on a copy of the entries while the map keeps them in its arrays (up to three by default), and on a read-only view of the backing map otherwise, as before. The views still can't change the map. ## Tests - `ListHashMapTest`: the views and a `synchronizedMap` wrapper see later puts, replacements and removals, across both storage switches. - `ASTNodeTest`: `getNodeMetaData()` and `copyNodeMetaData` see entries added, replaced and removed after an earlier snapshot. Both fail without the fix. The full core `:test` suite, `NodeMetaDataHandlerStressTest` and the `groovy-ginq`, `groovy-contracts` and `groovy-macro` tests pass. With a temporary check that compared each copy against the live map, the 34 stale copies seen in `DefaultGroovyMethodsSTCTest`, `StaticCompileDGMTest`, `GenericsSTCTest` and `GenericsStaticCompileTest` drop to none. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
