[jboss-jira] [JBoss JIRA] (DROOLS-383) switch over String in function
Matteo Mortari (JIRA)
issues at jboss.org
Thu Dec 19 05:20:33 EST 2013
Matteo Mortari created DROOLS-383:
-------------------------------------
Summary: switch over String in function
Key: DROOLS-383
URL: https://issues.jboss.org/browse/DROOLS-383
Project: Drools
Issue Type: Bug
Security Level: Public (Everyone can see)
Affects Versions: 6.0.0.Final
Reporter: Matteo Mortari
Assignee: Mark Proctor
*Executive Summary*: if I try to implement switch over String as per Java 1.7, inside of DRL function, compilation of DRL fails, but the error message would suggest that actually switch over String should work.
*Steps to reproduce*
Have a DRL file with function with String parameter and inside the function a switch over the parameter, for example
{code:title=acme.drl|borderStyle=solid}
rule "Stupid rule over String"
when
String()
then
System.out.println("Hello world");
end
function void theTest(String input) {
switch(input) {
case "Hello World" :
System.out.println("yep");
break;
default :
System.out.println("uh");
break;
}
}
{code}
Have simple code to compile DRL for default KieBase, for example snippet:
{code:title=App.java|borderStyle=solid}
String input = "Hello World";
// Java 1.7
switch(input) {
case "Hello World" :
System.out.println("yep");
break;
default :
System.out.println("uh");
break;
}
System.out.println( "Hello World!" );
KieServices ks = KieServices.Factory.get();
KieContainer kContainer = ks.getKieClasspathContainer();
KieBase kieBase = kContainer.getKieBase();
for ( KiePackage kp : kieBase.getKiePackages() ) {
for (Rule rule : kp.getRules()) {
System.out.println("kp" + kp + " rule " + rule.getName());
}
}
{code}
Console would log DRL compile fails with error:
{noformat}
Exception in thread "main" java.lang.RuntimeException: Error while creating KieBase[Message [id=1, level=ERROR, path=acme.drl, line=-1, column=0
text=Error importing : 'defaultpkg.TheTest.theTest'], Message [id=2, level=ERROR, path=acme.drl, line=8, column=0
text=[ function theTesttheTest (line:8): Cannot switch on a value of type String. Only convertible int values, strings or enum constants are permitted
]], Message [id=3, level=ERROR, path=acme.drl, line=1, column=0
text=Rule Compilation error The import defaultpkg.TheTest cannot be resolved]]
{noformat}
Please notice the 'strings' bit in the error message : {{Cannot switch on a value of type String. Only convertible int values, *strings* or enum constants are permitted}}
Therefore would suggest it would compile a switch over String, but for some reason it is failing to recognize that input parameter is indeed a String?
Thank you
Ciao
MM
--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators
For more information on JIRA, see: http://www.atlassian.com/software/jira
More information about the jboss-jira
mailing list