<i18n dev> RFR: 8246788: ZoneRules invariants can be broken
smarks at openjdk.java.net
Fri Jan 22 18:54:42 UTC 2021
On Fri, 22 Jan 2021 17:12:34 GMT, Daniel Fuchs <dfuchs at openjdk.org> wrote:
>> Or even maybe `rulesArray = lastRules.toArray(ZoneOffsetTransitionRule::new);`?
> Good point - but that would be:
> ZoneOffsetTransitionRule rulesArray = lastRules.toArray(ZoneOffsetTransitionRule::new).clone();
Interesting. This last one is more concise, but it's a bit harder to reason about. The lastRules implementation could return an array of a type other than ZOTR. If it's unrelated or a supertype, this would result in ClassCastException -- probably not a problem. If it were a subtype of ZOTR, this would get stored in the object's field. Is this a problem? Turns out it can't happen, since ZOTR is final. While not wrong, I don't think this is the right idiom.
It occurs to me that there should by another overload Arrays.copyOf(array, newType) that changes the type without changing the length. This would let us get rid of the local variable.
More information about the i18n-dev