[jboss-jira] [JBoss JIRA] Issue Comment Edited: (JBRULES-3215) NPE when calling PackageBuilder.addPackageFromDrl(Reader)
Edson Tirelli (JIRA)
jira-events at lists.jboss.org
Mon Oct 3 11:23:26 EDT 2011
[ https://issues.jboss.org/browse/JBRULES-3215?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12631832#comment-12631832 ]
Edson Tirelli edited comment on JBRULES-3215 at 10/3/11 11:22 AM:
------------------------------------------------------------------
Jean-Marc,
I tried your example with the latest Drools master branch code and it no longer raises a NPE. It now provides an error message:
{code:title=ErrorMessage.txt|borderStyle=solid}
Unable to create reader for 'reference.source':[Error: unable to resolve method using strict-mode: java.lang.Object.source()]
[Near : {... reference.source ....}]
^
[Line: 1, Column: 0] : [Rule name='form-rules.n3 9']
[Error: unable to resolve method using strict-mode: java.lang.Object.source()]
[Near : {... reference.source ....}]
^
[Line: 1, Column: 11]
Rule Compilation error : [Rule name='form-rules.n3 9']
n3_project/helpers3/Rule_form_rules_n3_9.java (30:2567) : $JTEXT_FIELD cannot be resolved
{code}
This happens because Drools 5.2 implemented tighter compile time type checking. Since Assignment.reference is a java.lang.Object, the engine is unable to check that the actual instance in there contains a property named "source".
To disable compile time type checking for the Assignment class you can use a declare statement:
declare Assignment
@typesafe( false )
end
This way Drools will not try to resolve "source" at compile time, but instead will resolve it dynamically at runtime.
I don't have your full code to test your rule above, but with the declare, it does successfully compiles.
was (Author: tirelli):
Jean-Marc,
I tried your example with the latest Drools master branch code and it no longer raises a NPE. It now provides an error message:
Unable to create reader for 'reference.source':[Error: unable to resolve method using strict-mode: java.lang.Object.source()]
[Near : {... reference.source ....}]
^
[Line: 1, Column: 0] : [Rule name='form-rules.n3 9']
[Error: unable to resolve method using strict-mode: java.lang.Object.source()]
[Near : {... reference.source ....}]
^
[Line: 1, Column: 11]
Rule Compilation error : [Rule name='form-rules.n3 9']
n3_project/helpers3/Rule_form_rules_n3_9.java (30:2567) : $JTEXT_FIELD cannot be resolved
This happens because Drools 5.2 implemented tighter compile time type checking. Since Assignment.reference is a java.lang.Object, the engine is unable to check that the actual instance in there contains a property named "source".
To disable compile time type checking for the Assignment class you can use a declare statement:
declare Assignment
@typesafe( false )
end
This way Drools will not try to resolve "source" at compile time, but instead will resolve it dynamically at runtime.
I don't have your full code to test your rule above, but with the declare, it does successfully compiles.
> NPE when calling PackageBuilder.addPackageFromDrl(Reader)
> ---------------------------------------------------------
>
> Key: JBRULES-3215
> URL: https://issues.jboss.org/browse/JBRULES-3215
> Project: Drools
> Issue Type: Bug
> Security Level: Public(Everyone can see)
> Components: drools-core
> Affects Versions: 5.3.0.Beta1
> Environment: % uname -a
> Linux oem-laptop 2.6.32-5-amd64 #1 SMP Fri Sep 9 20:23:16 UTC 2011 x86_64 GNU/Linux
> % java -version
> java version "1.7.0"
> Java(TM) SE Runtime Environment (build 1.7.0-b147)
> Java HotSpot(TM) 64-Bit Server VM (build 21.0-b17, mixed mode)
> Reporter: Jean-Marc Vanel
> Assignee: Edson Tirelli
>
> Daemon Thread [SwingWorker-pool-3-thread-1] (Suspended (breakpoint at line 89 in ClassUtils))
> ClassUtils.canonicalName(Class) line: 89
> DeclarationTypeFixer.fix(Declaration) line: 11
> JavaRuleBuilderHelper.createVariableContext(String, String, RuleBuildContext, Declaration[], Declaration[], Map<String,Class<?>>) line: 158
> JavaRuleBuilderHelper.createConsequenceContext(RuleBuildContext, String, String, String, Map<String,Declaration>, BoundIdentifiers) line: 94
> ASMConsequenceStubBuilder(AbstractASMConsequenceBuilder).consequenceContext(RuleBuildContext, String) line: 47
> ASMConsequenceStubBuilder(AbstractASMConsequenceBuilder).build(RuleBuildContext, String) line: 17
> RuleBuilder.build(RuleBuildContext) line: 99
> PackageBuilder.addRule(RuleDescr) line: 1993
> PackageBuilder.addPackage(PackageDescr) line: 793
> PackageBuilder.addPackageFromDrl(Reader) line: 355
> NOTE: with the debugger, I saw that variable $JTEXT_FIELD is causing the problem; see the DRL below in "how to reproduce"
--
This message is automatically generated by JIRA.
For more information on JIRA, see: http://www.atlassian.com/software/jira
More information about the jboss-jira
mailing list