[JAVA-2951] NPE with getter without backing field Created: 29/Aug/18 Updated: 28/Oct/23 Resolved: 30/Aug/18 |
|
| Status: | Closed |
| Project: | Java Driver |
| Component/s: | POJO |
| Affects Version/s: | 3.7.0, 3.7.1, 3.8.0, 3.8.1 |
| Fix Version/s: | 3.8.2 |
| Type: | Bug | Priority: | Major - P3 |
| Reporter: | Clécius J. Martinkoski | Assignee: | Ross Lawley |
| Resolution: | Fixed | Votes: | 0 |
| Labels: | None | ||
| Remaining Estimate: | Not Specified | ||
| Time Spent: | Not Specified | ||
| Original Estimate: | Not Specified | ||
| Backwards Compatibility: | Fully Compatible |
| Description |
|
ConventionSetPrivateFieldImpl throws a NPE when mapping a POJO with a getter method. This getter isn't related to a backing field, it is simply a business getter (like getTotal() of a sale). The relevant part of stacktrace is:
Debugging to discover the NPE source i'm got to this point of failure at line 36 of bson/src/main/org/bson/codecs/pojo/ConventionSetPrivateFieldImpl.java:
When the propertyMetaData has state:
The return of isDeserializable is false, then after ! the other condition of && is tested, in this the propertyMetadaData.getField() that is null, is acessed without nullable check.
|
| Comments |
| Comment by Githook User [ 30/Aug/18 ] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Author: {'name': 'Ross Lawley', 'email': 'ross.lawley@gmail.com', 'username': 'rozza'}Message: Fix NPE error with ConventionSetPrivateField
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Comment by Githook User [ 30/Aug/18 ] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Author: {'name': 'Ross Lawley', 'email': 'ross.lawley@gmail.com', 'username': 'rozza'}Message: Fix NPE error with ConventionSetPrivateField
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Comment by Ross Lawley [ 30/Aug/18 ] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Hi eprecise-clecius, Thanks - seems my intellij was having an issue and wouldnt reload the class. I have a fix in review. Ross | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Comment by Clécius J. Martinkoski [ 30/Aug/18 ] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Hi @ross.lawley, I'm thinking in send a PR with this correction, do you see problems? About the example, i've reached this bug in java and in kotlin as well, i'll send to you both POJO samples:
Java example:
The kotlin example:
The problem is on getter that only execute some rule then return, without backing field. In first case our workaroud is removing 'get' prefix, but in kotlin this is generated by the compiler. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Comment by Ross Lawley [ 30/Aug/18 ] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Hi eprecise-clecius, Could you provide an example POJO? - when testing this didn't NPE and I would like to add a regression test case. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Comment by Ross Lawley [ 30/Aug/18 ] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Thanks for reporting this eprecise-clecius. Will look to fix in the next release.
|