Skip to content

Use default values for primitive attributes when Graph properties are unset. #2348

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

Closed
fnordian opened this issue Aug 4, 2021 · 2 comments
Closed
Assignees
Labels
type: bug A general bug

Comments

@fnordian
Copy link

fnordian commented Aug 4, 2021

I am upgrading my existing application to sdn6. There's a boolean field in my entities that is not set for some of the nodes.

Reading those nodes fails with NullPointerException when unboxing null to boolean.

I tried to trace that problem and to me it seems that DefaultNeo4jConversionService has extra handling for null-values (valueIsLiteralNullOrNullValue) and that causes that no converters are called.

So the case cannot be caught through a custom converter. Is there another way to handle null-values gracefully?

This problem did not exist with OGM

@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged label Aug 4, 2021
@michael-simons
Copy link
Collaborator

Are you happen to have these properties defined as constructor parameters? Than this behavior is expected.

It used to be a mapping exception but that prevents Kotlins explicit defaults from working:

871d586

Non constructor properties should work.
If not I take care next week. Also for your other issues. Thanks for reporting them. 👍

@michael-simons michael-simons self-assigned this Aug 4, 2021
@michael-simons michael-simons added type: bug A general bug and removed status: waiting-for-triage An issue we've not yet triaged labels Aug 9, 2021
@michael-simons michael-simons changed the title NPE when boolean property is not set Use default values for primitive attributes when Graph properties are unset. Aug 9, 2021
@michael-simons
Copy link
Collaborator

That has been actually more tricky than I thought, as we also want to support Kotlin default values (non JVM defaults, but explicit ones). But things should work now. Thanks again for the report.

@michael-simons michael-simons added this to the 6.0.12 (2020.0.12) milestone Aug 9, 2021
michael-simons added a commit that referenced this issue Aug 9, 2021
…erties are unset.

This changes the behaviour in regards of default values for primitives attributes of domain objects: They have well known default values on the JVM and we should use them, even if the property is non-existent in the graph (materializing as literal null). People migrating from SDN+OGM rely on the behaviour.

This change does not apply to attributes assigned via constructor arguments.
Constructor argument don't have default values (in Java) and we try to avoid guessing as much as possible.
In addition, it would also clash with actually possible default values in Kotlin data classes.

The change cannot be done in `DefaultNeo4jConversionService` as originally planned, as the conversion service is of course unaware about the target of a converted value.

This fixes #2348.
michael-simons added a commit that referenced this issue Aug 9, 2021
…erties are unset.

This changes the behaviour in regards of default values for primitives attributes of domain objects: They have well known default values on the JVM and we should use them, even if the property is non-existent in the graph (materializing as literal null). People migrating from SDN+OGM rely on the behaviour.

This change does not apply to attributes assigned via constructor arguments.
Constructor argument don't have default values (in Java) and we try to avoid guessing as much as possible.
In addition, it would also clash with actually possible default values in Kotlin data classes.

The change cannot be done in `DefaultNeo4jConversionService` as originally planned, as the conversion service is of course unaware about the target of a converted value.

This fixes #2348.
michael-simons added a commit that referenced this issue Aug 17, 2021
michael-simons added a commit that referenced this issue Aug 17, 2021
michael-simons added a commit that referenced this issue Aug 17, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: bug A general bug
Projects
None yet
Development

No branches or pull requests

3 participants