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

Popular posts from this blog

android - Why am I getting the message 'Youractivity.java is not an activity subclass or alias' -

python - How do I create a list index that loops through integers in another list -

c# - “System.Security.Cryptography.CryptographicException: Keyset does not exist” when reading private key from remote machine -