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
Fix npe if money is null #467
Conversation
Thanks, I'll review it when I have some time. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@ugrave great catch!
if(amount == null) { | ||
return null; | ||
} | ||
|
||
String currency = rs.getString(currencyColumnName); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Null-check should be here. Because creating monetary type without currency make no sense and could rise an exception Currency Code may not be null
.
I propose to use here:
if (rs.wasNull()) {
return null;
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Question is should the system thow an exception if only one of them is null or still ignored it an return also null in that case. I`m was not sure about this case and decide to let the exception be thrown.
Is there a diffferend if i use rs.wasNull()
or check the value of the last read column on none primitive types?
To get the correct result of rs.wasNull()
i need to read the column before. It also only checks if the last read column is null.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Because the Java doc of the rs.getBigDicimal(x)
says: if the value is SQL NULL, the value returned is null
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
null
seems to be enough.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
But we should reconsider strategy. If any of a column has null
- that should be null
or exception? Maybe if any value is null
- null
should be returned.
String amountColumnName = names[0]; | ||
String currencyColumnName = names[1]; | ||
|
||
BigDecimal amount = rs.getBigDecimal(amountColumnName); | ||
if(amount == null) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Removing this null-check in favor of rs.wasNull()
(see prev comment).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@piotrooo The wasNull
method call is useful only when you have primitive values on the Java side, but this is not the case here. We can use == null
checks.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
null
seems to be enough.
Applied upstream, thanks. |
Closed gh-465