Uploaded image for project: 'JBRULES'
  1. JBRULES
  2. JBRULES-3622

Improve the error message for the ClassCastException when Using interval-based Temporal Operators with timestamps

    Details

    • Type: Bug
    • Status: Open (View Workflow)
    • Priority: Minor
    • Resolution: Unresolved
    • Affects Version/s: 5.4.0.Final
    • Fix Version/s: None
    • Component/s: drools-core (expert)
    • Labels:
      None

      Description

      When trying to determine if two dates overlap using the "overlappedby" keyword with parameters in a rule, Drools throws a ClassCastException. If I use another temporal keyword such as "coincides" with parameters, the rule works as expected. I am using a StatefulKnowledgeSession and this occurs after I insert facts into the session. The facts I insert are of a different type than TimeBoxedFact. The LHS is as follows:

            $encD : TimeBoxedFact(yearRecorded == durationCycleYear  )
            $encN : TimeBoxedFact( ID != $encD.ID,   datetimeRecorded overlappedby[1ms,90d] $encD.datetimeRecorded )
      

      durationCycleYear is a global Integer equal to the four digit year (e.g. 2012 or 1998; declared as follows "global Integer durationCycleYear;")

      Here is what the TimeBoxedFact object looks like:

      package com.company;
      
      import java.io.Serializable;
      import java.sql.Timestamp;
      
      public class TimeBoxedFact implements Serializable{
      
          protected Timestamp datetime = null;
          protected int ID;
          private static final long serialVersionUID = -7640003804511140444L;
      
          
          public int getID() {
              return this.ID;
          }
          
          public void setID(int id) {
              this.ID = id;
          } 
      
          public Timestamp getDatetimeRecorded() {
              return this.datetime;
          }
          public java.util.Date getDateRecorded(){
              return new java.util.Date(this.datetime.getTime());
          }
          public int getYearRecorded(){
              return calendarDateRecorded.get(Calendar.YEAR);
          }
      
          
          public void setDatetimeRecorded(Timestamp dt) {
              this.datetime = dt;
      
              //create the calendar object
              calendarDateRecorded = Calendar.getInstance();
              calendarDateRecorded.setTimeInMillis(datetime.getTime());
          } 
      
      }
      

      The stack trace is as follows:

      java.lang.ClassCastException: org.drools.common.DefaultFactHandle cannot be cast to com.company.TimeBoxedFact
      	at org.drools.base.com.company.TimeBoxedFact1639733674$getDatetimeRecorded.getValue(Unknown Source)
      	at org.drools.base.extractors.BaseObjectClassFieldReader.isNullValue(BaseObjectClassFieldReader.java:179)
      	at org.drools.base.ClassFieldReader.isNullValue(ClassFieldReader.java:179)
      	at org.drools.rule.VariableRestriction$ObjectVariableContextEntry.updateFromTuple(VariableRestriction.java:327)
      	at org.drools.common.DoubleBetaConstraints.updateFromTuple(DoubleBetaConstraints.java:137)
      	at org.drools.reteoo.JoinNode.assertLeftTuple(JoinNode.java:84)
      	at org.drools.reteoo.SingleLeftTupleSinkAdapter.doPropagateAssertLeftTuple(SingleLeftTupleSinkAdapter.java:196)
      	at org.drools.reteoo.SingleLeftTupleSinkAdapter.propagateAssertLeftTuple(SingleLeftTupleSinkAdapter.java:71)
      	at org.drools.reteoo.JoinNode.assertLeftTuple(JoinNode.java:98)
      	at org.drools.reteoo.SingleLeftTupleSinkAdapter.doPropagateAssertLeftTuple(SingleLeftTupleSinkAdapter.java:196)
      	at org.drools.reteoo.SingleLeftTupleSinkAdapter.createAndPropagateAssertLeftTuple(SingleLeftTupleSinkAdapter.java:145)
      	at org.drools.reteoo.LeftInputAdapterNode.assertObject(LeftInputAdapterNode.java:154)
      	at org.drools.reteoo.CompositeObjectSinkAdapter.doPropagateAssertObject(CompositeObjectSinkAdapter.java:497)
      	at org.drools.reteoo.CompositeObjectSinkAdapter.propagateAssertObject(CompositeObjectSinkAdapter.java:382)
      	at org.drools.reteoo.CompositeObjectSinkAdapter.propagateAssertObject(CompositeObjectSinkAdapter.java:364)
      	at org.drools.reteoo.ObjectTypeNode.assertObject(ObjectTypeNode.java:235)
      	at org.drools.reteoo.EntryPointNode.assertObject(EntryPointNode.java:240)
      	at org.drools.common.NamedEntryPoint.insert(NamedEntryPoint.java:337)
      	at org.drools.common.NamedEntryPoint.insert(NamedEntryPoint.java:298)
      	at org.drools.common.AbstractWorkingMemory.insert(AbstractWorkingMemory.java:888)
      	at org.drools.common.AbstractWorkingMemory.insert(AbstractWorkingMemory.java:847)
      	at org.drools.impl.StatefulKnowledgeSessionImpl.insert(StatefulKnowledgeSessionImpl.java:269)
      	at com.company.RulesRunner.persistAndInsertBRE(RulesRunner.java:267)
      	at com.company.RulesRunner.runRules(RulesRunner.java:249)
      	at com.company.testProtocol_0_In90Days(Test025.java:205)
      	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
      	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
      	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
      	at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:44)
      	at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:15)
      	at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:41)
      	at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:20)
      	at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:28)
      	at org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:31)
      	at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:76)
      	at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:50)
      	at org.junit.runners.ParentRunner$3.run(ParentRunner.java:193)
      	at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:52)
      	at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:191)
      	at org.junit.runners.ParentRunner.access$000(ParentRunner.java:42)
      	at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:184)
      	at org.junit.runners.ParentRunner.run(ParentRunner.java:236)
      	at org.junit.runner.JUnitCore.run(JUnitCore.java:157)
      	at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:76)
      	at com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:195)
      	at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:63)
      	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
      	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
      	at com.intellij.rt.execution.application.AppMain.main(AppMain.java:120)
      

        Gliffy Diagrams

          Attachments

            Activity

              People

              • Assignee:
                mark.proctor Mark Proctor
                Reporter:
                julian_k Julian Klein
              • Votes:
                0 Vote for this issue
                Watchers:
                2 Start watching this issue

                Dates

                • Created:
                  Updated: