RFR: 8281631: HashMap copy constructor and putAll can over-allocate table [v28]

XenoAmess duke at openjdk.java.net
Fri Mar 11 01:11:25 UTC 2022


On Thu, 10 Mar 2022 22:21:28 GMT, Stuart Marks <smarks at openjdk.org> wrote:

> The difficulty with having a loop instead of constants is that the expected value now needs to be computed. We could probably use `tableSizeFor` to do this. But this is starting to get uncomfortably close to a testing antipattern which is to use the code under test as part of the test. If a bug is introduced into `tableSizeFor`, it could introduce the error into both the actual value and the expected value, covering up the bug. (This is related to one of the flaws with the Enum/ConstantDirectoryOptimalCapacity test.) Now we _hope_ that `tableSizeFor` is correct and tested, but that verges on having tests depend on each other in a subtle and uncomfortable way.

you are correct about this.

-------------

PR: https://git.openjdk.java.net/jdk/pull/7431


More information about the core-libs-dev mailing list