Uploaded image for project: 'OptaPlanner'
  1. OptaPlanner
  2. PLANNER-2798

Domain with multiple entities with chained variables fails at runtime with ClassCastException

XMLWordPrintable

    • 2022 Week 35-37 (from Aug 29), 2022 Week 38-40 (from Sept 19), 2022 Week 41-43 (from Oct 10), 2022 Week 44-46 (from Oct 31)
    • NEW
    • NEW

      It can be either a CCE or IllegalArgumentException depending on whether a LambdaBeanPropertyMemberAccessor or ReflectionBeanPropertyMemberAccessor is used internally.

      Stack trace:

      java.lang.IllegalArgumentException: object is not an instance of declaring class
      	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
      	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
      	at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
      	at java.base/java.lang.reflect.Method.invoke(Method.java:566)
      	at org.optaplanner.core.impl.domain.common.accessor.ReflectionBeanPropertyMemberAccessor.executeGetter(ReflectionBeanPropertyMemberAccessor.java:66)
      	at org.optaplanner.core.impl.domain.variable.descriptor.VariableDescriptor.getValue(VariableDescriptor.java:100)
      	at org.optaplanner.core.impl.domain.variable.inverserelation.ExternalizedSingletonInverseVariableSupply.insert(ExternalizedSingletonInverseVariableSupply.java:75)
      	at java.base/java.util.ArrayList.forEach(ArrayList.java:1541)
      	at org.optaplanner.core.impl.domain.solution.descriptor.SolutionDescriptor.lambda$visitAllEntities$9(SolutionDescriptor.java:912)
      	at org.optaplanner.core.impl.domain.solution.descriptor.SolutionDescriptor.visitAllEntities(SolutionDescriptor.java:926)
      	at org.optaplanner.core.impl.domain.solution.descriptor.SolutionDescriptor.visitAllEntities(SolutionDescriptor.java:912)
      	at org.optaplanner.core.impl.domain.variable.inverserelation.ExternalizedSingletonInverseVariableSupply.resetWorkingSolution(ExternalizedSingletonInverseVariableSupply.java:36)
      	at org.optaplanner.core.impl.domain.variable.listener.support.VariableListenerSupport.createSupply(VariableListenerSupport.java:84)
      	at java.base/java.util.HashMap.computeIfAbsent(HashMap.java:1134)
      	at org.optaplanner.core.impl.domain.variable.listener.support.VariableListenerSupport.demand(VariableListenerSupport.java:75)
      	at org.optaplanner.core.impl.heuristic.selector.move.generic.ChangeMoveSelector.solvingStarted(ChangeMoveSelector.java:49)
      	at org.optaplanner.core.impl.phase.event.PhaseLifecycleSupport.fireSolvingStarted(PhaseLifecycleSupport.java:15)
      	at org.optaplanner.core.impl.constructionheuristic.placer.AbstractEntityPlacer.solvingStarted(AbstractEntityPlacer.java:23)
      	at org.optaplanner.core.impl.constructionheuristic.DefaultConstructionHeuristicPhase.solvingStarted(DefaultConstructionHeuristicPhase.java:89)
      	at org.optaplanner.core.impl.solver.AbstractSolver.solvingStarted(AbstractSolver.java:69)
      	at org.optaplanner.core.impl.solver.DefaultSolver.solvingStarted(DefaultSolver.java:225)
      	at org.optaplanner.core.impl.solver.DefaultSolver.solve(DefaultSolver.java:192)
      

      Alternatively, something like:

      java.lang.ClassCastException: class org.optaplanner.core.impl.testdata.domain.chained.multivar.TestdataTaxiPlace cannot be cast to class org.optaplanner.core.impl.testdata.domain.chained.multivar.TestdataAirport (org.optaplanner.core.impl.testdata.domain.chained.multivar.TestdataTaxiPlace and org.optaplanner.core.impl.testdata.domain.chained.multivar.TestdataAirport are in unnamed module of loader 'app')
      
      	at org.optaplanner.core.impl.domain.common.accessor.LambdaBeanPropertyMemberAccessor.executeGetter(LambdaBeanPropertyMemberAccessor.java:121)
      	at org.optaplanner.core.impl.domain.variable.descriptor.VariableDescriptor.getValue(VariableDescriptor.java:100)
              ...
      

      Original reproducer: https://github.com/Christopher-Chianelli/issue-reproducer/tree/multiple-planning-entities-chained
      based on SO: https://stackoverflow.com/questions/73597412/inheritance-of-optapy-planning-entitiy-classes

              jlocker Jiří Locker (Inactive)
              jlocker Jiří Locker (Inactive)
              Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

                Created:
                Updated:
                Resolved: