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

Alexey Ivanov aivanov at openjdk.org
Mon Aug 22 19:57:54 UTC 2022


On Fri, 19 Aug 2022 10:40:14 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:
> 
>   Updated as per review comment

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

> 1185:             // TODO: it's rather a temporary trick, to be revised
> 1186:             String text;
> 1187:             Object[] objs = new Object[1];

I suggest moving this declaration into the following block:


            } else if (value instanceof Long len) {
                Object[] objs = new Object[1];

                if (listViewWindowsStyle) {


This will reduce the visibility of the variable to the block where it's used.

Giving it a descriptive name would also be better. Is `fileSize` good enough? `displayedFileSize`?

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

> 1203:                  * similar to linux file system
> 1204:                  * Empty file size show as 0.0 KB
> 1205:                  * 1->100 byte files show as 0.1 KB and so on

Suggestion:

                 * Code block is relevant to Linux.
                 * File size is display up to 1 decimal precision.
                 * Base-10 number system used for formatting file size
                 * similar to how it's formatted in file managers on Linux.
                 * Empty file size is shown as 0.0 KB,
                 * 1-100-byte files are shown as 0.1 KB and so on.

test/jdk/javax/swing/JFileChooser/FileSizeCheck.java line 65:

> 63:         JFrame frame = new JFrame("JFileChooser File Size test");
> 64:         JFileChooser fc = new JFileChooser();
> 65:         Path dir = Paths.get(System.getProperty("test.src"));

When run with jtreg, it creates the files in the test source tree, which is probably not what we want. If the files aren't removed, they'll be left in the source tree and may prevent further updates to the source.

Should this always default to the current directory? When `jtreg` runs a test, the current directory is a `scratch` directory which is cleaned between the tests if the test passes, if the test fails, the contents is copied to the test log directory.

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

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



More information about the client-libs-dev mailing list