jdk
jdk copied to clipboard
8288882: JFileChooser - empty (0 bytes) file is displayed as 1 KB
JFileChooser - empty file size issue fixed. For empty file, now the size 0 KB. Manual Test Case "FileSizeCheck.java" created.
Progress
- [x] Change must be properly reviewed (1 review required, with at least 1 Reviewer)
- [x] Change must not contain extraneous whitespace
- [x] Commit message must refer to an issue
Issue
- JDK-8288882: JFileChooser - empty (0 bytes) file is displayed as 1 KB
Reviewers
- Alexey Ivanov (@aivanov-jdk - Reviewer) ⚠️ Review applies to a5ae29c1
- Andy Goryachev (@andy-goryachev-oracle - no project role) ⚠️ Review applies to 084a82a7
Reviewing
Using git
Checkout this PR locally:
$ git fetch https://git.openjdk.org/jdk pull/9327/head:pull/9327
$ git checkout pull/9327
Update a local copy of the PR:
$ git checkout pull/9327
$ git pull https://git.openjdk.org/jdk pull/9327/head
Using Skara CLI tools
Checkout this PR locally:
$ git pr checkout 9327
View PR using the GUI difftool:
$ git pr show -t 9327
Using diff file
Download this PR as a diff file:
https://git.openjdk.org/jdk/pull/9327.diff
:wave: Welcome back kumarabhi006! A progress list of the required criteria for merging this PR into master will be added to the body of your pull request. There are additional pull request commands available for use with this pull request.
@kumarabhi006 The following label will be automatically applied to this pull request:
client
When this pull request is ready to be reviewed, an "RFR" email will be sent to the corresponding mailing list. If you would like to change these labels, use the /label pull request command.
Webrevs
- 30: Full - Incremental (604d6fd7)
- 29: Full - Incremental (b4361c32)
- 28: Full - Incremental (6d2b9557)
- 27: Full - Incremental (3d6ae268)
- 26: Full - Incremental (99224c1c)
- 25: Full - Incremental (cea398f5)
- 24: Full - Incremental (8ffcc83a)
- 23: Full - Incremental (1e086cae)
- 22: Full - Incremental (dac1ae7d)
- 21: Full - Incremental (5526919c)
- 20: Full - Incremental (497c6864)
- 19: Full - Incremental (8ac27853)
- 18: Full - Incremental (d749cc38)
- 17: Full - Incremental (a5ae29c1)
- 16: Full - Incremental (1d830a54)
- 15: Full - Incremental (e699f033)
- 14: Full - Incremental (45d017ed)
- 13: Full - Incremental (084a82a7)
- 12: Full - Incremental (4dbd5849)
- 11: Full - Incremental (99778d96)
- 10: Full - Incremental (02d4c08b)
- 09: Full - Incremental (0ccb7521)
- 08: Full - Incremental (31e9252f)
- 07: Full - Incremental (600ac735)
- 06: Full - Incremental (f29fe0b2)
- 05: Full - Incremental (6b3ae9e5)
- 04: Full - Incremental (518c6fd6)
- 03: Full - Incremental (8f6c9fef)
- 02: Full - Incremental (b1006c66)
- 01: Full - Incremental (a7b31d98)
- 00: Full (c9583130)
JFileChooser in Windows and Ubuntu is setting the filesize from two different files. In ubuntu, the method "public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column)" in FilePane.java is formatting the length and return it back. In Windows, it uses ShellFolder to set FileSize column values and it is returned in terms of bytes in stead of KB (as shown by native tools). To handle filesize in windows, I will like to raise separate PR.
In Windows, it uses ShellFolder to set FileSize column values and it is returned in terms of bytes in stead of KB (as shown by native tools).
This doesn't seem to be true for Windows, I see "0 KB" and "1 KB" for zero-byte and one-byte sized files correspondingly in Windows Explorer.
To handle filesize in windows, I will like to raise separate PR.
Are you saying you will submit a new bug to address the above?
In Windows, it uses ShellFolder to set FileSize column values and it is returned in terms of bytes in stead of KB (as shown by native tools).
This doesn't seem to be true for Windows, I see "0 KB" and "1 KB" for zero-byte and one-byte sized files correspondingly in Windows Explorer.
To handle filesize in windows, I will like to raise separate PR.
Are you saying you will submit a new bug to address the above?
For Windows, I would like to submit a new bug,
File size shown in native is upto 1 decimal value. Now JFileChooser also shows filesize upto 1 decimal value similar to native.
There is a change in conversion factor from 1024 to 1000 to show file size as per native.

