RFR: 8288882: JFileChooser - empty (0 bytes) file is displayed as 1 KB [v22]
Abhishek Kumar
duke at openjdk.org
Mon Aug 22 09:48:46 UTC 2022
On Sun, 21 Aug 2022 21:10:29 GMT, Phil Race <prr at openjdk.org> wrote:
>> Abhishek Kumar has updated the pull request incrementally with one additional commit since the last revision:
>>
>> Updated as per review comment
>
> src/java.desktop/share/classes/sun/swing/FilePane.java line 1261:
>
>> 1259:
>> 1260: private static double formatToDoubleValue(long len) {
>> 1261: return (len / 100L) / 10.0d;
>
> First "formatToDouble" isn't really a very good name for this.
> Perhaps I could provide a better one if I could be sure of what the intent is here but
> at the very least this method needs comments explaining what it is doing AND why.
>
> The first (len / 100L) expression means that (eg)
> 100 and 199 will both become 1 and the return value of the method is 0.1
>
> So rounding DOWN is happening here, whereas (separately) we round UP for value < 100 ..
>
> So anything from 1 byte to 199 bytes will be 0.1 KB ?
>
> The test doesn't seem to cover this case.
"formatToDouble" method is taking filesize as a long value in parameter and convert it to one decimal precision value.
The reason for converting to one decimal point is to make it similar to native file system which shows file size in one decimal precision.
can "formatToDouble" method rename to "getOneDecimalPrecisionFileSize" ?
Since we are displaying file size in one decimal precision, files having size from 1 to 199 byte will be 0.1 KB.
1 to 99 byte file size is handled separately otherwise it will show 0.0 KB.
I will add few test case for 100 to 199 byte file.
-------------
PR: https://git.openjdk.org/jdk/pull/9327
More information about the client-libs-dev
mailing list