how can fix this nullpointerexception on sonarcube?
Java Code:
GeneratedKeyHolder generatedKeyHolder = new GeneratedKeyHolder();
String sql = "Update users set enable=true where username=:username";
SqlParameterSource paramSource = new MapSqlParameterSource().addValue("username", u.getUsername());
namedParameterJdbcTemplate.update(sql, paramSource, generatedKeyHolder);
try {
return generatedKeyHolder.getKey().intValue();
A "NullPointerException" could be thrown; "getKey()" can return null.
}
catch (NullPointerException nl){
return 0;
}
}