I managed to reproduce the failure again. It appears that the empty declare section is used as a placeholder, because otherwise it is not possible to subclass a POJO that is not in the same package as the new fact type.
So far I am reproducing it in a fairly minimal set of classes, but not a test case yet.
The important elements to reproduce are:
1) The types are declared in a separate package and drl from the rules. If they are in the same package it works. Unfortunately, I need to be able to create separate packages for the rules, so this doesn't help me.
The type name seems to be important, but can't be the only factor. On my production system both the names Drools_root and Drools_applications fails, while in my test case, Drools_root (and Drools_root_applications) work, but Drools_applications still fails. This happens even when the types are reduced to a bare minumum:
The POJO (com/foobar/rules/BaseClass.java):
package com.foobar.rules;
public class BaseClass {
}
The declaration DRL Sample2.drl):
package com.foobar.rules
import com.foobar.rules.BaseClass;
declare Drools_applications extends BaseClass
drools_app_name : String
end
declare Drools_root_applications extends BaseClass
drools_app_name : String
end
The rules DRL (Sample_rules.drl):
package com.sample
rule "R2"
when
$app : com.foobar.rules.Drools_applications( drools_app_name != "" )
then
System.out.println( "rule: R2" );
System.out.println( $app.getDrools_app_name() );
end
rule "R3"
when
$root : com.foobar.rules.Drools_root_applications( drools_app_name != "" )
then
System.out.println( "rule: R3" );
System.out.println( $root.getDrools_app_name() );
end
The code to create the KnowledgeBase:
KnowledgeBuilder kbuilder = KnowledgeBuilderFactory.newKnowledgeBuilder();
kbuilder.add(ResourceFactory.newClassPathResource("Sample2.drl"), ResourceType.DRL);
KnowledgeBase kbase = KnowledgeBaseFactory.newKnowledgeBase();
kbase.addKnowledgePackages(kbuilder.getKnowledgePackages());
KnowledgeBuilder kbuilder2 = KnowledgeBuilderFactory.newKnowledgeBuilder(kbase);
kbuilder2.add(ResourceFactory.newClassPathResource("Sample_rules.drl"), ResourceType.DRL);
// This line may not be necessary
kbase.addKnowledgePackages(kbuilder2.getKnowledgePackages());
The code to trigger the exception
FactType rootType = kbase.getFactType("com.foobar.rules", "Drools_root_applications"); // No exception
Object root = rootType.newInstance();
rootType.set(root, "drools_app_name", "1");
ksession.insert(root);
FactType test2Type = kbase.getFactType("com.foobar.rules", "Drools_applications"); // Exception HERE!!!!!
Object test2 = test2Type.newInstance();
test2Type.set(test2, "drools_app_name", "appName");
ksession.insert(test2);
ksession.fireAllRules();