Nullcheck Major bug on CallableStatement

Hello everyone.

Sonar is detecting me a Major bug on the code implementing an integration with an Oracle Stored Procedure.

Here the code follows:

session.doReturningWork(new ReturningWork<List<ClassSample>>() {
			public List<ClassSample> execute(Connection con) throws SQLException {
				try (CallableStatement cs = con
						.prepareCall("{CALL SCHEMASAMPLE.proceduraSample(?,?)}")) {
					cs.setString("p_1_sample", sample1); //HERE SONAR COMPLAINS
					cs.registerOutParameter("p_3_sample", OracleTypes.ARRAY, "SCHEMASAMPLE.TYPESAMPLE");
					if (sampleIn != null) {
						cs.setInt("p_3_sample", sampleIn);
					return result;

Sonar complains a Correctness - Nullcheck of value previously dereferenced on the line cs.SetString(“p_1_sample”, sample1);

Here the explanation from SonarQube:
A value is checked here to see whether it is null, but this value can’t be null because it was previously dereferenced and if it were null a null pointer exception would have occurred at the earlier dereference. Essentially, this code and the previous dereference disagree as to whether this value is allowed to be null. Either the check is redundant or the previous dereference is erroneous.

Not getting if it is a FP or I have to apply some remediation for getting rid of it.

Thanks for the support,

Hi Matteo,

Welcome to the community!

What version of SonarQube are you using?

Also, could you provide a screenshot - redacted/blurred as necessary - of the issue in question? I’d like to make sure it’s not citing any secondary locations.

And one final request: what’s the rule key. It’ll be something like java:Snnn.