RFR: 8273375: Remove redundant 'new String' calls after concatenation in java.desktop

Alexey Ivanov aivanov at openjdk.java.net
Tue Sep 7 19:50:11 UTC 2021


On Fri, 3 Sep 2021 07:53:21 GMT, Andrey Turbanov <github.com+741251+turbanoff at openjdk.org> wrote:

> Result of string concatenation is a newly created `String` object. There is no need it wrap it in another `new String` call.
> Such calls are confusing and produce warnings in IDE. Without them code is easier to read.

src/java.desktop/macosx/classes/com/apple/laf/AquaTabbedPaneCopyFromBasicUI.java line 3209:

> 3207: 
> 3208:         public String toString() {
> 3209:             return "viewport.viewSize=" + viewport.getViewSize() + "\n" + "viewport.viewRectangle=" + viewport.getViewRect() + "\n" + "leadingTabIndex=" + leadingTabIndex + "\n" + "tabViewPosition=" + tabViewPosition;

Does it make sense to break this long line?

src/java.desktop/share/classes/java/awt/image/DirectColorModel.java line 1414:

> 1412:                 + Integer.toHexString(green_mask) + " bmask="
> 1413:                 + Integer.toHexString(blue_mask) + " amask="
> 1414:                 + Integer.toHexString(alpha_mask);

Suggestion:

        return "DirectColorModel: rmask=" + Integer.toHexString(red_mask)
                + " gmask=" + Integer.toHexString(green_mask)
                + " bmask=" + Integer.toHexString(blue_mask)
                + " amask=" + Integer.toHexString(alpha_mask);

Is it easier to read?

src/java.desktop/share/classes/sun/awt/image/ShortBandedRaster.java line 806:

> 804: 
> 805:     public String toString() {
> 806:         return "ShortBandedRaster: width = " + width + " height = "

Maybe wrap `height` to the next line like it's done in several other files above?
Perhaps, wrap in all -Raster classes for consistency, also it's easier to read when each field is concatenated on its own line.

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

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



More information about the client-libs-dev mailing list