[英]This method call passes a null value for a nonnull method parameter. Either the parameter is annotated as a parameter that should always be nonnull
SonarQube error for below method, any suggestion experts on how to resolve the issue -This method call passes a null value for a nonnull method parameter. 以下方法的SonarQube错误,有关如何解决问题的任何建议专家-此方法调用将为非空方法参数传递空值。 Either the parameter is annotated as a parameter that should always be nonnull, or analysis has shown that it will always be dereferenced. 该参数被注释为应始终为非空的参数,或者分析表明它将始终被取消引用。
public ByteArrayResource readFile() throws IOException {
byte[] content = null;
try (S3Object object = amazonS3.getObject(new GetObjectRequest(bucketName, key))) {
content = IOUtils.toByteArray(object.getObjectContent());
return new ByteArrayResource(content);
} catch (IOException e) {
LOG.error("IOException caught while reading file", e);
}
return new ByteArrayResource(content);
}
Problem is with return new ByteArrayResource(content);
问题是return new ByteArrayResource(content);
statement outside of try/catch
block. 在try/catch
块之外的语句。 As your method is throwing IOException
, you shouldn't be catching it. 当您的方法抛出IOException
,您不应该捕获它。 Below should resolve it: 下面应该解决它:
public ByteArrayResource readFile() throws IOException {
try (S3Object object = amazonS3.getObject(new GetObjectRequest(bucketName, key))) {
byte[] content = IOUtils.toByteArray(object.getObjectContent());
return new ByteArrayResource(content);
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.