Skip to content

Problems with new BooleanLiteral warning #5134

@norrisjeremy

Description

@norrisjeremy

The new BooleanLiteral warning can lead to code change recommendations that would result in NPE's at runtime.

For example, see the following code that Error Prone will now issue a warning for:

Boolean foo = null;
Boolean bar = 1 > 0 ? foo : Boolean.TRUE;

If you follow naively follow Error Prone's suggestion to turn Boolean.TRUE into true here, this will actually result in an NPE at runtime, as the JVM will attempt to unbox the variable foo (by calling foo.booleanValue()).

My suggestion would be to simply remove this new BooleanLiteral warning entirely from Error Prone, as it seems to be more coding flavor based as opposed to actually identifying real bugs in random code bases, and can instead actually introduce bugs instead of fixing anything.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions