RFR: 8298042: Fix hidden but significant trailing whitespace in properties files for client code
SWinxy
duke at openjdk.org
Fri Dec 2 22:51:11 UTC 2022
On Fri, 2 Dec 2022 16:38:54 GMT, Magnus Ihse Bursie <ihse at openjdk.org> wrote:
> According to [the specification](https://docs.oracle.com/en/java/javase/19/docs/api/java.base/java/util/Properties.html#load(java.io.Reader)) trailing whitespaces in the values of properties files are (somewhat surprisingly) actually significant.
>
> We have multiple files in the JDK with trailing whitespaces in the values. For most of this files, this is likely incorrect and due to oversight, but in a few cases it might actually be intended (like "The value is: ").
>
> After a discussion in the PR for [JDK-8295729](https://bugs.openjdk.org/browse/JDK-8295729), the consensus was to replace valid trailing spaces with the corresponding unicode sequence, `\u0020`. (And of course remove non-wanted trailing spaces.)
>
> Doing so has a dual benefit:
>
> 1) It makes it clear to everyone reading the code that there is a trailing space and it is intended
>
> 2) It will allow us to remove all actual trailing space characters, and turn on the corresponding check in jcheck to keep the properties files, just like all other source code files, free of trailing spaces.
>
> Ultimately, the call of whether a trailing space is supposed to be there, or is a bug, lies with the respective component teams owning these files. Thus I have split up the set of properties files with trailing spaces in several groups, to match the JDK teams, and open a JBS issue for each of them. This issue is for code I believe belong with the client-libs team.
These bring to light inconsistencies between locales.
All but a few don't need spaces afterwards. The line-by-line reviews apply to the same properties in other locales in the same path. I looked at all of the usages and similar properties, and most were either put in JLabels, tooltips, or alt texts. Some strings are concatenated in Java code and the space can be put there instead.
Since a lot of them are in the java.desktop package, would they require a CSR to bring in consistency between locales?
src/demo/share/jfc/SwingSet2/resources/swingset_ja.properties line 51:
> 49: ### Status ###
> 50:
> 51: Status.loading=\u8AAD\u8FBC\u307F\u4E2D:\u0020
ja and zh-CN both have spaces, but en and de don't. The string is concatenated without a space in between in the demo code, so this would be technically correct (and en and de incorrect). An example of the current behavior is producing `正在加载: 按钮演示` (correct) or `Loading:Button Demo` (incorrect).
The proper solution would be to remove the space and the colon, putting them in the code.
src/demo/share/jfc/SwingSet2/resources/swingset_ja.properties line 187:
> 185: ### Button Demo ###
> 186:
> 187: ButtonDemo.accessible_description=ButtonDemo\u3067\u306F\u3001JButton\u3001JRadioButton\u3001JToggleButton\u304A\u3088\u3073JCheckBox\u306E\u4F7F\u7528\u4F8B\u3092\u7D39\u4ECB\u3057\u307E\u3059\u0020
Judging by the context of "accessible description," I'm guessing that there doesn't need to be a space afterwards. It's otherwise unused.
src/demo/share/jfc/SwingSet2/resources/swingset_ja.properties line 214:
> 212: ButtonDemo.radioX=<html><font size=2 color=red>3<bold>(HTML)</bold></font></html>
> 213:
> 214: ButtonDemo.check1=1\u0020
Used only in JLabels. Since 2 and 3 don't have spaces afterwards (the usages are identical afaict), and since other locales like en don't have the space, it's fine to remove.
src/demo/share/jfc/SwingSet2/resources/swingset_ja.properties line 224:
> 222: ButtonDemo.phone=\u96FB\u8A71\u0020
> 223: ButtonDemo.write=\u66F8\u8FBC\u307F
> 224: ButtonDemo.peace=\u30D4\u30FC\u30B9
It's only here that the space is present, while `write` and `peace` don't, nor does the en locale. It goes into the alt text of an icon, so a space afterwards is unnecessary.
src/demo/share/jfc/SwingSet2/resources/swingset_ja.properties line 454:
> 452: SliderDemo.name=Slider\u30C7\u30E2
> 453:
> 454: SliderDemo.slidervalue=Slider\u306E\u5024:\u0020
Unsure. It's used in four places. The two that use it concatenated should probably have a space added in the code and this removed.
src/java.desktop/macosx/classes/com/apple/laf/resources/aqua_zh_CN.properties line 67:
> 65: FileChooser.newFolderTitle.textAndMnemonic=\u65B0\u5EFA\u6587\u4EF6\u5939
> 66: FileChooser.fileNameLabel.textAndMnemonic=\u6587\u4EF6:
> 67: FileChooser.saveDialogFileNameLabel.textAndMnemonic=\u53E6\u5B58\u4E3A:\u0020
Unused, but other locales don't have the space. Dunno.
src/java.desktop/macosx/classes/com/apple/laf/resources/aqua_zh_CN.properties line 178:
> 176: SplitPane.rightButton.textAndMnemonic=\u53F3\u952E
> 177: # Used for Isindex
> 178: IsindexView.prompt=\u8FD9\u662F\u53EF\u641C\u7D22\u7D22\u5F15\u3002\u8BF7\u8F93\u5165\u641C\u7D22\u5173\u952E\u5B57:\u0020
Inserted into a label. No use for a space afterwards. Other locales don't have it, but zh-TW does. Down further, there are identical-looking usages of `IsindexView.prompt`.
src/java.desktop/share/classes/com/sun/imageio/plugins/common/iio-plugin.properties line 11:
> 9: ImageUtil0=The supplied Raster does not represent a binary data set.
> 10: ImageUtil1=The provided sample model is null.
> 11: ImageUtil2=The provided image cannot be encoded using:\u0020
Already concatenated with a space in `ImageUtil.java`. Creates a double space.
src/java.desktop/share/classes/com/sun/java/swing/plaf/gtk/resources/gtk_zh_CN.properties line 57:
> 55: FileChooser.acceptAllFileFilter.textAndMnemonic=\u6240\u6709\u6587\u4EF6
> 56: FileChooser.newFolderButton.textAndMnemonic=\u65B0\u6587\u4EF6\u5939(&N)
> 57: FileChooser.newFolderDialog.textAndMnemonic=\u6587\u4EF6\u5939\u540D:\u0020
Unused, and other locales don't have a space. Remove?
src/java.desktop/share/classes/com/sun/java/swing/plaf/gtk/resources/gtk_zh_CN.properties line 68:
> 66: FileChooser.openDialogTitle.textAndMnemonic=\u6253\u5F00
> 67: FileChooser.pathLabel.textAndMnemonic=\u9009\u5B9A\u5185\u5BB9(&S):
> 68: FileChooser.filterLabel.textAndMnemonic=\u7B5B\u9009\u5668:\u0020
Unused, and other locales don't have a space. Also remove?
src/java.desktop/share/classes/com/sun/java/swing/plaf/motif/resources/motif_it.properties line 58:
> 56: FileChooser.foldersLabel.textAndMnemonic=Car&telle
> 57: FileChooser.filesLabel.textAndMnemonic=F&ile
> 58: FileChooser.enterFileNameLabel.textAndMnemonic=Immettere il &nome file:\u0020
Unused, but most have the space included (except for en, oddly). Put a space in en?
src/java.desktop/share/classes/sun/print/resources/serviceui_zh_CN.properties line 65:
> 63: label.size=\u5927\u5C0F(&Z):
> 64: label.source=\u6765\u6E90(&C):
> 65: label.status=\u72B6\u6001:\u0020
It is more consistent to have no spaces afterwards.
src/java.desktop/windows/classes/com/sun/java/swing/plaf/windows/resources/windows_zh_CN.properties line 47:
> 45:
> 46: FileChooser.lookInLabel.textAndMnemonic=\u67E5\u627E(&I):
> 47: FileChooser.saveInLabel.textAndMnemonic=\u4FDD\u5B58:\u0020
More consistent without the space.
test/jdk/sanity/client/lib/SwingSet3/src/com/sun/swingset3/demos/filechooser/resources/FileChooserDemo.properties line 11:
> 9: FileChooserDemo.filter.blur = blur
> 10: FileChooserDemo.filter.edge = edge
> 11: FileChooserDemo.filter.sharpen = sharpen\u0020
Uh, remove? No other strings have a space.
test/jdk/sanity/client/lib/SwingSet3/src/com/sun/swingset3/demos/filechooser/resources/FileChooserDemo.properties line 22:
> 20: FileChooserDemo.rotateright.tooltip = Rotate right\u0020
> 21: FileChooserDemo.fliphorizontal.tooltip = Flip horizontal\u0020
> 22: FileChooserDemo.flipvertical.tooltip = Flip vertical\u0020
Tooltips don't need a space.
test/jdk/sanity/client/lib/SwingSet3/src/com/sun/swingset3/demos/table/resources/TableDemo.properties line 12:
> 10:
> 11: TableDemo.noDataStatusLabel=No data loaded
> 12: TableDemo.loadingStatusLabel=Loading data:\u0020
It might need a space? I can't tell.
test/jdk/sanity/client/lib/SwingSet3/src/com/sun/swingset3/demos/table/resources/TableDemo.properties line 14:
> 12: TableDemo.loadingStatusLabel=Loading data:\u0020
> 13: TableDemo.rowCountLabel=Showing\u0020
> 14: TableDemo.searchCountLabel=Search found\u0020
These are concatenated, so either keep the space or update the code to include the space.
test/jdk/sanity/client/lib/SwingSet3/src/com/sun/swingset3/demos/togglebutton/resources/ToggleButtonDemo.properties line 3:
> 1: ### Button Demo ###
> 2:
> 3: ToggleButtonDemo.accessible_description=The ButtonDemo shows examples of using JButton, JRadioButton, JToggleButton, and JCheckBox\u0020
Unused. Can be removed.
test/jdk/sanity/client/lib/SwingSet3/src/com/sun/swingset3/demos/togglebutton/resources/ToggleButtonDemo.properties line 38:
> 36: ToggleButtonDemo.customcheck=A custom lightbulb checkbox.
> 37:
> 38: ToggleButtonDemo.phone=Phone\u0020
Not necessary. All are just placed in labels.
-------------
Changes requested by SWinxy at github.com (no known OpenJDK username).
PR: https://git.openjdk.org/jdk/pull/11488
More information about the client-libs-dev
mailing list