AlexisLeite opened a new issue, #7315:
URL: https://github.com/apache/incubator-kie/issues/7315

   ### Describe the bug
   
   ### Description
   
   In Drools 10.2.0, calling `insertLogical` for a fact that is already stated 
can leave a session that the standard protobuf marshaller writes successfully 
but cannot restore. The failure occurs during unmarshalling in 
`ProtobufInputMarshaller.readTruthMaintenanceSystem`.
   
   ### Environment
   
   - Drools 10.2.0
   - OpenJDK 25.0.4.1
   - Maven dependencies `org.drools:drools-engine:10.2.0` and 
`org.drools:drools-serialization-protobuf:10.2.0`
   
   ### Minimal reproducer
   
   Save as `Reproducer.java` and run it with the dependencies above on the 
classpath.
   
   ```java
   import java.io.ByteArrayInputStream;
   import java.io.ByteArrayOutputStream;
   import org.drools.model.codegen.ExecutableModelProject;
   import org.kie.api.KieServices;
   import org.kie.api.conf.EqualityBehaviorOption;
   import org.kie.api.io.ResourceType;
   import org.kie.internal.utils.KieHelper;
   
   class Reproducer {
       public static void main(String[] args) throws Exception {
           var base = new KieHelper().addContent("""
               package repro;
               rule "Logical result"
               when
                   Integer(this == 1)
               then
                   insertLogical("result");
               end
               """, ResourceType.DRL)
               .build(ExecutableModelProject.class, 
EqualityBehaviorOption.EQUALITY);
   
           var marshaller = 
KieServices.Factory.get().getMarshallers().newMarshaller(base);
   
           for (boolean stated : new boolean[]{false, true}) {
               var session = base.newKieSession();
               try {
                   if (stated) {
                       session.insert("result");
                   }
                   session.insert(1);
                   session.fireAllRules();
   
                   var bytes = new ByteArrayOutputStream();
                   marshaller.marshall(bytes, session);
   
                   System.out.println("Marshalling succeeded. stated=" + 
stated);
                   var restored = marshaller.unmarshall(
                       new ByteArrayInputStream(bytes.toByteArray()));
                   try {
                       System.out.println(restored.getObjects());
                   } finally {
                       restored.dispose();
                   }
               } finally {
                   session.dispose();
               }
           }
       }
   }
   ```
   
   ### Actual behavior
   
   - `stated=false` — the session restores and contains `1` and `"result"`.
   - `stated=true` — rule execution and marshalling succeed. Unmarshalling 
throws a `NullPointerException` at 
`ProtobufInputMarshaller.readTruthMaintenanceSystem`, line 534.
   
   In the failing checkpoint, the TMS equality key references a logical fact 
handle missing from the serialized entry point's fact-handle list. The stated 
handle is present.
   
   ### Expected behavior
   
   According to the [Drools 10.2.0 logical insertion 
flowchart](https://kie.apache.org/docs/10.2.x/drools/drools/_images/rule-engine/Logical_Assertion.png),
 a logical insertion should not add a justification when the fact is already 
stated. After `fireAllRules()`, the session should survive a protobuf round 
trip and retain the stated fact.
   
   ### Expected behavior
   
   _No response_
   
   ### Actual behavior
   
   _No response_
   
   ### How to Reproduce?
   
   _No response_
   
   ### Output of `uname -a` or `ver`
   
   _No response_
   
   ### Output of `java -version`
   
   _No response_
   
   ### GraalVM version (if different from Java)
   
   _No response_
   
   ### Kogito version or git rev (or at least Quarkus version if you are using 
Kogito via Quarkus platform BOM)
   
   _No response_
   
   ### Build tool (ie. output of `mvnw --version` or `gradlew --version`)
   
   _No response_
   
   ### Additional information
   
   _No response_


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to