RFR: 8289397: Fix warnings: Possible accidental assignment in place of a comparison. A condition expression should not be reduced to an assignment [v2]

Kevin Rushforth kcr at openjdk.org
Fri Jul 29 17:07:58 UTC 2022


On Fri, 29 Jul 2022 07:40:42 GMT, Marius Hanl <mhanl at openjdk.org> wrote:

>> i think *now* the code is clear without the comment!
>> (and the comment does not explain *why* it is intentional or what is the intention)
>
> I would probably leave it as before. I found that code already when working on the OpenJFX project and while it looks strange at first glance, it was clear afterwards. And the comment makes this clear as well.
> 
> The `== true` might confuse more now.

The combination of removing the comment in connection with adding the `== true` has made the purpose of this line of code somewhat less clear. It needs a comment to explain what is otherwise a pretty obscure construct. The code relies on the fact that the body of the `assert` is executed if-and-only-if assertions are enabled at runtime. Thus the side-effect of the assignment is crucial to its operation. Here is a comment that might explain this:


            // The following assertion check will always pass. The side-effect
            // of the `assertsEnabled = true` assignment is intentional. It will
            // be executed if-and-only-if assertions are enabled at runtime.

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

PR: https://git.openjdk.org/jfx/pull/851


More information about the openjfx-dev mailing list