RFR 8208399: Metadata methods print_(value_)on_maybe_null() compare 'this' to NULL

Kim Barrett kim.barrett at oracle.com
Tue Jul 31 14:35:38 UTC 2018

> On Jul 30, 2018, at 9:15 PM, David Holmes <david.holmes at oracle.com> wrote:
> On 31/07/2018 11:00 AM, Ioi Lam wrote:
>> There are 92 cases of '[(]NULL ==' vs 3403 cases of '== NULL[)]' in the hotspot source code.
>> It's been claimed that (NULL == variable) is superior because if you type "=" by mistake, or delete one of the equal signs by mistake, the compiler will catch you.
> Yes well aware of the reason behind it :) I just find it jarring to read code expressed that way. If I'd been taught it from the beginning, or if hotspot had always used it ...
> But unless we're planning on updating the coding guidelines to require this I don't see we should be making such changes "just because”

I agree with David here.

Also, I recall some compilers warning about a simple assignment as a control expression,
specifically to address that mistake.  The workaround for the warning might be to parenthesize
the expression, or not use the implicit bool conversion (as required by Hotspot style guide).

More information about the hotspot-runtime-dev mailing list