Exception during comparing String value - java.lang.ClassCastException: org.javers.core.metamodel.property.MissingProperty incompatible with java.lang.String
See original GitHub issueUsing Javers I created custom comparator for String value so that null and empty String treat as same value. During manual tests in private project (I cant show you code of this project) I came accross such an exception:
java.lang.ClassCastException: org.javers.core.metamodel.property.MissingProperty incompatible with java.lang.String at .StringComparator.compare(StringComparator.java:21) at org.javers.core.diff.custom.CustomToNativeAppenderAdapter.calculateChanges(CustomToNativeAppenderAdapter.java:33) 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:125) 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:175) …
This is what StringComparator look like:
class StringComparator implements CustomPropertyComparator<String, SetChange> {
StringComparator() {
}
@Override
public Optional<SetChange> compare(String originString, String modifizierteString,
PropertyChangeMetadata propertyChangeMetadata, Property property) {
if (equals(originString, modifizierteString)) {
return Optional.empty();
} else {
final Set<Character> leftSet = getSetCharacterFromString(originString);
final Set<Character> rightSet = getSetCharacterFromString(modifizierteString);
return getSetChangeFromDiffrentSets(leftSet, rightSet, propertyChangeMetadata);
}
}
@Override
public boolean equals(String s1, String s2) {
return StringUtils.equals(StringUtils.defaultString(s1), StringUtils.defaultString(s2));
}
@Override
public String toString(String s) {
return s;
}
private Set<Character> getSetCharacterFromString(String s) {
return !isNull(s) ? s.chars().mapToObj(c -> (char) c).collect(Collectors.toSet()) : null;
}
}
Can anyone tell me whether this is a javers bug or my code bug? I think I am not able to debug it, because immediately throws exception.
Javers’ Version 5.14
Issue Analytics
- State:
- Created 3 years ago
- Comments:9 (5 by maintainers)

Top Related StackOverflow Question
looks like a bug in javers, it probably happens when you compare two objects with different type definition but the same type name
we need a working test case , see https://github.com/javers/javers/blob/master/CONTRIBUTING.md#guidelines-for-bug-reporting