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.

NullPointerException when commit property value is null

See original GitHub issue

It is possible to write a commit property whose value is null (in Java).

But when Javers later tries to read/parse this (by calling new JsonPrimitive() on this line), an NPE is thrown because JsonPrimitive doesn’t handle null.

Caused by: java.lang.NullPointerException
	at com.google.gson.JsonPrimitive.isPrimitiveOrString(JsonPrimitive.java:278)
	at com.google.gson.JsonPrimitive.setValue(JsonPrimitive.java:101)
	at com.google.gson.JsonPrimitive.<init>(JsonPrimitive.java:65)
	at org.javers.core.json.typeadapter.commit.CommitPropertiesConverter.toJson(CommitPropertiesConverter.java:34)
	at org.javers.core.json.typeadapter.commit.CdoSnapshotAssembler.assembleCommitMetadata(CdoSnapshotAssembler.java:72)
	at org.javers.core.json.typeadapter.commit.CdoSnapshotAssembler.assemble(CdoSnapshotAssembler.java:22)
	at org.javers.core.json.JsonConverter.fromSerializedSnapshot(JsonConverter.java:82)
	at org.javers.repository.sql.finders.CdoSnapshotFinder.lambda$fetchCdoSnapshots$3(CdoSnapshotFinder.java:94)
	at java.util.stream.ReferencePipeline$3$1.accept(ReferencePipeline.java:193)
	at java.util.ArrayList$ArrayListSpliterator.forEachRemaining(ArrayList.java:1380)
	at java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:481)
	at java.util.stream.AbstractPipeline.wrapAndCopyInto(AbstractPipeline.java:471)
	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.common.collections.Lists.transform(Lists.java:68)
	at org.javers.repository.sql.finders.CdoSnapshotFinder.fetchCdoSnapshots(CdoSnapshotFinder.java:93)
	at org.javers.repository.sql.finders.CdoSnapshotFinder.lambda$getLatest$0(CdoSnapshotFinder.java:54)
	at java.util.Optional.map(Optional.java:215)
	at org.javers.repository.sql.finders.CdoSnapshotFinder.getLatest(CdoSnapshotFinder.java:52)
	at org.javers.repository.sql.JaversSqlRepository.getLatest(JaversSqlRepository.java:51)
	at org.javers.repository.api.JaversExtendedRepository.getLatest(JaversExtendedRepository.java:92)
	at java.util.stream.ReferencePipeline$3$1.accept(ReferencePipeline.java:193)
	at java.util.HashMap$KeySpliterator.forEachRemaining(HashMap.java:1553)
	at java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:481)
	at java.util.stream.AbstractPipeline.wrapAndCopyInto(AbstractPipeline.java:471)
	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.core.snapshot.SnapshotGraphFactory.createLatest(SnapshotGraphFactory.java:29)
	at org.javers.core.commit.CommitFactory.create(CommitFactory.java:71)
	at org.javers.core.JaversCore.commit(JaversCore.java:82)
	at org.javers.spring.jpa.JaversTransactionalDecorator.commit(JaversTransactionalDecorator.java:65)

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:7 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
bartoszwalacikcommented, Dec 20, 2017

fix released in 3.7.7

0reactions
bartoszwalacikcommented, Nov 10, 2017

so we need to filter out all keys with null values

Read more comments on GitHub >

github_iconTop Results From Across the Web

Javers throws exception when property is null - java
If I commit a User object, if either Person or Address has a null property, Javers fails with the above error. How does...
Read more >
NullPointerException when commiting/making roll... - JBoss.org
RuntimeException: Unable to commit the transaction caused by NullPointerException. ... But the property is there so I am wondering why.
Read more >
How to Fix and Avoid NullPointerException in Java - Rollbar
NullPointerException in Java occurs when a variable is accessed which is not pointing to any object and refers to nothing or null.
Read more >
How can I resolve Null pointer exception in my transaction ...
I get null pointer exception when I try my Server ......20_txnmgr_conf.xml ... <property name="persistent-space" value="jdbm:MyTxnSpace" />.
Read more >
System.setProperty(key, value) does not accept null value
If value is null, System.setProperty(key, value) will throw NullPointerException. This behavior is not on the spec and makes it difficult to remove a...
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