RFR: 8313865: Always true condition in sun.nio.cs.CharsetMapping#readINDEXC2B

Naoto Sato naoto at openjdk.org
Wed Sep 13 18:02:50 UTC 2023


On Wed, 13 Sep 2023 07:22:24 GMT, Aleksey Shipilev <shade at openjdk.org> wrote:

>> Simple clean-up for removing an unnecessary condition.
>
> src/java.base/share/classes/sun/nio/cs/CharsetMapping.java line 242:
> 
>> 240:         char[] map = readCharArray();
>> 241:         for (int i = map.length - 1; i >= 0; i--) {
>> 242:             if (c2b == null) {
> 
> Post-review comment:
> 
> I don't quite understand this code. `c2b` is loop-invariant, right? So, what this does is checking for `c2b != null`, and if so, instantiates the `c2b` array with `new char[map[map.length - 1] + 256]`. This does not even require a loop, as written right now.

Indeed the code looks weird. Will have a deeper look. Thanks!

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

PR Review Comment: https://git.openjdk.org/jdk/pull/15672#discussion_r1324881959


More information about the nio-dev mailing list