0

Using a List<Optional<PersoonFast>> (where PersoonFast is a proper class) as @ValueRangeProvider, I get the following exception:

Exception in thread "main" java.lang.IllegalArgumentException: The entityClass (class nl.smartinstall.titania.solver.Bezetting) has a PlanningVariable annotated property (persoon) that refers to a ValueRangeProvider annotated member (field private java.util.List nl.smartinstall.titania.solver.PlanningDefault.personen) that returns a parameterized Collection with an unsupported type arguments (java.util.Optional&lt;nl.smartinstall.titania.solver.PersoonFast>).

Optaplanner version 6.3.0.Final accepts this construction and works fine, version 6.4.0.Final throws the exception. Could anyone please explain why the exception is thrown? Is there a workaround?

Geoffrey De Smet
  • 26,223
  • 11
  • 73
  • 120
Stevie
  • 1
  • What's the method signature of `Bezetting.getPersoon()` and that of `PlanningDefault.getPersonen()`? – Geoffrey De Smet Apr 30 '16 at 12:13
  • I 'll need more info to determine if this is a regression bug or not. – Geoffrey De Smet May 03 '16 at 10:55
  • It is 'public Optional getPersoon()'. There's no getter method 'PlanningDefault.getPersonen()'. Adding one (' public List> getPersonen()') and moving the annotation from field to method results in a similar error (referring to the method). – Stevie May 09 '16 at 07:10

1 Answers1

0

I reproduced it locally, this is a confirmed bug and fixed for 7.0.0.Beta1.

That being said (OptaPlanner should support generic types as planning value classes) - I advice against using Optional as a planning value class, due to this warning from IntelliJ:

Reports any uses of java.util.Optional, java.util.OptionalDouble, java.util.OptionalInt, java.util.OptionalLong or com.google.common.base.Optional as the type for a field or a parameter. Optional was designed to provide a limited mechanism for library method return types where there needed to be a clear way to represent "no result". Using a field with type java.util.Optional is also problematic if the class needs to be Serializable, which java.util.Optional is not.

Geoffrey De Smet
  • 26,223
  • 11
  • 73
  • 120