<i18n dev> RFR: 8274640: Cleanup unnecessary null comparison before instanceof check in java.desktop [v2]

Andrey Turbanov duke at openjdk.java.net
Mon Nov 29 08:17:53 UTC 2021


On Sat, 27 Nov 2021 16:27:36 GMT, Alexey Ivanov <aivanov at openjdk.org> wrote:

>> Andrey Turbanov has updated the pull request incrementally with one additional commit since the last revision:
>> 
>>   8274640: Cleanup unnecessary null comparison before instanceof check in java.desktop
>>   apply review comments
>
> src/java.desktop/macosx/classes/com/apple/laf/AquaTableHeaderUI.java line 148:
> 
>> 146:     protected static TableColumn getTableColumn(final JTableHeader target, final Object value) {
>> 147:         if (!(value instanceof Integer idx)) return null;
>> 148:         final int columnIndex = idx;
> 
> Probably, this expression could be simplified?
> Suggestion:
> 
>         if (!(value instanceof final Integer columnIndex)) return null;

done

> src/java.desktop/macosx/classes/sun/lwawt/macosx/CPlatformWindow.java line 247:
> 
>> 245:         }},
>> 246:         new Property<CPlatformWindow>(WINDOW_DOCUMENT_FILE) { public void applyProperty(final CPlatformWindow c, final Object value) {
>> 247:             if (!(value instanceof java.io.File f)) {
> 
> Is `file` a better name?

updated

> src/java.desktop/share/classes/javax/swing/JOptionPane.java line 2336:
> 
>> 2334:         if (icon instanceof Serializable ser) {
>> 2335:             values.addElement("icon");
>> 2336:             values.addElement(ser);
> 
> I suggest omitting `ser` variable declaration: it's not used as `Serializable`, checking with `instanceof` is enough. This comment applies to all similar if-conditions below.

ok

> src/java.desktop/share/classes/javax/swing/JPopupMenu.java line 1338:
> 
>> 1336:         }
>> 1337:         // Save the popup, if it's Serializable.
>> 1338:         if (popup instanceof Serializable ser) {
> 
> Suggestion:
> 
>         if (popup instanceof Serializable) {

updated

> src/java.desktop/share/classes/javax/swing/JTree.java line 3132:
> 
>> 3130:         s.defaultWriteObject();
>> 3131:         // Save the cellRenderer, if it's Serializable.
>> 3132:         if (cellRenderer instanceof Serializable ser) {
> 
> Suggestion:
> 
>         if (cellRenderer instanceof Serializable) {

updated

> src/java.desktop/share/classes/javax/swing/tree/DefaultMutableTreeNode.java line 1301:
> 
>> 1299:         s.defaultWriteObject();
>> 1300:         // Save the userObject, if it's Serializable.
>> 1301:         if (userObject instanceof Serializable ser) {
> 
> Suggestion:
> 
>         if (userObject instanceof Serializable) {

updated

> src/java.desktop/share/classes/javax/swing/tree/DefaultTreeModel.java line 694:
> 
>> 692:         s.defaultWriteObject();
>> 693:         // Save the root, if it's Serializable.
>> 694:         if (root instanceof Serializable ser) {
> 
> Suggestion:
> 
>         if (root instanceof Serializable) {

updated

> src/java.desktop/share/classes/javax/swing/tree/DefaultTreeSelectionModel.java line 1221:
> 
>> 1219:         s.defaultWriteObject();
>> 1220:         // Save the rowMapper, if it implements Serializable
>> 1221:         if (rowMapper instanceof Serializable ser) {
> 
> Suggestion:
> 
>         if (rowMapper instanceof Serializable) {

updated

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

PR: https://git.openjdk.java.net/jdk/pull/5482


More information about the i18n-dev mailing list