so have equality comparison as
if( profiletypecode.equals( profileconstant.type_bill ) ) {
this possibly generate nullpointerexception if profiletypecode not correctly contain value being compared constant.
correct
if( profileconstant.type_bill.equals( profiletypecode ) ) {
i looking code violation plugin flag type of violations. using codepro , didn't flag this.
can me how flag kind of comparisons ?
you can use findbugs fb-contrib plugin: has diagnostic called lsc_literal_string_comparison:
this line in form of
string str = ... str.equals("someotherstring"); //or str.compareto("someotherstring");
a
nullpointerexception
may occur ifstring
variablestr
null
. if instead code restructured tostring str = ... "someotherstring".equals(str); //or "someotherstring".compareto(str);
that is, call
equals()
orcompareto()
on string literal, passing variable argument, exception never happen bothequals()
,compareto()
checknull
.
seems it's need.
Comments
Post a Comment