[jboss-jira] [JBoss JIRA] (DROOLS-383) switch over String in function

Mario Fusco (JIRA) issues at jboss.org
Fri Jan 31 11:01:30 EST 2014


    [ https://issues.jboss.org/browse/DROOLS-383?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12940514#comment-12940514 ] 

Mario Fusco commented on DROOLS-383:
------------------------------------

The problem is not only in functions. It happens exactly the same if you try to use the switch over String directly in a consequence.
That error message is generated by the Eclipse Java Compiler the we are using internally at the moment.
The only way to fix this is to migrate to the native Java compiler that it is something that we have already planned.
This is only a reason more to make this migration asap. 
                
> 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
>         Attachments: 20131219.drools6scratch-switchoverstring.zip
>
>
> *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