exception stack java.lang.IllegalStateException: Expected lazy evaluation to yield a non-null value but got null! at org.springframework.data.util.Lazy.get(Lazy.java:66) at org.springframework.data.mapping.model.AnnotationBasedPersistentProperty.isWritable(AnnotationBasedPersistentProperty.java:211) at org.springframework.data.mongodb.core.convert.MappingMongoConverter.writeProperties(MappingMongoConverter.java:490) at org.springframework.data.mongodb.core.convert.MappingMongoConverter.writeInternal(MappingMongoConverter.java:481) at org.springframework.data.mongodb.core.convert.MappingMongoConverter.writeInternal(MappingMongoConverter.java:455) at org.springframework.data.mongodb.core.convert.MappingMongoConverter.write(MappingMongoConverter.java:399) at org.springframework.data.mongodb.core.convert.MappingMongoConverter.write(MappingMongoConverter.java:78) at org.springframework.data.mongodb.core.MongoTemplate.toDocument(MongoTemplate.java:1071) at org.springframework.data.mongodb.core.MongoTemplate.doInsertBatch(MongoTemplate.java:1164) at org.springframework.data.mongodb.core.MongoTemplate.insert(MongoTemplate.java:1116)
Exception occured after system startup, guess concurrent invoking org.springframework.data.mapping.model.AnnotationBasedPersistentProperty#isWritable.get() caused the problem.
Check the code:
private final Lazy<Boolean> isWritable = Lazy
.of(() -> !isTransient() && !isAnnotationPresent(ReadOnlyProperty.class));
public T get() {
T value = getNullable();
if (value == null) {
throw new IllegalStateException("Expected lazy evaluation to yield a non-null value but got
null!");
}
return value;
}
@Nullable
private T getNullable() {
T value = this.value;
if (this.resolved) {
return value;
}
value = supplier.get();
this.value = value;
this.resolved = true;
return value;
}
guess problem was because of the class property "value" and "resolved" has no volatile claim. The jvm resort the third code, and at runtime, the resolved is firstly updated to memory while the "value" is still remain in thread local memory, at the same time another thread come to visit, then problem happened Above all is my guess, found no way to varify. please somebody check the issue.