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

commit_date_instant NullPointerException when committing entities created prior 5.1.3 #782

Closed
kkonstantin42 opened this issue Feb 14, 2019 · 3 comments
Labels

Comments

@kkonstantin42
Copy link

I have upgraded our project from Javers 3.12.1 to 5.1.3 and now getting NullPointerException (stacktrace below) when committing entities that have older commits that were done before the upgrade. Committing new entities works well. We are using SqlRepository with postgresql database.

Done a bit of digging into the source code and it looks like exception happens when Javers is deserialising commit_date_instant column value in SnapshotQuery:166 which is always null for older commits.

Here is a relevant part of the stack trace:

 java.lang.NullPointerException: text
        at java.util.Objects.requireNonNull(Objects.java:228)
        at java.time.format.DateTimeFormatter.parse(DateTimeFormatter.java:1846)
        at java.time.Instant.parse(Instant.java:395)
        at org.javers.core.json.CdoSnapshotSerialized.withCommitDateInstant(CdoSnapshotSerialized.java:45)
        at org.javers.repository.sql.finders.SnapshotQuery$CdoSnapshotMapper.get(SnapshotQuery.java:166)
        at org.javers.repository.sql.finders.SnapshotQuery$CdoSnapshotMapper.get(SnapshotQuery.java:160)
        at org.javers.repository.sql.session.PreparedStatementExecutor.lambda$executeQuery$5(PreparedStatementExecutor.java:64)
        at org.javers.repository.sql.session.PreparedStatementExecutor$$Lambda$1279/63189136.callAndGet(Unknown Source)
        at org.javers.repository.sql.session.PreparedStatementExecutor.wrapExceptionAndCall(PreparedStatementExecutor.java:126)
        at org.javers.repository.sql.session.PreparedStatementExecutor.runSql(PreparedStatementExecutor.java:100)
        at org.javers.repository.sql.session.PreparedStatementExecutor.executeQuery(PreparedStatementExecutor.java:58)
        at org.javers.repository.sql.session.Session.executeQuery(Session.java:99)
        at org.javers.repository.sql.session.SelectBuilder.executeQuery(SelectBuilder.java:99)
        at org.javers.repository.sql.finders.SnapshotQuery.run(SnapshotQuery.java:148)
        at org.javers.repository.sql.finders.CdoSnapshotFinder.fetchCdoSnapshots(CdoSnapshotFinder.java:92)
        at org.javers.repository.sql.finders.CdoSnapshotFinder.lambda$getLatest$1(CdoSnapshotFinder.java:51)
        at org.javers.repository.sql.finders.CdoSnapshotFinder$$Lambda$1270/1714142470.apply(Unknown Source)
        at java.util.Optional.map(Optional.java:215)
        at org.javers.repository.sql.finders.CdoSnapshotFinder.getLatest(CdoSnapshotFinder.java:46)
        at org.javers.repository.sql.JaversSqlRepository.lambda$getLatest$0(JaversSqlRepository.java:72)
        at org.javers.repository.sql.JaversSqlRepository$$Lambda$1266/145383050.apply(Unknown Source)
        at java.util.stream.ReferencePipeline$3$1.accept(ReferencePipeline.java:193)
        at java.util.HashMap$KeySpliterator.forEachRemaining(HashMap.java:1540)
        at java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:512)
        at java.util.stream.AbstractPipeline.wrapAndCopyInto(AbstractPipeline.java:502)
        at java.util.stream.ReduceOps$ReduceOp.evaluateSequential(ReduceOps.java:708)
        at java.util.stream.AbstractPipeline.evaluate(AbstractPipeline.java:234)
        at java.util.stream.ReferencePipeline.collect(ReferencePipeline.java:499)
        at org.javers.repository.sql.JaversSqlRepository.getLatest(JaversSqlRepository.java:75)
        at org.javers.repository.api.JaversExtendedRepository.getLatest(JaversExtendedRepository.java:98)
        at org.javers.core.snapshot.SnapshotGraphFactory.createLatest(SnapshotGraphFactory.java:24)
        at org.javers.core.commit.CommitFactory.createCommit(CommitFactory.java:86)
        at org.javers.core.commit.CommitFactory.create(CommitFactory.java:75)
        at org.javers.core.JaversCore.commit(JaversCore.java:82)
@bartoszwalacik
Copy link
Member

that's easy to fix, consider contributing a PR

@kkonstantin42
Copy link
Author

Sure, will do a PR

@bartoszwalacik
Copy link
Member

fix released in 5.2.0

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

No branches or pull requests

2 participants