Skip to content

Commit

Permalink
[DROOLS-51] fix positional constraint when using a null as value
Browse files Browse the repository at this point in the history
  • Loading branch information
mariofusco committed Feb 22, 2013
1 parent ef4dc90 commit d2249b8
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 1 deletion.
Expand Up @@ -566,7 +566,9 @@ protected void processPositional( final RuleBuildContext context,
return;
}

boolean isSimpleIdentifier = descr.getExpression().matches("[a-zA-Z_\\$][a-zA-Z_\\$0-9]*");
String expr = descr.getExpression();
boolean isSimpleIdentifier = !expr.equals("true") && !expr.equals("false") &&
!expr.equals("null") && expr.matches("[a-zA-Z_\\$][a-zA-Z_\\$0-9]*");

if ( isSimpleIdentifier ) {
// create a binding
Expand Down
28 changes: 28 additions & 0 deletions drools-compiler/src/test/java/org/drools/test/PositionalTest.java
Expand Up @@ -53,4 +53,32 @@ public void testPositional() {

}


@Test(timeout = 5000)
public void testPositionalWithNull() {
// DROOLS-51
String str =
"declare Bean\n" +
" value : String\n" +
"end\n" +
"\n" +
"rule \"Init\"\n" +
"when\n" +
"then\n" +
" insert( new Bean( null ) );\n" +
" insert( \"test\" );\n" +
"end\n" +
"\n" +
"rule \"Bind\"\n" +
"when\n" +
" $s : String( )\n" +
" $b : Bean( null ; )\n" +
"then\n" +
" modify ( $b ) { setValue( $s ); }\n" +
"end";

KnowledgeBase kbase = loadKnowledgeBaseFromString(str);
StatefulKnowledgeSession ksession = kbase.newStatefulKnowledgeSession();
assertEquals(2, ksession.fireAllRules());
}
}

0 comments on commit d2249b8

Please sign in to comment.