RFR: 6434110: Color constructor parameter name is misleading
Alexey Ivanov
aivanov at openjdk.org
Tue Feb 17 15:56:04 UTC 2026
On Mon, 16 Feb 2026 07:40:55 GMT, Sergey Bylokhov <serb at openjdk.org> wrote:
> Small cleanup: the parameter names in the Color(int, boolean) constructor have been renamed:
> - rgba -> argb, since this is the format described in the spec
> - hasalpha -> hasAlpha, to follow common naming conventions
>
> Also adds a basic test for the constructor.
src/java.desktop/share/classes/java/awt/Color.java line 404:
> 402: * the green component in bits 8-15, and the blue component in bits 0-7. If
> 403: * the {@code hasAlpha} argument is {@code false}, alpha is defaulted to
> 404: * 255.
Suggestion:
* Creates an sRGB color with the specified combined ARGB value consisting of
* <ul>
* <li>the alpha component in bits 24-31,</li>
* <li>the red component in bits 16-23,</li>
* <li>the green component in bits 8-15, and</li>
* <li>the blue component in bits 0-7.</li>
* </ul>
* If the {@code hasAlpha} argument is {@code false}, alpha is defaulted to 255.
What do you think about such formatting? Each color component stands out this way.
I'd also change the last sentence to _“alpha defaults to 255.”_
However, changing the formatting for this constructor will require changing the formatting for `Color(int rgb)`. And it will break the first sentence summary displayed in the table of contructors methods.
src/java.desktop/share/classes/java/awt/Color.java line 408:
> 406: * @param argb the combined ARGB components
> 407: * @param hasAlpha {@code true} if the alpha bits are valid; {@code false}
> 408: * otherwise
Suggestion:
* @param argb the combined ARGB components
* @param hasAlpha {@code true} if the alpha bits are valid; {@code false}
* otherwise
Remove an extra space between the `@param` tag and the parameter name, other constructors don't have this additional space and use only one space.
test/jdk/java/awt/ColorClass/ColorARGBConstructorTest.java line 49:
> 47: int expA = hasAlpha ? argb >>> 24 : 0xFF;
> 48: int expR = (argb >> 16) & 0xFF;
> 49: int expG = (argb >> 8) & 0xFF;
I suggest using `>>>` or `>>` in all the cases for consistency.
`(argb >> 24) & 0xFF` will produce the same result for `expA`.
Alternatively, `argb >>> 16` for `expR` will not need `& 0xFF`.
-------------
PR Review Comment: https://git.openjdk.org/jdk/pull/29734#discussion_r2817755415
PR Review Comment: https://git.openjdk.org/jdk/pull/29734#discussion_r2817772086
PR Review Comment: https://git.openjdk.org/jdk/pull/29734#discussion_r2817727317
More information about the client-libs-dev
mailing list