Skip to content
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

NullPointerException when Levenshtein distance and NewObjectsSnapshot are used together #820

Closed
bkuzio opened this issue Apr 2, 2019 · 2 comments

Comments

@bkuzio
Copy link

@bkuzio bkuzio commented Apr 2, 2019

Hello,

When configuring Javers to use new objects snapshot and Levenshtein distance list comparison, then comparing to null object, I'm getting NullPointerException. It doesn't happen when either a different list comparison method is used or new object snapshot is not used.

Test case to reproduce (version 5.3.4):

class BugTest {

    @Test
    void shouldNotFail() {
        Javers javers = JaversBuilder.javers().withNewObjectsSnapshot(true)
                                     .withListCompareAlgorithm(ListCompareAlgorithm.LEVENSHTEIN_DISTANCE).build();

        javers.compare(null, new Obj(Collections.singletonList("test")));
    }
    static class Obj {
        private List<String> strings;

        public Obj(List<String> strings) {
            this.strings = strings;
        }
    }
}

The issue seems to be similar to #240, but not exactly the same.

Same error happens when comparing a list to an empty list:
javers.compareCollections(Collections.emptyList(), Collections.singletonList(obj));

Stack trace:

java.lang.NullPointerException
at org.javers.core.diff.appenders.levenshtein.Backtrack.evaluateSteps(Backtrack.java:21)
at org.javers.core.diff.appenders.levenshtein.LevenshteinListChangeAppender.calculateChanges(LevenshteinListChangeAppender.java:44)
at org.javers.core.diff.appenders.levenshtein.LevenshteinListChangeAppender.calculateChanges(LevenshteinListChangeAppender.java:17)
at org.javers.core.diff.appenders.CorePropertyChangeAppender.calculateChanges(CorePropertyChangeAppender.java:45)
at org.javers.core.diff.DiffFactory.appendChanges(DiffFactory.java:153)
at org.javers.core.diff.DiffFactory.appendPropertyChanges(DiffFactory.java:143)
at org.javers.core.diff.DiffFactory.createAndAppendChanges(DiffFactory.java:119)
at org.javers.core.diff.DiffFactory.create(DiffFactory.java:69)
at org.javers.core.diff.DiffFactory.compare(DiffFactory.java:54)
at org.javers.core.JaversCore.compare(JaversCore.java:171)

bartoszwalacik added a commit that referenced this issue Apr 9, 2019
bartoszwalacik added a commit that referenced this issue Apr 10, 2019
@bartoszwalacik
Copy link
Member

@bartoszwalacik bartoszwalacik commented Apr 10, 2019

fixed in 5.3.6

@bkuzio
Copy link
Author

@bkuzio bkuzio commented Apr 11, 2019

Thanks! Can confirm that it works.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
2 participants