TimefoldAI / TimefoldAI/timefold-solver

NPE when using entitySelector with sorting and STEP cache type

Open
#169 9 comments 0 reactions 1 assignee View on GitHub

@triceo is already working on this.

Since Jul 13, 2023.

  • #173 by @triceo — closed without merging
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

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:

  1. DefaultConstructionHeuristicPhase.java:45 tries to start iterating over the entities
  2. Since cacheType STEP is used, the cachedEntityList in SortingEntitySelector has not been initialized.
  3. The cachedEntityList would have been initialized in DefaultConstructionHeuristicPhase.java:47, but that has obviously not been executed yet.

So there's a little chicken and egg situation.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.