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

getOldObject() of ObjectUpdatedEvent is returning same value as getObject()

    XMLWordPrintable

Details

    • Bug
    • Resolution: Not a Bug
    • Optional
    • None
    • 7.16.0.Final
    • core engine
    • None
    • 2019 Week 29-31
    • Hide

      Create a fact file

      public class TestFact {
        private String testString;
        public String getTestString() {return testString;}
        public void setTestString(String testString) {this.testString = testString;}
        @Override public String toString() {return testString;}
      }
      

      Create a test.drl file

      when
        $test : TestFact(testString == "input")
      then
        $test.setTestString("output");
        update($test);
      

      Create a Listener

      public class TestRuntimeListener implements org.kie.api.event.rule.RuleRuntimeEventListener {
        @Override public void objectDeleted(final ObjectDeletedEvent event) {}
        @Override public void objectInserted(final ObjectInsertedEvent event) {}
        @Override public void objectUpdated(final ObjectUpdatedEvent event) {
          System.out.println("Old and New are the same? " + event.getOldObject() == event.getObject());
          System.out.println("Old value=" + even event.getOldObject());
          System.out.println("New value=" + even event.getObject());
        }
      }
      

      Execute

      org.kie.api.runtime.KieSession kSession = [Initialize KieSession]
      kSession.addEventListener(new TestRuntimeListener());
      TestFact fact = new TestFact;
      fact.setString("input");
      kSession.insert(fact);
      kSession.fireAllRules();
      

      Expected Output

      Old and New are the same? false
      Old value=input
      New value=output
      

      Actual output

      Old and New are the same? true
      Old value=output
      New value=output
      
      Show
      Create a fact file public class TestFact { private String testString; public String getTestString() { return testString;} public void setTestString( String testString) { this .testString = testString;} @Override public String toString() { return testString;} } Create a test.drl file when $test : TestFact(testString == "input" ) then $test.setTestString( "output" ); update($test); Create a Listener public class TestRuntimeListener implements org.kie.api.event.rule.RuleRuntimeEventListener { @Override public void objectDeleted( final ObjectDeletedEvent event) {} @Override public void objectInserted( final ObjectInsertedEvent event) {} @Override public void objectUpdated( final ObjectUpdatedEvent event) { System .out.println( "Old and New are the same? " + event.getOldObject() == event.getObject()); System .out.println( "Old value=" + even event.getOldObject()); System .out.println( "New value=" + even event.getObject()); } } Execute org.kie.api.runtime.KieSession kSession = [Initialize KieSession] kSession.addEventListener( new TestRuntimeListener()); TestFact fact = new TestFact; fact.setString( "input" ); kSession.insert(fact); kSession.fireAllRules(); Expected Output Old and New are the same? false Old value=input New value=output Actual output Old and New are the same? true Old value=output New value=output
    • NEW
    • NEW
    • Dark-Wynd

    Description

      We have built a logger file for our rules that implements org.kie.api.event.rule.RuleRuntimeEventListener.

      Whenever the objectUpdated(ObjectUpdatedEvent) method is called, the ObjectUpdatedEvent contains the values of both the old Object and new object (or getOldObject() and getObject() )

      However, it seems that getOldObject() is always returning the same value as getObject().

      Having both values would be very helpful in debugging rules.

      Attachments

        Activity

          People

            mfusco@redhat.com Mario Fusco
            dark-wynd Benoit Proulx (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: