Uploaded image for project: 'Drools'
  1. Drools
  2. DROOLS-857

NullPointerException error needs to be improved

XMLWordPrintable

      I am changing around the dinner party example in OptaPlanner and have added a new score rule to the drl:

       rule "sameSleepingPreference"
       	when
       		$leftDesignation : SeatDesignation($leftGuest : guest)
            	$rightDesignation : SeatDesignation(isRightOf($leftDesignation), $rightGuest : guest)
            
                 eval($leftGuest.sleepingPreference.equals($rightGuest.sleepingPreference))
                
          then
              	scoreHolder.addConstraintMatch(kcontext, +1);
       end 
      

      When I run the program with a data sheet of four people, it works fine. However, when I try it with a data sheet of 144 peopIe, I get this null pointer exception:

      2015-07-23 10:41:59,414 [AWT-EventQueue-0] INFO  Opened: data\dinnerparty\unsolved\hannahWeddingTest.xml
      2015-07-23 10:42:01,012 [SwingWorker-pool-4-thread-1] INFO  Solving started: time spent (97), best score (uninitialized/-14400), environment mode (REPRODUCIBLE), random (JDK with seed 0).
      Exception in thread "AWT-EventQueue-0" java.lang.IllegalStateException: Solving failed.
          at org.optaplanner.examples.common.swingui.SolverAndPersistenceFrame$SolveWorker.done(SolverAndPersistenceFrame.java:297)
          at javax.swing.SwingWorker$5.run(Unknown Source)
          at javax.swing.SwingWorker$DoSubmitAccumulativeRunnable.run(Unknown Source)
          at sun.swing.AccumulativeRunnable.run(Unknown Source)
          at javax.swing.SwingWorker$DoSubmitAccumulativeRunnable.actionPerformed(Unknown Source)
          at javax.swing.Timer.fireActionPerformed(Unknown Source)
          at javax.swing.Timer$DoPostEvent.run(Unknown Source)
          at java.awt.event.InvocationEvent.dispatch(Unknown Source)
          at java.awt.EventQueue.dispatchEventImpl(Unknown Source)
          at java.awt.EventQueue.access$300(Unknown Source)
          at java.awt.EventQueue$3.run(Unknown Source)
          at java.awt.EventQueue$3.run(Unknown Source)
          at java.security.AccessController.doPrivileged(Native Method)
          at java.security.ProtectionDomain$1.doIntersectionPrivilege(Unknown Source)
          at java.awt.EventQueue.dispatchEvent(Unknown Source)
          at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)
          at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
          at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
          at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
          at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
          at java.awt.EventDispatchThread.run(Unknown Source)
      Caused by: java.lang.RuntimeException: org.optaplanner.examples.dinnerparty.solver.Rule_sameSleepingPreference1438171934Eval0Invoker@a59a25b3 : java.lang.NullPointerException
          at org.drools.core.rule.EvalCondition.isAllowed(EvalCondition.java:123)
          at org.drools.core.phreak.PhreakEvalNode.doLeftInserts(PhreakEvalNode.java:55)
          at org.drools.core.phreak.PhreakEvalNode.doNode(PhreakEvalNode.java:39)
          at org.drools.core.phreak.RuleNetworkEvaluator.innerEval(RuleNetworkEvaluator.java:342)
          at org.drools.core.phreak.RuleNetworkEvaluator.outerEval(RuleNetworkEvaluator.java:161)
          at org.drools.core.phreak.RuleNetworkEvaluator.evaluateNetwork(RuleNetworkEvaluator.java:116)
          at org.drools.core.phreak.RuleExecutor.reEvaluateNetwork(RuleExecutor.java:231)
          at org.drools.core.phreak.RuleExecutor.evaluateNetworkAndFire(RuleExecutor.java:106)
          at org.drools.core.common.DefaultAgenda.fireNextItem(DefaultAgenda.java:1016)
          at org.drools.core.common.DefaultAgenda.fireAllRules(DefaultAgenda.java:1302)
          at org.drools.core.impl.StatefulKnowledgeSessionImpl.fireAllRules(StatefulKnowledgeSessionImpl.java:1289)
          at org.drools.core.impl.StatefulKnowledgeSessionImpl.fireAllRules(StatefulKnowledgeSessionImpl.java:1262)
          at org.optaplanner.core.impl.score.director.drools.DroolsScoreDirector.calculateScore(DroolsScoreDirector.java:87)
          at org.optaplanner.examples.dinnerparty.solver.solution.initializer.DinnerPartySolutionInitializer.initializeSeatDesignationList(DinnerPartySolutionInitializer.java:69)
          at org.optaplanner.examples.dinnerparty.solver.solution.initializer.DinnerPartySolutionInitializer.changeWorkingSolution(DinnerPartySolutionInitializer.java:41)
          at org.optaplanner.core.impl.phase.custom.DefaultCustomPhase.doStep(DefaultCustomPhase.java:78)
          at org.optaplanner.core.impl.phase.custom.DefaultCustomPhase.solve(DefaultCustomPhase.java:60)
          at org.optaplanner.core.impl.solver.DefaultSolver.runPhases(DefaultSolver.java:213)
          at org.optaplanner.core.impl.solver.DefaultSolver.solve(DefaultSolver.java:176)
          at org.optaplanner.examples.common.business.SolutionBusiness.solve(SolutionBusiness.java:302)
          at org.optaplanner.examples.common.swingui.SolverAndPersistenceFrame$SolveWorker.doInBackground(SolverAndPersistenceFrame.java:286)
          at org.optaplanner.examples.common.swingui.SolverAndPersistenceFrame$SolveWorker.doInBackground(SolverAndPersistenceFrame.java:1)
          at javax.swing.SwingWorker$1.call(Unknown Source)
          at java.util.concurrent.FutureTask.run(Unknown Source)
          at javax.swing.SwingWorker.run(Unknown Source)
          at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
          at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
          at java.lang.Thread.run(Unknown Source)
      Caused by: java.lang.NullPointerException
          at org.optaplanner.examples.dinnerparty.solver.Rule_sameSleepingPreference1438171934.eval0(Rule_sameSleepingPreference1438171934.java:8)
          at org.optaplanner.examples.dinnerparty.solver.Rule_sameSleepingPreference1438171934Eval0InvokerGenerated.evaluate(Unknown Source)
          at org.optaplanner.examples.dinnerparty.solver.Rule_sameSleepingPreference1438171934Eval0Invoker.evaluate(Unknown Source)
          at org.drools.core.rule.EvalCondition.isAllowed(EvalCondition.java:118)
          ... 27 more `
      

      I asked for help on StackOverflow, and Geoffrey, the OptaPlanner creator, told me to report this, as the last nullpointerexception was not specific enough and the error message should be improved.

              mproctor@redhat.com Mark Proctor
              hrose_jira Hannah Rosen (Inactive)
              Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

                Created:
                Updated: