[jboss-jira] [JBoss JIRA] Resolved: (JBRULES-1951) NullPointerException if no package name defined in package files

Edson Tirelli (JIRA) jira-events at lists.jboss.org
Sat Mar 14 12:31:22 EDT 2009


     [ https://jira.jboss.org/jira/browse/JBRULES-1951?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Edson Tirelli resolved JBRULES-1951.
------------------------------------

    Fix Version/s: 5.0.0.GA
       Resolution: Done


Default package name in the java sense, i.e. absence of a namespace, is something we don't want to support because of the several side effects. So, after discussing this issue we decided to support a default namespace that can be changed by using a knowledge builder configuration.

So, any DRL file that does not contain a package name declaration is automatically set to the configured default package name.

To set this option, you can use either the type safe configuration:

        config = KnowledgeBuilderFactory.newKnowledgeBuilderConfiguration();
        config.setOption( DefaultPackageNameOption.get( "org.test" ) );

Or use a property set through the API, system property or configuration file:

        // setting the default pkg name using the string based setProperty() method
        config.setProperty( DefaultPackageNameOption.PROPERTY_NAME,
                            "org.drools" );

Where:

public static final String PROPERTY_NAME = "drools.defaultPackageName";

By default, the package name is:

drools.defaultPackageName = defaultpkg

Thanks for reporting.
Edson

> NullPointerException if no package name defined in package files
> ----------------------------------------------------------------
>
>                 Key: JBRULES-1951
>                 URL: https://jira.jboss.org/jira/browse/JBRULES-1951
>             Project: JBoss Drools
>          Issue Type: Bug
>      Security Level: Public(Everyone can see) 
>          Components: drools-compiler
>    Affects Versions: 5.0.0.M5
>         Environment: All OS Environments
>            Reporter: Shahad Ahmed
>            Assignee: Edson Tirelli
>             Fix For: 5.0.0.GA
>
>
> If you don't define a package name for a rule package then the drools eclipse plugin version 5.0M5 display the following NullPointerException error message against the associated rules files:
>   Error: java.lang.NullPointerException
> For example, if your package is defined in a drl file, or Excel decision table and you haven't defined a package name in the file, or in an associated rules.package file then the error is reported - I've set the plugin to re-parse whenever a resource is changed in the plugin options. Similarly, if you're defining guided rules and haven't defined a package name in a rule.package file then the same NPE error is displayed.
> I've done a bit of debugging and found the NPE is thrown because the package name is still null internally and so the first attempt to use the package name (by JavaDialect.getUniqueLegalName) throws the NPE - a full stacktrace is given below. 
> I've looked into a fix, and it appears as if the code to report a sensible error message has been commented out in org.drools.compiler.PackageBuilder. In the PackageBuilder.addPackage method the first line has a commented out call to method validatePackageName - this entire method has also been commented out. The problem can also be traced back to DroolsEclipsePlugin.getParsedResource, which calls PackageBuilder.addPackage in the first place. This constructs the PackageBuilder using a PackageBuilderConfiguration, which in turn calls this form of the constructor: 
>   PackageBuilder(RuleBase ruleBase, PackageBuilderConfiguration configuration).
> This constructor also has the following comments in it, which hints at some fixes that still need to be added:
>   // FIXME, we need to get drools to support "default" namespace.
>   //this.defaultNamespace = pkg.getName();   
> Note that addPackage does set the package name as the default namespace if the package has no name. However, as can be see from the commented out code above, because the default namespace is never set (i.e. is null) the package name is set to null in the PackageDescr and hence the NPE.
> StackTrace:
> java.lang.NullPointerException
>         at org.drools.rule.builder.dialect.java.JavaDialect.getUniqueLegalName(J
> avaDialect.java:731)
>         at org.drools.rule.builder.dialect.java.JavaDialect.init(JavaDialect.jav
> a:222)
>         at org.drools.rule.builder.RuleBuildContext.<init>(RuleBuildContext.java
> :93)
>         at org.drools.compiler.PackageBuilder.addRule(PackageBuilder.java:1153)
>         at org.drools.compiler.PackageBuilder.addPackage(PackageBuilder.java:633
> )
>         at org.drools.eclipse.DroolsEclipsePlugin.generateParsedResource(Unknown
>  Source)
>         at org.drools.eclipse.DroolsEclipsePlugin.parseBRLResource(Unknown Sourc
> e)
>         at org.drools.eclipse.builder.DroolsBuilder.parseBRLFile(Unknown Source)
>         at org.drools.eclipse.builder.DroolsBuilder.parseResource(Unknown Source
> )
>         at org.drools.eclipse.builder.DroolsBuilder$DroolsBuildVisitor.visit(Unk
> nown Source)
>         at org.eclipse.core.internal.resources.Resource$2.visit(Resource.java:10
> 6)
>         at org.eclipse.core.internal.resources.Resource$1.visitElement(Resource.
> java:58)
>         at org.eclipse.core.internal.watson.ElementTreeIterator.doIteration(Elem
> entTreeIterator.java:81)
>         at org.eclipse.core.internal.watson.ElementTreeIterator.doIteration(Elem
> entTreeIterator.java:85)
>         at org.eclipse.core.internal.watson.ElementTreeIterator.doIteration(Elem
> entTreeIterator.java:85)
>         at org.eclipse.core.internal.watson.ElementTreeIterator.doIteration(Elem
> entTreeIterator.java:85)
>         at org.eclipse.core.internal.watson.ElementTreeIterator.doIteration(Elem
> entTreeIterator.java:85)
>         at org.eclipse.core.internal.watson.ElementTreeIterator.iterate(ElementT
> reeIterator.java:126)
>         at org.eclipse.core.internal.resources.Resource.accept(Resource.java:68)
>         at org.eclipse.core.internal.resources.Resource.accept(Resource.java:104
> )
>         at org.eclipse.core.internal.resources.Resource.accept(Resource.java:88)
>         at org.drools.eclipse.builder.DroolsBuilder.fullBuild(Unknown Source)
>         at org.drools.eclipse.builder.DroolsBuilder.incrementalBuild(Unknown Sou
> rce)
>         at org.drools.eclipse.builder.DroolsBuilder.build(Unknown Source)
>         at org.eclipse.core.internal.events.BuildManager$2.run(BuildManager.java
> :633)
>         at org.eclipse.core.runtime.SafeRunner.run(SafeRunner.java:37)
>         at org.eclipse.core.internal.events.BuildManager.basicBuild(BuildManager
> .java:170)
>         at org.eclipse.core.internal.events.BuildManager.basicBuild(BuildManager
> .java:201)
>         at org.eclipse.core.internal.events.BuildManager$1.run(BuildManager.java
> :253)
>         at org.eclipse.core.runtime.SafeRunner.run(SafeRunner.java:37)
>         at org.eclipse.core.internal.events.BuildManager.basicBuild(BuildManager
> .java:256)
>         at org.eclipse.core.internal.events.BuildManager.basicBuildLoop(BuildMan
> ager.java:309)
>         at org.eclipse.core.internal.events.BuildManager.build(BuildManager.java
> :341)
>         at org.eclipse.core.internal.events.AutoBuildJob.doBuild(AutoBuildJob.ja
> va:140)
>         at org.eclipse.core.internal.events.AutoBuildJob.run(AutoBuildJob.java:2
> 38)
>         at org.eclipse.core.internal.jobs.Worker.run(Worker.java:55)

-- 
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators: https://jira.jboss.org/jira/secure/Administrators.jspa
-
For more information on JIRA, see: http://www.atlassian.com/software/jira

        



More information about the jboss-jira mailing list