question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Allow CustomValueComparators to handle nulls

See original GitHub issue

Currently, before calling a CustomValueComparator impl, Javers checks nulls and assumes that :

null != any non-null value

This assumption simplifies an impl, but from the other hand it makes impossible to write a Comparator which treats nulls as empty values. See https://stackoverflow.com/questions/66497652/javers-comparison-string-collection-and-boolean-with-defined-rules

public interface CustomValueComparator<T> {
    /**
     * Called by JaVers to compare two Values.
     *
     * @param a not null
     * @param b not null
     */
    boolean equals(T a, T b);

New feature Skip the Javers internal null-safety logic and allow passing nulls to CustomValueComparators.

Unfortunately it could break existing users’ code

Test case CaseWithCustomComparatorBlejwas.groovy

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Reactions:2
  • Comments:7 (6 by maintainers)

github_iconTop GitHub Comments

1reaction
bluebartlecommented, Nov 4, 2021

Thanks @bartoszwalacik - and good point. I’ll make the naming more straightforward as suggested. I’ll get a PR raised presently.

1reaction
bartoszwalacikcommented, Nov 4, 2021

Ok @ratskinmahoney, your design looks good, but maybe we can avoid double negations?

public interface CustomValueComparator<T> {
  
  // ...

  default boolean nullSafety() { return true; }
}
Read more comments on GitHub >

github_iconTop Results From Across the Web

CustomValueComparator not called, when attribute is null in ...
I'm using Javers to compare two object having a String attribute. Since in my application an empty String and a null value in...
Read more >
Release notes — JaVers Documentation
1075 Added a new feature which allows CustomValueComparators to handle nulls: ... Javers skips that logic and * allows a comparator to handle...
Read more >
How to Use Comparison Operators with NULLs in SQL
Let's get started by reviewing NULL values in SQL. ... To handle NULLs correctly, SQL provides two special comparison operators: IS NULL and ......
Read more >
Javers Compare String Null And "" Empty String - ADocLib
javers/javers.github.io 4 #1075 Allow CustomValueComparators to handle nulls.#1075 This comment begins the outline of the approach. To allow nulls you can ...
Read more >
Best way to handle nulls in Java? [closed]
Or something that allows erroneous code to be somehow acceptable. Can you explain how erroneous code is not getting fixed? What's the political ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found