Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Retracted Objects remain in drools working memory event after retracting them #6264

Open
hardikisc opened this issue Feb 25, 2025 · 1 comment

Comments

@hardikisc
Copy link

Hi,

Step -1 We are creating kieSession using below code:

final Resource resource = ResourceFactory.newFileResource(drlFile);
final KnowledgeBuilderConfiguration kConfig = KnowledgeBuilderFactory.newKnowledgeBuilderConfiguration();
kConfig.setOption(PropertySpecificOption.DISABLED);
final KnowledgeBuilder kBuilder = KnowledgeBuilderFactory.newKnowledgeBuilder(kConfig);
kBuilder.add(resource, ResourceType.DRL);
kbase=kBuilder.newKieBase();
KieSession ksession=kbase.newKieSession();

Step -2 We fire all the rules using fireAllRules Method like so:

int thisIterNumRulesFired = ksession.fireAllRules();

Step -3 Then after firing all the rule we are retract all the facts from working memory like so:

Collection<FactHandle> factHandles = ksession.getFactHandles();
List<FactHandle> handlesToRetract = new ArrayList<>(factHandles);
for (FactHandle handle : handlesToRetract) {
ksession.retract(handle);
}

Step -4 After this, We are logging how many object remain in drools working memory:

log.info("After deleted: " + ksession.getObjects().stream().toList());

Then we are repeating steps from step 2 to 4 again and again.
This log always return no facts.

We have declared fact in drl file this is the fact declaration:
declare GtiAssetMessageData
id: String
prefix : String
suffix : String
domesticAssetTy : String
common : String
countryOfTax : Integer
countryOfTaxSub : Boolean
active : Integer
z2 : Integer
z2Sub : Boolean
lu : Integer
luSub : Boolean
issdCapInd : String
interestFreqDayNoTranslated : int
usualPayDates : String
shortDesc : String
longDesc : String
cntryQuote : String
assetIdTy : String
assetId : String
relatedInd : String
relatedAssets : String
earliestNotificationDt : Integer
end

We have rule which creates inserts this fact in drools working memory

// rule values at B39, header at B22
rule "Initialize > Default"
no-loop true
when
state : State(current == "Initialize3")
RuleSet(simulatedSequentialSalience == -14)
then
GtiAssetMessageData gamd = new GtiAssetMessageData();
gamd.setId(decisionTableHelper.getRandomId());
gamd.setCommon("");
gamd.setActive(0);
gamd.setCountryOfTax(0);
gamd.setZ2(0);
gamd.setLu(0);
gamd.setIssdCapInd(" ");
gamd.setUsualPayDates("");
gamd.setShortDesc("");
gamd.setLongDesc("");
gamd.setCountryOfTaxSub(false);
gamd.setLuSub(false);
gamd.setZ2Sub(false);
gamd.setRelatedInd("");
gamd.setRelatedAssets("");
insert(gamd);
decisionTableHelper.log("\nInitialize > Default fired - inserted GtiAssetMessageData with id:"+gamd.getId());
state.setCurrent ("save AssetId");
update (state);
end

This fact always remains in working even though we delete all the facts from working memory.
We are facing this issue in drools version 7.60.0.Final, 7.61.0.Final, 7.62.0.Final with java 17 and java 21. But these drools version work fine with java 11
I have attached all the drools version compatibility testing result in below attached excel

drools_java_version_compatibility.xlsx

@tkobayas
Copy link
Contributor

tkobayas commented Feb 26, 2025

Hi, The latest version is 10.0.0 which requires JDK 17+. Please confirm if your rules work with 10.0.0. If you face the issue with 10.0.0, please share a reproducer (= a simple maven project to reproduce the issue). Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants