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

Naoto Sato naoto at openjdk.org
Thu Sep 14 22:58:50 UTC 2023


On Wed, 13 Sep 2023 18:00:01 GMT, Naoto Sato <naoto at openjdk.org> wrote:

>> 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!

The code seems to read the data written with this piece of code:
https://github.com/openjdk/jdk/blob/b55e418a077791b39992042411cde97f68dc39fe/make/jdk/src/classes/build/tools/charsetmapping/JIS0213.java#L145
but apparently it does not seem to work as expected. Since this is a very old code, not sure I would proactively modify it though.

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

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


More information about the nio-dev mailing list