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. 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);
statement outside of try/catch
block. As your method is throwing IOException
, you shouldn't be catching it. 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);
}
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.