Domanda

I'm replacing a group of String constants with an enum, but the constants weren't used everywhere they should have been. So we're replacing a lot of someValue.equals(FOO_CONST) with someValue == MyEnum.FOO. It's easy to fix all the places where they were used--just delete the constants and the compiler tells you where the problems are. However, there are also bits like "foo".equals(someValue), which the compiler can't identify as an error after the change is made.

Is there any way I can detect potential bugs caused by any of these inline literals that get missed during the conversion? (I'm using eclipse)

È stato utile?

Soluzione

FindBugs reports bugs for calls to equals(Object) when the two objects are not of the same type, which handles this problem nicely.

They will show up in the Bug Explorer under:

  • Scariest
    • High confidence
      • Call to equals() comparing different types
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top