I have the following code:
try {
if ((jsonData = new JSONObject(getJSONString(request))) != null) {
if (jsonData.has("country_code")) {
user_id = Integer.valueOf(request.getParameter("user_id"));
jobjcountries = new OpenNCPApi().getCountryListAttritube(jsonData.getString("country_code"), "en");
jObj.put("status", 1);
jObj.put("attributes", jobjcountries);
return jObj.toString();
} else {
jObj.put("status", 0);
jObj.put("error", "Unfilled inputs");
return jObj.toString();
}
}
//request is null
else {
jObj.put("status", 0);
jObj.put("error", "Unfilled inputs");
return jObj.toString();
}
} catch (Exception e) {
e.printStackTrace();
jObj.put("status", 0);
jObj.put("error", "Problem while calling ncp service");
return jObj.toString();
} finally {...}
For the following code I get a warning of dead code
.
else {
jObj.put("status", 0);
jObj.put("error", "Unfilled inputs");
return jObj.toString();
}
However, return jObj.toString();
is needed to be there and I need to have status
and error
values. I've added this else
statement to satisfies the case when (jsonData = new JSONObject(getJSONString(request)))
is null.