Created a directory with bug-id (8288882) name under "open/test/jdk/javax/swing/JFileChooser". Added manual test case file "FileSizeCheck.java" along with some dummy files to perform filesize checks.
ZeroFileSizeCheck file has been deleted as it is moved to different directory and is of no longer use.

Attached the screenshot for GTK LAF and Nimbus LAF for JFileChooser. In GTK LAF, JFileChooser doesn't show the file size. In Nimbus, JFileChooser shows file sizes correctly.
Declared a variable "baseFileSize to replace 1000.0 value. Method formatToDoubleValue has been moved inside class DetailsTableCellRenderer.
@prrace @andy-goryachev-oracle There are few changes as per review comments, so request to please review them.
Do not check in files - you can generate these at run time and then delete them
- This also means you don't need the extra level of folder - which should be named something else than the bug id anyway
Deleted the previously checked in test files. Added the code to create and delete the test files at run time. FileSizeCheck manual test case file moved outside the folder and kept inside JFileChooser directory. So, there is no extra level of folder now.
@andy-goryachev-oracle Checked in Oracle Linux and it shows file size similar to native.
Attached the screenshot for filesize in native Oracle linux and JFileChooser.

Does the size formatting respect the user's setting for the decimal symbol?
@aivanov-jdk I have updated the suggested changes. JFileChooser has been added as a component in frame.
@prsadhuk I have made few changes in formatting the file size, using MessageFormat and NumberFormat to format the file size with 1 decimal place precision. Earlier JFileChooser show file size for "1.0" as "1", now it will show one decimal place precision. Empty files show as "0 KB".

