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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -75,14 +75,14 @@ public int hashCode(Object x) throws HibernateException { | |
|
||
@Override | ||
public Object nullSafeGet(ResultSet rs, String[] names, SharedSessionContractImplementor session, Object owner) throws HibernateException, SQLException { | ||
if (rs.wasNull()) { | ||
return null; | ||
} | ||
|
||
String amountColumnName = names[0]; | ||
String currencyColumnName = names[1]; | ||
|
||
BigDecimal amount = rs.getBigDecimal(amountColumnName); | ||
if(amount == null) { | ||
return null; | ||
} | ||
|
||
String currency = rs.getString(currencyColumnName); | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 I propose to use here:
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Because the Java doc of the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. But we should reconsider strategy. If any of a column has |
||
return Money.of(amount, currency); | ||
|
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.