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

Alexey Ivanov aivanov at openjdk.org
Thu Sep 8 17:35:04 UTC 2022


On Fri, 2 Sep 2022 11:12:53 GMT, Abhishek Kumar <duke at openjdk.org> wrote:

>> JFileChooser - empty file size issue fixed. 
>> For empty file, now the size 0 KB.
>> Manual Test Case "FileSizeCheck.java" created.
>
> Abhishek Kumar has updated the pull request incrementally with one additional commit since the last revision:
> 
>   Filesize calculation logic modified

Changes requested by aivanov (Reviewer).

src/java.desktop/share/classes/sun/swing/FilePane.java line 1277:

> 1275:             DecimalFormat df = new DecimalFormat("0.0");
> 1276:             double val = fileSize/baseFileSize;
> 1277:             return  Double.valueOf(df.format(val));

The new code to round up looks difficult to understand. I liked the previous version better. The only thing required to introduce rounding up is updating `roundToOneDecimalPlace`:


        private static double roundToOneDecimalPlace(long fileSize) {
            return  Math.ceilDiv(fileSize, 100L) / 10.0d;
        }


[`Math.ceilDiv`](https://docs.oracle.com/en/java/javase/18/docs/api/java.base/java/lang/Math.html#ceilDiv(long,long)) is available since Java 18.

However, this code also works and is better suited for backporting:


        private static double roundToOneDecimalPlace(long fileSize) {
            return  Math.ceil(fileSize / 100.0d) / 10.0d;
        }

Note that the first division is also floating point.

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

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



More information about the client-libs-dev mailing list