@prsadhuk I have made few changes in formatting the file size, using MessageFormat and NumberFormat to format the file size with 1 decimal place precision. Earlier JFileChooser show file size for "1.0" as "1", now it will show one decimal place precision. Empty files show as "0 KB".
If JFileChooser always shows a decimal point for nearly all files, should it show 0.0 KB for zero-sized files?
I guess it would simplify your code as there'll be no reason to change number format.
@prsadhuk I have made few changes in formatting the file size, using MessageFormat and NumberFormat to format the file size with 1 decimal place precision. Earlier JFileChooser show file size for "1.0" as "1", now it will show one decimal place precision. Empty files show as "0 KB".
If JFileChooser always shows a decimal point for nearly all files, should it show 0.0 KB for zero-sized files?
I guess it would simplify your code as there'll be no reason to change number format.
@aivanov-jdk It will simplify the code but I checked in native file system and it shows "0 bytes" for zero-sized files. So to keep it similar to native, zero-sized files shown as "0 KB".
@aivanov-jdk I have updated as per the suggested changes.
@prsadhuk I have made few changes in formatting the file size, using MessageFormat and NumberFormat to format the file size with 1 decimal place precision. Earlier JFileChooser show file size for "1.0" as "1", now it will show one decimal place precision. Empty files show as "0 KB".
If JFileChooser always shows a decimal point for nearly all files, should it show 0.0 KB for zero-sized files? I guess it would simplify your code as there'll be no reason to change number format.
@aivanov-jdk It will simplify the code but I checked in native file system and it shows "0 bytes" for zero-sized files. So to keep it similar to native, zero-sized files shown as "0 KB".
Yet still it's shows 0 KB in Java; all other sizes are showed with one digit after the decimal point, thus only 0 KB has special handling. It's different from the native system, and I am for consistency in Java approach. If we decided, we show the size as #.# where there's always a digit after the decimal point, I'd rather see it always displayed. It would be easier to scan the sizes.
I wonder how the file size of 200 bytes is shown: 1 KB or 0.2 KB.
@prsadhuk I have made few changes in formatting the file size, using MessageFormat and NumberFormat to format the file size with 1 decimal place precision. Earlier JFileChooser show file size for "1.0" as "1", now it will show one decimal place precision. Empty files show as "0 KB".
If JFileChooser always shows a decimal point for nearly all files, should it show 0.0 KB for zero-sized files? I guess it would simplify your code as there'll be no reason to change number format.
@aivanov-jdk It will simplify the code but I checked in native file system and it shows "0 bytes" for zero-sized files. So to keep it similar to native, zero-sized files shown as "0 KB".
Yet still it's shows 0 KB in Java; all other sizes are showed with one digit after the decimal point, thus only 0 KB has special handling. It's different from the native system, and I am for consistency in Java approach. If we decided, we show the size as #.# where there's always a digit after the decimal point, I'd rather see it always displayed. It would be easier to scan the sizes.
I wonder how the file size of 200 bytes is shown: 1 KB or 0.2 KB.
As of now files having size >0 and <1000 bytes are shown as 1.0 KB.
I wonder how the file size of 200 bytes is shown: 1 KB or 0.2 KB.
As of now files having size >0 and <1000 bytes are shown as 1.0 KB.
And this seems wrong and inconsistent, doesn't it?
If we display the file size with one decimal point precision, then it doesn't hold at all until the file size reaches 1 KB.
Whatever the decision we make, I'd like to have a test for 1 KB file and for 0.5 KB file to document how it works. It's the point of having different file sizes in the test, right?
I agree the file sizes less than 1 KB are somewhat uncommon, I'm okay with displaying them as 1.0 KB.
I wonder how the file size of 200 bytes is shown: 1 KB or 0.2 KB.
As of now files having size >0 and <1000 bytes are shown as 1.0 KB.
And this seems wrong and inconsistent, doesn't it?
If we display the file size with one decimal point precision, then it doesn't hold at all until the file size reaches 1 KB.
Whatever the decision we make, I'd like to have a test for 1 KB file and for 0.5 KB file to document how it works. It's the point of having different file sizes in the test, right?
I agree the file sizes less than 1 KB are somewhat uncommon, I'm okay with displaying them as 1.0 KB.
Yeah, you are right if we display the file size with one decimal point precision then it is inconsistent. I will add the test files for 1 KB and 0.5 KB.
If we display the file size with one decimal point precision, then it doesn't hold at all until the file size reaches 1 KB.
Is your point ( pun intended) that it looks like we are displaying files to a decimal precision, but in fact are not ?
ie it is very odd to display 1.0kb for files of 100, 200, 300, etc bytes .. What is the reason for displaying them all as 1.0kb .. this review is so long I'm not sure I am following any more.
Could we get a summary in a few sentences of the entire current proposal and the justification for it ?
If we display the file size with one decimal point precision, then it doesn't hold at all until the file size reaches 1 KB.
Is your point ( pun intended) that it looks like we are displaying files to a decimal precision, but in fact are not ?
ie it is very odd to display 1.0kb for files of 100, 200, 300, etc bytes .. What is the reason for displaying them all as 1.0kb .. this review is so long I'm not sure I am following any more.
Could we get a summary in a few sentences of the entire current proposal and the justification for it ?
There was an issue with plural forms if we show file sizes in terms of bytes. So, it has been discussed that we can show the file size in terms of "1 KB" for files having size >0 and <1000 bytes. To keep file size similar to native file system, JFileChooser displays file sizes with one decimal point precision.
Now, the issue is whether an empty file should be displayed as "0.0 KB" or "0 KB" ? As of now empty files are displayed as "0 KB".
If we display the file size with one decimal point precision, then it doesn't hold at all until the file size reaches 1 KB.
Is your point ( pun intended) that it looks like we are displaying files to a decimal precision, but in fact are not ?
That's exactly my point.
Could we get a summary in a few sentences of the entire current proposal and the justification for it ?
I also asked for the summary. That time it was a bit different: https://github.com/openjdk/jdk/pull/9327#discussion_r939828467
There was an issue with plural forms if we show file sizes in terms of bytes. So, it has been discussed that we can show the file size in terms of "1 KB" for files having size >0 and <1000 bytes. To keep file size similar to native file system, JFileChooser displays file sizes with one decimal point precision.
Now, the issue is whether an empty file should be displayed as "0.0 KB" or "0 KB" ? As of now empty files are displayed as "0 KB".
The original issue is that we displayed a zero-sized file as 1 KB. It's stated in the bug subject and in the bug description with more details.
The initial fix was to display it as 0 bytes, which leads to localisation problems, especially if we take into account 1 byte.
Eventually, it was decided to display the size in KB. Thus zero-sized file is displayed as 0 KB, and one-byte-sized file is displayed as 1 KB. This is fine.
Later on, the decimal point was added to mimic native file navigation app in Ubuntu. Now for files larger than 1 KB, the size is shown up to one decimal point. Yet all the files below 1 KB are still displayed as 1 KB. I think it is confusing. If we care to display the size with one decimal point for larger files, why can't we display the size of smaller files with the same precision?
So, 0 bytes is 0.0 KB; > 0 and <= 100 bytes is 0.1 KB, and so on.
Alternatively, drop the decimal altogether.
To have all files 1->1000 bytes be 1.0kB and yet 1,100 -> 1,200 bytes be 1.1kB does seem anomalous from a precision perspective, since the major order of magnitude would seem to be more important to describe.
Since we already aren't going to say "bytes" for those small files, then just getting that precision with the decimal point seems better - as well as being consistent !
@prrace @aivanov-jdk I have modified the existing logic to show decimal precision for smaller files. Added few test cases for files having size <1000 bytes.