[rules-dev] possible bug, NPE in PackageBuilder.java

Zoltan Farkas zoly at daxtechnologies.com
Mon Dec 22 09:42:35 EST 2008


Here is a unit test you can add to PackageBuilderTest:
 
    public void testAddPackage() throws IOException {
 
        KnowledgeBuilder kbuilder =
KnowledgeBuilderFactory.newKnowledgeBuilder();
 
kbuilder.add(ResourceFactory.newInputStreamResource(this.getClass().getR
esourceAsStream("mortgages_TEST.pkg")),
                ResourceType.PKG);
 
        KnowledgeBase kbase = KnowledgeBaseFactory.newKnowledgeBase();
        kbase.addKnowledgePackages(kbuilder.getKnowledgePackages());
        StatefulKnowledgeSession session =
kbase.newStatefulKnowledgeSession();
    }
 
 
The unit test uses the mortgages_TEST from guvnor, you need to add
mortgages_TEST.pkg to 
src/test/resources/org.drools.compiler. I have attached the mortgages
test pkg to this email.
 
regards
 
--zoly
 

________________________________

From: rules-dev-bounces at lists.jboss.org
[mailto:rules-dev-bounces at lists.jboss.org] On Behalf Of Mark Proctor
Sent: Monday, December 22, 2008 6:22 AM
To: Rules Dev List
Subject: Re: [rules-dev] possible bug, NPE in PackageBuilder.java


Try changing the code to this, let me know if it fixes the problem and
I'll apply to trunk. any chance you could send us a mini self contained
unit test for this bug?

    public synchronized void addPackage(final Package newPkg) {
        PackageRegistry pkgRegistry = this.pkgRegistryMap.get(
newPkg.getName() );
        Package pkg = null;
        if ( pkgRegistry != null ) {
            pkg = pkgRegistry.getPackage();
        }

        if ( pkg == null ) {
            pkg = newPackage( new PackageDescr( newPkg.getName() )
).getPackage();
        }

Zoltan Farkas wrote: 

	PackageBuilder.java at line 688:
	 
	    public synchronized void addPackage(final Package newPkg) {
	            Package pkg = this.pkgRegistryMap.get(
newPkg.getName() ).getPackage();
	
	 
	if pkgRegistryMap is empty as it should probably be initially
adding a new package will cause a NPE.
	This fuction assumes that there is always a package in the
packageRegistryMap.
	 
	I am getting a NPE when I am trying something like:
	 
	                KnowledgeBuilder kbuilder =
KnowledgeBuilderFactory.newKnowledgeBuilder();
	                kbuilder.add(ResourceFactory.newUrlResource("a
valid url"),
	                        ResourceType.PKG);
	 
	thanks for any help
	 
	--zoly
	
________________________________


	_______________________________________________
	rules-dev mailing list
	rules-dev at lists.jboss.org
	https://lists.jboss.org/mailman/listinfo/rules-dev
	  


-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.jboss.org/pipermail/rules-dev/attachments/20081222/cc7d565a/attachment.html 
-------------- next part --------------
A non-text attachment was scrubbed...
Name: mortgages_TEST.pkg
Type: application/octet-stream
Size: 18557 bytes
Desc: mortgages_TEST.pkg
Url : http://lists.jboss.org/pipermail/rules-dev/attachments/20081222/cc7d565a/attachment.obj 


More information about the rules-dev mailing list