Repository navigation
Commit f493213
committed
[kubernetes] Fix Quantity.hashCode to honor equals/hashCode contract
Quantity.equals compares the underlying BigDecimal by value
(ObjectUtils.compare -> BigDecimal.compareTo, scale-insensitive), but
hashCode used Objects.hash(number) which is scale-sensitive. Value-equal
quantities such as "1" and "1000m" (1.000) are therefore equal yet
produce different hash codes, breaking HashMap/HashSet lookups.
Normalize the scale with BigDecimal.stripTrailingZeros() before hashing
so the hash is consistent with the value-based equals.
Adds a focused unit test (fails before, passes after).1 parent 7f36a85 commit f493213
2 files changed
Lines changed: 17 additions & 1 deletion
File tree
- kubernetes/src
- main/java/io/kubernetes/client/custom
- test/java/io/kubernetes/client/custom
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
90 | 90 | | |
91 | 91 | | |
92 | 92 | | |
93 | | - | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
94 | 97 | | |
95 | 98 | | |
96 | 99 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
30 | 30 | | |
31 | 31 | | |
32 | 32 | | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
33 | 46 | | |
0 commit comments