-
Notifications
You must be signed in to change notification settings - Fork 30
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 null pointer issue when typeKey is set as null #685
Conversation
When a custom bean of AerospikeTypeAliasAccessor is created passing null in the constructor(for skipping the typeKey to be saved in aerospike) eg: @bean public AerospikeTypeAliasAccessor aerospikeTypeAliasAccessor() { return new AerospikeTypeAliasAccessor(null); } While saving there is null check in writeTypeTo method to safely skip saving the typeKey if its passed as null, but in case of readAliasFrom it will throw NullPointerException, so added null check.
How can I add a label to this pull request? |
@avi054, added. |
Hi @avi054 thanks for contributing to Spring Data Aerospike! I tried to override When calling typeKey = null -> source.get(typeKey) returns null -> Alias.ofNullable(null) returns Alias.NONE. Can you please share the rest of the code and the exact record you have in your database that resulted in NPE? I think this check might be redundant since its already being checked when calling Alias.ofNullable(). Also worth mentioning: |
Hi @roimenashe , Null pointer will be thrown by sources.get(null), that's why the check is necessary. |
@avi054 That's Map interface documentation but null handling depends on the implementation, when reading from Aerospike we use Can you provide the exact case that resulted in a NPE? |
Hi @roimenashe , LinkedHashMap is only used for bins, but when we stored a list of nested objects, internally it is unpacked as a ArrayList of TreeMap. |
Sample code to reproduce:
Sample json: |
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.
When a custom bean of AerospikeTypeAliasAccessor is created passing null in the constructor(for skipping the typeKey to be saved in aerospike)
eg:
While saving there is null check in writeTypeTo method to safely skip saving the typeKey if its passed as null, but in case of readAliasFrom it will throw NullPointerException, so added null check.