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

ConstraintVerifier must not presume the planningId is a Long (regression)

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Done
    • Icon: Critical Critical
    • 8.5.0.Final
    • None
    • optaplanner-test
    • None

      OptaPlanner requires an immutable class for a @PlanningId, such as Long, long, String or UUID. (It can't validate the immutability, but the javadocs says so).

      As of 8.4.0, ConstraintVerifier throws an exception if it's not a Long:

      java.lang.ClassCastException: class java.lang.String cannot be cast to class java.lang.Long (java.lang.String and java.lang.Long are in module java.base of loader 'bootstrap')
      
      	at org.optaplanner.test.impl.score.stream.DefaultSingleConstraintVerification.lambda$assertDistinctPlanningIds$2(DefaultSingleConstraintVerification.java:71)
      	at java.base/java.util.stream.Collectors.lambda$groupingBy$53(Collectors.java:1127)
      	at java.base/java.util.stream.ReduceOps$3ReducingSink.accept(ReduceOps.java:169)
      	at java.base/java.util.ArrayList$ArrayListSpliterator.forEachRemaining(ArrayList.java:1654)
      	at java.base/java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:484)
      	at java.base/java.util.stream.AbstractPipeline.wrapAndCopyInto(AbstractPipeline.java:474)
      	at java.base/java.util.stream.ReduceOps$ReduceOp.evaluateSequential(ReduceOps.java:913)
      	at java.base/java.util.stream.AbstractPipeline.evaluate(AbstractPipeline.java:234)
      	at java.base/java.util.stream.ReferencePipeline.collect(ReferencePipeline.java:578)
      	at org.optaplanner.test.impl.score.stream.DefaultSingleConstraintVerification.lambda$assertDistinctPlanningIds$6(DefaultSingleConstraintVerification.java:70)
      	at java.base/java.util.concurrent.ConcurrentHashMap.forEach(ConcurrentHashMap.java:1603)
      	at org.optaplanner.test.impl.score.stream.DefaultSingleConstraintVerification.assertDistinctPlanningIds(DefaultSingleConstraintVerification.java:62)
      	at org.optaplanner.test.impl.score.stream.DefaultSingleConstraintVerification.given(DefaultSingleConstraintVerification.java:95)
      	at org.optaplanner.test.impl.score.stream.DefaultSingleConstraintVerification.given(DefaultSingleConstraintVerification.java:39)
      

      This needs test coverage (think TDD) and a fix. If the PAM 7.11 branch (8.6.x?) is already branched, the fix needs to be backported to that branch too.

              cchianel Christopher Chianelli (Inactive)
              gdesmet@redhat.com Geoffrey De Smet (Inactive)
              Votes:
              0 Vote for this issue
              Watchers:
              3 Start watching this issue

                Created:
                Updated:
                Resolved: