[英]A “NullPointerException” could be thrown; “getBody” can return null Sonar
Sonar points that A "NullPointerException" could be thrown; "getBody()" can return null
声纳指出
A "NullPointerException" could be thrown; "getBody()" can return null
A "NullPointerException" could be thrown; "getBody()" can return null
around recaptchaResponseEntity.getBody()
"getBody()" 可以在
recaptchaResponseEntity.getBody()
周围A "NullPointerException" could be thrown; "getBody()" can return null
public BooleanResponse verifyCaptcha(String recaptchaResponse) {
//Alot more sophisticated logic
Boolean success = (Boolean) recaptchaResponseEntity.getBody().get("success");
List<String> errors = (List) recaptchaResponseEntity.getBody().get("error-codes");
return success ? BooleanResponse.success() : BooleanResponse.failure(errors.get(0));
}
I tried我试过了
recaptchaResponseEntity.getBody()!=null , Objects.noNull(recaptchaResponseEntity.getBody()),
!Objects.isNull(recaptchaResponseEntity.getBody())
But got no luck, can you please help to resolve this issue?但是没有运气,你能帮忙解决这个问题吗? Thanks
谢谢
Each of your example attempt do not store the compared value anywhere.您的每个示例尝试都不会将比较值存储在任何地方。 I assume that you have run those checks, but then you still called
getBody()
again, which would trigger the issue (there is no guarantee that the method will return the same result twice).我假设您已经运行了这些检查,但是您仍然再次调用
getBody()
,这将触发问题(不能保证该方法将返回两次相同的结果)。 I would try to store getBody()
return value in a variable and only use that after the check, eg:我会尝试将
getBody()
返回值存储在变量中,并且仅在检查后使用它,例如:
<appropriate type here> recaptchaResponseBody = recaptchaResponseEntity.getBody();
if (recaptchaResponseBody != null) {
Boolean success = (Boolean) recaptchaResponseBody.get("success");
...
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.