Skip to content

Commit

Permalink
BZ-1019473: checking for null matches to avoid NPE on 'from' node
Browse files Browse the repository at this point in the history
  • Loading branch information
etirelli committed Oct 18, 2013
1 parent 315cc8f commit affb4e3
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 2 deletions.
Expand Up @@ -19,6 +19,7 @@
import org.drools.compiler.Address;
import org.drools.compiler.Cheese;
import org.drools.compiler.CommonTestMethodBase;
import org.drools.compiler.Message;
import org.drools.compiler.Person;
import org.drools.core.ClassObjectFilter;
import org.drools.core.RuleBaseConfiguration;
Expand Down Expand Up @@ -146,6 +147,43 @@ public void testUpdateWithNonEffectiveActivations() throws Exception {
ksession.dispose();
}

@Test
public void testNPEOnMutableGlobal() throws Exception {
// BZ-1019473
String str = "package org.drools.compiler\n" +
"global java.util.List context\n" +
"rule B\n" +
" when\n" +
" Message( message == \"b\" )\n" +
" $s : String() from context\n" +
" then\n" +
" System.out.println($s);\n" +
"end";

KieServices ks = KieServices.Factory.get();
KieFileSystem kfs = ks.newKieFileSystem();
kfs.write(ResourceFactory.newByteArrayResource(str.getBytes()).setTargetPath("org/drools/compiler/rules.drl") );

KieBuilder kbuilder = KieServices.Factory.get().newKieBuilder(kfs);
kbuilder.buildAll();

assertEquals(0, kbuilder.getResults().getMessages().size());

ks.newKieContainer(kbuilder.getKieModule().getReleaseId()).getKieBase();
KieSession ksession = ks.newKieContainer(kbuilder.getKieModule().getReleaseId()).newKieSession();
assertNotNull( ksession );

List<String> context = new ArrayList<String>();
ksession.setGlobal("context", context);

FactHandle b = ksession.insert( new Message( "b" ) );
ksession.delete(b);
int fired = ksession.fireAllRules(1);

assertEquals( 0, fired );
ksession.dispose();
}

@Test
public void testClassNotFoundAfterDeserialization() throws Exception {
// JBRULES-3670
Expand Down
Expand Up @@ -254,8 +254,12 @@ public void doLeftDeletes(FromNode fromNode,
}


// @TODO (mdp) is this really necessary? won't the entire FH and RightTuple chaines just et GC'd?
unlinkCreatedHandles(leftTuple);
// if matches == null, the deletion might be happening before the fact was even propagated. See BZ-1019473 for details.
if( matches != null ) {

// @TODO (mdp) is this really necessary? won't the entire FH and RightTuple chaines just et GC'd?
unlinkCreatedHandles(leftTuple);
}

leftTuple.clearStaged();
leftTuple = next;
Expand Down

0 comments on commit affb4e3

Please sign in to comment.