java - Object not created locally -
i have in method snippet below:
jsonparser jsonparser = new jsonparser(); try { object obj = jsonparser.parse(new inputstreamreader(is)); jsonobject jsonobj = (jsonobject) obj; jsonarray jsonarray = (jsonarray) jsonobj.get("json_node"); string jsonstr = jsonarray.tojsonstring(); return (jsonobject)jsonparser.parse(jsonstr); }
in sonarqube getting issue "object not created locally" on
string jsonstr = jsonarray.tojsonstring();
i trying understand why getting this. help?
why violation?
this violation relates fact method called on object not created within method , rather, retrieved return object result of method invocation on 1 of local objects.
your jsonarray
object satisfies above condition.
how fix ,
see 1 sample listed here , code can fixed on similar lines.
according law of demeter, method m
of object o
should call following types of methods :
1.methods of object o 2.methods of object passed argument 3.method of object, held in instance variable 4.any object created locally in method m
Comments
Post a Comment