Skip to content

"error calling Constructor for CustomType" exception when CustomPropertyComparator is registered for value's parent class #789

Closed
@kkonstantin42

Description

@kkonstantin42

error calling Constructor for org.javers.core.metamodel.type.CustomType exception is thrown on javers.compare(..) when there is a CustomPropertyComparator registered for a parent class of some value that exist in objects that are being compared.

Here is a test case that reproduces the issue: https://github.com/kkonstantin42/javers/blob/custom-property-comparator-with-inheritance/javers-core/src/test/groovy/org/javers/core/cases/CustomPropertyComparatorWithInheritanceCase.groovy

This behaviour has appeared after CustomType constructor was changed to accept CustomPropertyComparator as a second parameter in this commit: ec6113b#diff-461b37401e91dc6db100811e06995807
Possibly there should be a special case in TypeFactory.spawnFromPrototype method that would handle creation of CustomType objects. Can submit a PR.

Here is a stacktrace:

java.lang.RuntimeException: error calling Constructor for org.javers.core.metamodel.type.CustomType

	at org.javers.core.metamodel.type.JaversType.spawn(JaversType.java:50)
	at org.javers.core.metamodel.type.TypeFactory.spawnFromPrototype(TypeFactory.java:121)
	at org.javers.core.metamodel.type.TypeFactory.infer(TypeFactory.java:74)
	at org.javers.core.metamodel.type.TypeMapperState.infer(TypeMapperState.java:157)
	at org.javers.core.metamodel.type.TypeMapperState.lambda$getJaversType$0(TypeMapperState.java:89)
	at org.javers.core.metamodel.type.TypeMapperState.computeIfAbsent(TypeMapperState.java:113)
	at org.javers.core.metamodel.type.TypeMapperState.getJaversType(TypeMapperState.java:89)
	at org.javers.core.metamodel.type.TypeMapper.getJaversType(TypeMapper.java:129)
	at org.javers.core.metamodel.type.ManagedClassFactory.lambda$null$2(ManagedClassFactory.java:54)
	at org.javers.core.metamodel.type.JaversProperty.getType(JaversProperty.java:23)
	at org.javers.core.graph.ObjectGraphBuilder.lambda$getSingleReferencesWithManagedTypes$0(ObjectGraphBuilder.java:105)
	at java.util.stream.ReferencePipeline$2$1.accept(ReferencePipeline.java:174)
	at java.util.ArrayList$ArrayListSpliterator.forEachRemaining(ArrayList.java:1382)
	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.positiveFilter(Lists.java:71)
	at org.javers.core.metamodel.type.ManagedClass.getManagedProperties(ManagedClass.java:72)
	at org.javers.core.metamodel.type.ManagedType.getProperties(ManagedType.java:55)
	at org.javers.core.graph.ObjectGraphBuilder.getSingleReferencesWithManagedTypes(ObjectGraphBuilder.java:105)
	at org.javers.core.graph.ObjectGraphBuilder.buildSingleEdges(ObjectGraphBuilder.java:75)
	at org.javers.core.graph.ObjectGraphBuilder.buildEdges(ObjectGraphBuilder.java:70)
	at org.javers.core.graph.ObjectGraphBuilder.buildGraphFromCdo(ObjectGraphBuilder.java:58)
	at org.javers.core.graph.ObjectGraphBuilder.buildGraph(ObjectGraphBuilder.java:47)
	at org.javers.core.graph.LiveGraphFactory.createLiveGraph(LiveGraphFactory.java:39)
	at org.javers.core.diff.DiffFactory.buildGraph(DiffFactory.java:99)
	at org.javers.core.diff.DiffFactory.compare(DiffFactory.java:54)
	at org.javers.core.JaversCore.compare(JaversCore.java:173)
	at org.javers.core.cases.CustomPropertyComparatorWithInheritanceCase.should use CustomPropertyComparator for all subclasses(CustomPropertyComparatorWithInheritanceCase.groovy:65)
Caused by: java.lang.NoSuchMethodException: org.javers.core.metamodel.type.CustomType.<init>(java.lang.reflect.Type)
	at java.lang.Class.getConstructor0(Class.java:3082)
	at java.lang.Class.getConstructor(Class.java:1825)
	at org.javers.core.metamodel.type.JaversType.spawn(JaversType.java:47)
	... 30 more

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions