Skip to content

foo != foo #53

Closed
Closed
@cushon

Description

@cushon
Collaborator

Original issue created by kevinb@google.com on 2012-11-02 at 01:57 PM


There is no good reason to test a primitive value or reference for inequality with itself. It is likely to mask a bug, or at least be pointlessly confusing.

The fix for 'foo != foo' is

  • if foo is of type float, replace with 'Float.isNaN(foo)'
  • if foo is of type double, replace with 'Double.isNaN(foo)'
  • otherwise, the transliteration is obviously to replace with 'false', which of course might not be want the user intended...

Here's an example of something this would have caught in the JDK:
http://bugs.sun.com/view_bug.do;jsessionid=a3391b8310ec77f33a52e1afb90d?bug_id=6958423

Activity

cushon

cushon commented on Oct 31, 2014

@cushon
CollaboratorAuthor

Original comment posted by eaftan@google.com on 2013-02-11 at 09:34 PM


(No comment entered for this change.)


Status: Accepted

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Development

      No branches or pull requests

        Participants

        @cushon

        Issue actions

          foo != foo · Issue #53 · google/error-prone