rootvector2 opened a new pull request, #745: URL: https://github.com/apache/commons-collections/pull/745
A `DualTreeBidiMap` sub map (`subMap`, `headMap`, `tailMap`) decorates an inner bidi map whose `normalMap` is restricted to the range while its `reverseMap` is the full map, and the inherited `AbstractDualBidiMap` code assumes both hold the same mappings. So `keySet().clear()`, `values().clear()`, `entrySet().clear()` and `retainAll` of an empty collection on a sub map wipe the whole reverse map, `put` of a value held by a key outside the range leaves two keys with that value, a `put` rejected for a key out of range has already removed the mapping that held the value, and `values().remove()` drops the reverse entry of a value outside the range. Found while reading `ViewMap`, then measured with a randomized differential test of the sub maps against `TreeMap`: 189778 of 500000 cases left the map and its inverse out of step. The view now decorates a private `ViewBidiMap` that overrides `clear`, `containsValue` and `put` for the restricted `normalMap`, and `Values.contains`/`Values.remove` go through the parent map the way `View.clear` already does. The fix sits in the inner map because `putAll`, the collection views and nested sub maps all reach it, which the existing `ViewMap.clear` and `ViewMap.containsValue` overrides could not cover. The differential test is clean over 1200000 cases after the change, and the new `AbstractSortedBidiMapTest` cases fail before it and pass after. - [x] Read the [contribution guidelines](CONTRIBUTING.md) for this project. - [x] Read the [ASF Generative Tooling Guidance](https://www.apache.org/legal/generative-tooling.html) if you use Artificial Intelligence (AI). - [x] I used AI to create any part of, or all of, this pull request. Which AI tool was used to create this pull request, and to what extent did it contribute? Claude Code was used to find the bug and to write the fix, the tests and this description. - [x] Run a successful build using the default [Maven](https://maven.apache.org/) goal with `mvn`; that's `mvn` on the command line by itself. - [x] Write unit tests that match behavioral changes, where the tests fail if the changes to the runtime are not applied. This may not always be possible, but it is a best practice. - [x] Write a pull request description that is detailed enough to understand what the pull request does, how, and why. - [x] Each commit in the pull request should have a meaningful subject line and body. Note that a maintainer may squash commits during the merge process. -- 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]
