RFR: 8289397: Fix warnings: Possible accidental assignment in place of a comparison. A condition expression should not be reduced to an assignment
Andy Goryachev
angorya at openjdk.org
Tue Jul 26 22:55:00 UTC 2022
On Tue, 26 Jul 2022 21:14:58 GMT, Andy Goryachev <angorya at openjdk.org> wrote:
> - replaced with exact functional equivalent (in the presence of exceptions, for example)
I think the main purpose of compiler warning is to avoid bugs. Because of that, I'd rather enable this warning and fix the code.
An argument could also be made to limit ourselves to one statement per line, and in
if(a = func())
we have two.
Before NPE started to have a better diagnostic messages, the following code could not be diagnosed in the field (from a customer log file):
Integer a;
if(a = b.func()) // if NPE gets thrown, is it because a==null or b==null?
- added space after 'if'
- went back to Michael's suggestion of spatially separating assignment and conditional
-------------
PR: https://git.openjdk.org/jfx/pull/851
More information about the openjfx-dev
mailing list