Last line of the snippet is reported as an issue:
A “NullPointerException” could be thrown; “fileName” is nullable here.
However before fileName is used, check is made using StringUtils library and if fileName is indeed equal to null, exception is thrown.
- versions used (SonarQube, Revision: a27f41e4ae5e8a41ab9b19f8dd6d86d7b384dad4)
- minimal code sample to reproduce:
import org.springframework.util.StringUtils;
import org.springframework.web.multipart.MultipartFile;
...
public void readFile(MultipartFile file) {
String fileName = file.getOriginalFilename();
if (StringUtils.isEmpty(fileName)) {
throw new Exception();
}
String ext = fileName.substring(fileName.lastIndexOf('.'));
}