Skip to content

Default values in entities are not used, potentially causes NullPointerExceptions #2565

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
cberes opened this issue Jul 12, 2022 · 3 comments
Assignees
Labels
type: bug A general bug

Comments

@cberes
Copy link
Contributor

cberes commented Jul 12, 2022

SDN does not respect default values set in entities. This differs from OGM's behavior.

For example, say you have an entity like this

@Getter
@Setter
@Node
public abstract class MyNode {
  @Property("name")
  private String name;

  @Property("active")
  private boolean active = true;

  @Property("age")
  private Integer age = 25;
}

And you create a new node without the active and age properties

CREATE (:MyNode {id: '123', name: 'Nikola Tesla'})

When you query for the node, active will be false and age will be null

MyNode found = myNodeRepository.findById("123").get();
if (!found.isActive()) {                // active is false but it should be true
  found.setAge(found.getAge() - 1);     // age is null: NullPointerException
}

As far as I know, this example has never worked correctly in SDN. Specifically I tried this with 6.3.1 and 6.2.0 and saw the same behavior.

However, this differs from OGM, which uses the default values set in an entity. The tests in this project would pass if run using OGM.

This seems similar to #2348

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

I tend to agree this is a bug.

@meistermeier
Copy link
Collaborator

I tend to agree with you and Michael. 🙂

@meistermeier meistermeier self-assigned this Jul 13, 2022
@meistermeier meistermeier added type: bug A general bug and removed status: waiting-for-triage An issue we've not yet triaged labels Jul 13, 2022
meistermeier added a commit that referenced this issue Jul 13, 2022
meistermeier added a commit that referenced this issue Jul 13, 2022
Allows to use default values in the entity classes.
Closes #2565
meistermeier added a commit that referenced this issue Jul 13, 2022
@meistermeier
Copy link
Collaborator

Thanks for reporting this. This was something I had not realised before.
It is fixed now in 6.3.2-GH-2565-SNAPSHOT but will very certain get merged tomorrow into 6.2, 6.3 and main.

meistermeier added a commit that referenced this issue Jul 14, 2022
Allows to use default values in the entity classes.
Closes #2565
meistermeier added a commit that referenced this issue Jul 14, 2022
Allows to use default values in the entity classes.
Closes #2565
@michael-simons michael-simons mentioned this issue Jan 4, 2023
4 tasks
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

4 participants