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.

Exception during comparing String value - java.lang.ClassCastException: org.javers.core.metamodel.property.MissingProperty incompatible with java.lang.String

See original GitHub issue

Using 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:open
  • Created 3 years ago
  • Comments:9 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
bartoszwalacikcommented, Mar 18, 2021

looks like a bug in javers, it probably happens when you compare two objects with different type definition but the same type name

Read more comments on GitHub >

github_iconTop Results From Across the Web

Release notes — JaVers Documentation
851 Fixed exception: java.lang.ClassCastException: class org.javers.core.metamodel.property.MissingProperty cannot be cast to class java.util.List.
Read more >
java.lang.ClassCastException: org.javers.core.diff.changetype ...
You are trying to cast an existing value change event into a map change event, which it isn't. Try doing exactly what you...
Read more >
CdoSnapshot (javers-core 5.15.0 API) - javadoc.io
Historical state of a domain object captured as the property->value Map. Values and primitives are stored 'by value'. Referenced Entities and ValueObjects ...
Read more >
javers - Bountysource
Exception during comparing String value - java.lang.ClassCastException: org.javers.core.metamodel.property.MissingProperty incompatible with java.lang.
Read more >
Collator (Java SE 15 & JDK 15) - Oracle Help Center
The Collator class performs locale-sensitive String comparison. You use this class to build searching and sorting routines for natural language text.
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