New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Problem with passing null parameter to MapSqlParameterSource [SPR-16843] #21383

Closed
spring-issuemaster opened this Issue May 18, 2018 · 3 comments

Comments

Projects
None yet
2 participants
@spring-issuemaster
Copy link
Collaborator

spring-issuemaster commented May 18, 2018

Georgi Lengarski opened SPR-16843 and commented

I have following problem when pass null to MapSqlParameterSource

 

{{ final MapSqlParameterSource paramMap = new MapSqlParameterSource()
.addValue("ALERT_ID", null);}}
|Code|Warning|
|:---|:---|
|NP|Null passed for non-null parameter of org.springframework.jdbc.core.namedparam.MapSqlParameterSource.addValue(String, Object) in bug.DocDao.test()|
| |Bug type NP_NONNULL_PARAM_VIOLATION (click for details) In class bug.DocDaoIn method bug.DocDao.test()Called method org.springframework.jdbc.core.namedparam.MapSqlParameterSource.addValue(String, Object)Argument 2 is definitely null but must not be nullAt DocDao.java:[line 15]|

In my case null is valid value for database.
Sample code is attached here
https://github.com/lengarski/bug

Here is the response from spotbugs
spotbugs/spotbugs#642


Affects: 5.0.5

Issue Links:

  • #21371 ConcurrentModel.addAttribute(name, value) javadoc should not declare null value as acceptable

Referenced from: commits d9c6318, 99534a3

@spring-issuemaster

This comment has been minimized.

Copy link
Collaborator

spring-issuemaster commented May 18, 2018

Juergen Hoeller commented

Indeed, those value parameters need to be marked as @Nullable. Fixed on master now; I'll backport it to 5.0.7 ASAP.

@spring-issuemaster

This comment has been minimized.

Copy link
Collaborator

spring-issuemaster commented Jul 4, 2018

Georgi Lengarski commented

Hello Juergen Hoeller,

I try with last version 5.0.7 but problem is still there. 

in my pom.xml

<groupId>org.springframework</groupId>
   <artifactId>spring-jdbc</artifactId>
    <version>5.0.7.RELEASE</version>
</dependency>

 

My code is the same as before 

final MapSqlParameterSource paramMap = new MapSqlParameterSource().addValue("ALERT_ID", null);

and the error again is the same 

|Null passed for non-null parameter of org.springframework.jdbc.core.namedparam.MapSqlParameterSource.addValue(String, Object) in bug.DocDao.test()|
| |Bug type NP_NONNULL_PARAM_VIOLATION (click for details) 
In class bug.DocDao
In method bug.DocDao.test()
Called method org.springframework.jdbc.core.namedparam.MapSqlParameterSource.addValue(String, Object)
Argument 2 is definitely null but must not be null
At DocDao.java:[line 15]|

 

@spring-issuemaster

This comment has been minimized.

Copy link
Collaborator

spring-issuemaster commented Jul 4, 2018

Juergen Hoeller commented

This seems to have been fixed on master (for 5.1) only; sorry for missing the backport there. I'll roll it into 5.0.8.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment