TimefoldAI / TimefoldAI/timefold-solver
NPE when using entitySelector with sorting and STEP cache type
Open
- Dominant language
- Java
- Stars
- 1.8k
- Forks
- 228
- Avg merge
- 1d 13h
- Merged PRs (30d)
- 46
Description
Describe the bug
Using a sorted entitySelector with cacheType STEP causes a null pointer exception.
Exception in thread "main" java.lang.NullPointerException: Cannot invoke "java.util.List.iterator()" because "this.cachedEntityList" is null
at ai.timefold.solver.core.impl.heuristic.selector.entity.decorator.SortingEntitySelector.iterator(SortingEntitySelector.java:41)
at ai.timefold.solver.core.impl.heuristic.selector.common.iterator.AbstractOriginalChangeIterator.<init>(AbstractOriginalChangeIterator.java:23)
at ai.timefold.solver.core.impl.heuristic.selector.move.generic.ChangeMoveSelector$2.<init>(ChangeMoveSelector.java:101)
at ai.timefold.solver.core.impl.heuristic.selector.move.generic.ChangeMoveSelector.iterator(ChangeMoveSelector.java:101)
at ai.timefold.solver.core.impl.constructionheuristic.placer.PooledEntityPlacer$PooledEntityPlacingIterator.createUpcomingSelection(PooledEntityPlacer.java:30)
at ai.timefold.solver.core.impl.constructionheuristic.placer.PooledEntityPlacer$PooledEntityPlacingIterator.createUpcomingSelection(PooledEntityPlacer.java:23)
at ai.timefold.solver.core.impl.heuristic.selector.common.iterator.UpcomingSelectionIterator.hasNext(UpcomingSelectionIterator.java:27)
at ai.timefold.solver.core.impl.constructionheuristic.DefaultConstructionHeuristicPhase.solve(DefaultConstructionHeuristicPhase.java:45)
at ai.timefold.solver.core.impl.solver.AbstractSolver.runPhases(AbstractSolver.java:83)
at ai.timefold.solver.core.impl.solver.DefaultSolver.solve(DefaultSolver.java:193)
at testschedules.Main.main(Main.java:15)
To Reproduce
-
Clone https://github.com/aioobe/timefold-repro-step-sorted-entities
-
Run with
./gradlew -Dorg.gradle.java.home=/path/to/java17 run
Environment
Timefold Solver Version or Git ref: 1.0.0
Output of java -version:
java version "17.0.7" 2023-04-18 LTS
Java(TM) SE Runtime Environment (build 17.0.7+8-LTS-224)
Java HotSpot(TM) 64-Bit Server VM (build 17.0.7+8-LTS-224, mixed mode, sharing)
Output of uname -a or ver:
Linux xyz 5.15.0-76-generic #83~20.04.1-Ubuntu SMP Wed Jun 21 20:23:31 UTC 2023 x86_64 x86_64 x86_64 GNU/Linux
Additional information
I think the issue is the following:
DefaultConstructionHeuristicPhase.java:45tries to start iterating over the entities- Since cacheType
STEPis used, thecachedEntityListinSortingEntitySelectorhas not been initialized. - The
cachedEntityListwould have been initialized inDefaultConstructionHeuristicPhase.java:47, but that has obviously not been executed yet.
So there's a little chicken and egg situation.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Assessment
This issue has not been assessed yet.