RFR: 8288882: JFileChooser - empty (0 bytes) file is displayed as 1 KB [v6]

Abhishek Kumar duke at openjdk.org
Tue Jul 19 05:53:04 UTC 2022


On Mon, 18 Jul 2022 19:59:00 GMT, Andy Goryachev <duke at openjdk.org> wrote:

>> src/java.desktop/share/classes/sun/swing/FilePane.java line 1207:
>> 
>>> 1205:                     len /= 1024L;
>>> 1206:                     if (len < 1024L) {
>>> 1207:                         text = MessageFormat.format(kiloByteString, len);
>> 
>> So ALL of these have an "off by one" issue don't they ?
>> 
>> Here a file that is (for example) 2047 bytes in size will be displayed as "1KB"
>
> I think this also deserves extracting it into a separate function, and a unit test.
> And perhaps another unit test with a non-English locale.

> So ALL of these have an "off by one" issue don't they ?
> 
> Here a file that is (for example) 2047 bytes in size will be displayed as "1KB"

There is "off by one" issue in this case. One possible solution can be - 


![FileChooser_FileSizes](https://user-images.githubusercontent.com/107542245/179674833-345a7e81-4af2-403e-b9e1-9d690bffeddd.png)

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

PR: https://git.openjdk.org/jdk/pull/9327



More information about the client-libs-dev mailing list