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

MissingProperty cannot be cast to class java.util.Map #988

Closed
kucharzyk opened this issue Jun 19, 2020 · 5 comments
Closed

MissingProperty cannot be cast to class java.util.Map #988

kucharzyk opened this issue Jun 19, 2020 · 5 comments
Labels

Comments

@kucharzyk
Copy link
Contributor

@kucharzyk kucharzyk commented Jun 19, 2020

Hi,

I've got ClassCastException after adding map to my entity

Test case:

    @TypeName("E")
    class Entity1 {
        @Id int id
    }

    @TypeName("E")
    class Entity2 {
        @Id int id
        List<String> propsList
        Set<String> propsSet
        Map<String, String> propsMap
    }

    def "should report when a list property is added or removed"(){
      given:
      def javers = javers().build()
      def object1 = new Entity1(id:1)
      def object2 = new Entity2(id:1, propsList: ["p"], propsSet: ["p"] as Set, propsMap: ["k": "v"])

      when:
      def diff = javers.compare(object1, object2)
      println diff.prettyPrint()
      def changes = diff.getChangesByType(PropertyChange)

      then:
      changes.size() == 3
      changes[0].propertyAdded
      changes[1].propertyAdded
      changes[2].propertyAdded

      when:
      diff = javers.compare(object2, object1)
      println diff.prettyPrint()
      changes = diff.getChangesByType(PropertyChange)

      then:
      changes.size() == 3
      changes[0].propertyRemoved
      changes[1].propertyRemoved
      changes[2].propertyRemoved
    }

Stacktrace:

class org.javers.core.metamodel.property.MissingProperty cannot be cast to class java.util.Map (org.javers.core.metamodel.property.MissingProperty is in unnamed module of loader 'app'; java.util.Map is in module java.base of loader 'bootstrap')
java.lang.ClassCastException: class org.javers.core.metamodel.property.MissingProperty cannot be cast to class java.util.Map (org.javers.core.metamodel.property.MissingProperty is in unnamed module of loader 'app'; java.util.Map is in module java.base of loader 'bootstrap')
	at org.javers.common.collections.Maps.wrapNull(Maps.java:17)
	at org.javers.core.metamodel.type.MapType.map(MapType.java:47)
	at org.javers.core.metamodel.type.EnumerableType.map(EnumerableType.java:39)
	at org.javers.core.graph.LiveNode.getDehydratedPropertyValue(LiveNode.java:84)
	at org.javers.core.diff.NodePair.getLeftDehydratedPropertyValueAndSanitize(NodePair.java:46)
	at org.javers.core.diff.appenders.MapChangeAppender.calculateChanges(MapChangeAppender.java:50)
	at org.javers.core.diff.appenders.MapChangeAppender.calculateChanges(MapChangeAppender.java:21)
	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:172)
	at org.javers.core.JaversDiffE2ETest.should report when a list property is added or removed(JaversDiffE2ETest.groovy:603)
kucharzyk added a commit to kucharzyk/javers that referenced this issue Jun 19, 2020
kucharzyk added a commit to kucharzyk/javers that referenced this issue Jun 19, 2020
@kucharzyk
Copy link
Contributor Author

@kucharzyk kucharzyk commented Jun 19, 2020

I've submitted two pull requests - one with failing test case and another one with solution

@bartoszwalacik
Copy link
Member

@bartoszwalacik bartoszwalacik commented Jun 19, 2020

nice, could you please merge it and create a single PR?

@kucharzyk
Copy link
Contributor Author

@kucharzyk kucharzyk commented Jun 19, 2020

PR wih fix contains also test case - we can merge it

kucharzyk added a commit to kucharzyk/javers that referenced this issue Jun 19, 2020
@kucharzyk
Copy link
Contributor Author

@kucharzyk kucharzyk commented Jun 19, 2020

I've also squashed it into single commit

@bartoszwalacik
Copy link
Member

@bartoszwalacik bartoszwalacik commented Jun 19, 2020

@kucharzyk thanks for your accurate contribution

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