Drools causes switch(enum e) to break?

classic Classic list List threaded Threaded
9 messages Options
Reply | Threaded
Open this post in threaded view
|

Drools causes switch(enum e) to break?

Leonard93
So I have a really weird problem and I think it could be relate-able to Drools, or maybe not but maybe some people here have seen it before.

I have a simple enum called 'RuleTypes' which is defined in its own file.
I have somewhere in my class a switch statement where I use the enum like this:

(The method is not finished, but its enough to show the problem)

        public IResult EvaluateRule(Object obj, RuleType type)
        {
                //TODO
                switch(type)
                {
                        case Discount :
                                TripRequest lr = (TripRequest) obj;
                                _Session.execute(lr);
                                return lr.getResult();
                        case Content:
                                break;
                        case None:
                                break;
                        default:
                                break;
                }
               
                return null;
        }

But I get an error saying 'Cannot switch on a value of type RuleType. Only convertible int values or enum variables are permitted'. While RuleType an enum is 100% sure.

Yet if I make a new project (with no drools libraries), make the same RuleType enum in its own file and have an empty class doing:

        public Test(RuleType type)
        {
                switch(type)
                {
                        case Discount :
                                break;
                        case Content:
                                break;
                        case None:
                                break;
                        default:
                                break;
                }
        }

There are no compiler errors. Anyone know here what could possibly happen? The only thing I could find was a possible Eclipse bug but that one had a fix that does not work for me ( https://bugs.eclipse.org/bugs/show_bug.cgi?id=413368 ).

Reply | Threaded
Open this post in threaded view
|

Re: [rules-users] Drools causes switch(enum e) to break?

laune
RuleType*s* or RuleType?

Also, you are posting Java code. How is this related to Drools?

Above all, post error messages in full, stating when and due to which
command they are emitted.

-W


On 14/04/2014, Leonard93 <[hidden email]> wrote:

> So I have a really weird problem and I think it could be relate-able to
> Drools, or maybe not but maybe some people here have seen it before.
>
> I have a simple enum called 'RuleTypes' which is defined in its own file.
> I have somewhere in my class a switch statement where I use the enum like
> this:
>
> (The method is not finished, but its enough to show the problem)
>
> public IResult EvaluateRule(Object obj, RuleType type)
> {
> //TODO
> switch(type)
> {
> case Discount :
> TripRequest lr = (TripRequest) obj;
> _Session.execute(lr);
> return lr.getResult();
> case Content:
> break;
> case None:
> break;
> default:
> break;
> }
>
> return null;
> }
>
> But I get an error saying 'Cannot switch on a value of type RuleType. Only
> convertible int values or enum variables are permitted'. While RuleType an
> enum is 100% sure.
>
> Yet if I make a new project (with no drools libraries), make the same
> RuleType enum in its own file and have an empty class doing:
>
> public Test(RuleType type)
> {
> switch(type)
> {
> case Discount :
> break;
> case Content:
> break;
> case None:
> break;
> default:
> break;
> }
> }
>
> There are no compiler errors. Anyone know here what could possibly happen?
> The only thing I could find was a possible Eclipse bug but that one had a
> fix that does not work for me (
> https://bugs.eclipse.org/bugs/show_bug.cgi?id=413368 ).
>
>
>
>
>
> --
> View this message in context:
> http://drools.46999.n3.nabble.com/Drools-causes-switch-enum-e-to-break-tp4029233.html
> Sent from the Drools: User forum mailing list archive at Nabble.com.
> _______________________________________________
> rules-users mailing list
> [hidden email]
> https://lists.jboss.org/mailman/listinfo/rules-users
>
_______________________________________________
rules-users mailing list
[hidden email]
https://lists.jboss.org/mailman/listinfo/rules-users
Reply | Threaded
Open this post in threaded view
|

Re: [rules-users] Drools causes switch(enum e) to break?

Leonard93
The enum is called RuleType, sorry. I am posting this here because this error only happens within Drools projects, in normal java projects this error does not happen.

The error is "Cannot switch on a value of type RuleType. Only convertible int values or enum variables are permitted" no more, no less. It happens on the switch(type). I don't really know how it can happen but maybe someone here could give some pointers.

Once again, the same switch and enum in a bland java project gives no problems.
Reply | Threaded
Open this post in threaded view
|

Re: [rules-users] Drools causes switch(enum e) to break?

laune
This would mean that setting a project as "Drools project" has an
impact on the compilation of plain old Java code? That would be
an evil bug in some Drools plugin. Posting all the details might
interest the Drools developer group.
-W


On 14/04/2014, Leonard93 <[hidden email]> wrote:

> The enum is called RuleType, sorry. I am posting this here because this
> error
> only happens within Drools projects, in normal java projects this error
> does
> not happen.
>
> The error is /"Cannot switch on a value of type RuleType. Only convertible
> int values or enum variables are permitted"/ no more, no less. It happens
> on
> the *switch(type)*. I don't really know how it can happen but maybe
> someone
> here could give some pointers.
>
> Once again, the same switch and enum in a bland java project gives no
> problems.
>
>
>
>
> --
> View this message in context:
> http://drools.46999.n3.nabble.com/Drools-causes-switch-enum-e-to-break-tp4029233p4029235.html
> Sent from the Drools: User forum mailing list archive at Nabble.com.
> _______________________________________________
> rules-users mailing list
> [hidden email]
> https://lists.jboss.org/mailman/listinfo/rules-users
>
_______________________________________________
rules-users mailing list
[hidden email]
https://lists.jboss.org/mailman/listinfo/rules-users
Reply | Threaded
Open this post in threaded view
|

Re: [rules-users] Drools causes switch(enum e) to break?

Leonard93
This post was updated on .
Well I don't know. It is just a guess that I made since it is the only lead I have on it so far.

What I have tried so far:
-The error happens in Eclipse Kepler and Juno when opening the same drools project.
-A netbeans project with the drools binaries imported (imported the eclipse project, then added binaries manually) works fine with no errors.

So maybe its something within eclipse? Since Netbeans works fine for me now together with Drools.
Reply | Threaded
Open this post in threaded view
|

Re: Drools causes switch(enum e) to break?

SydneyTechHead
This post has NOT been accepted by the mailing list yet.
In reply to this post by Leonard93
I'm seeing exactly the same issue as the OP using Drools 6.0.1.Final in Eclipse Kepler with standard Java project (with Maven nature).  It is described as a "Drools Error" in Eclipse Problems view:

"Cannot switch on a value of type XXX.RowTypes. Only convertible int values or enum variables are permitted"

It appears that Drools 6 is causing Eclipse to reference JRE 1.5 rather than JDK 1.7, which results in the error.  

As with the OP, I also suspect this is Drools-related.  The enum/switch Java code compiles fine in a plain Java project, which is not Drools-enabled.

In fact, when I first created this project yesterday, it was compiling fine when Drools-enabled.  The error arose when I made a few minor changes to the project properties, but once it happens, I'm not able to get the project building again.  The only way I can fix it is to create a new Java project and import source files.  However, making small changes to the project brings the error back and "breaks the project" again.

When the error first arises, I notice that in Project Properties, the Java Compiler Compliance level drops to 1.5 (I set it at 1.7 when creating project) and the JRE System Library on Build Path also drops to JRE 1.5.  However, if I change both back to 1.7, it doesn't fix this error.  I have to create a brand new project to fix it.

Prior to this issue, I have been experiencing another, seemingly, Drools-related, error.  I originally had my Drools Classes/Rules in a Dynamic Web Project, which built and ran fine under Drools 5 libraries.  After upgrading to Drools 6, it was originally working fine but then I start experiencing the enum error above and also "Drools Error - HttpServlet cannot be resolved to a type" for my servlets.  The only way I could resolve these errors was removing the Drools classes/rules from the web project an putting them into a separate Java project.  This started working fine yesterday, then I encountered the enum error above.

I accept that this is probably an Eclipse issue as I can compile the projects fine via command line.  However, there seems to be a compatibility issue with Drools that is causing it.

Let me know if I can supply any further information.  This problem has been frustrating me on an off for the last few weeks!
Reply | Threaded
Open this post in threaded view
|

Re: Drools causes switch(enum e) to break?

SydneyTechHead
I've reproduced this issue with a simple example:

1. Create a new "Drools Project" in Eclipse Kepler with Drools 6.0.1.Final installed (JDK 1.7) with simple "Hello World" rule example.  Project builds OK.

2. Create the following new class:

public class EnumTest {

    private enum EnumType { On, Off }
    private EnumType et = EnumType.On;    
    public EnumTest() {}
   
        public String TypeText()
        {
    switch(et)
    {
    case On:
    return "On";
    case Off:
    return "Off";
    default:
    return "";
    }
        }
}

3. Rebuild project.  Eclipse reports Problem:

Drools Error: "Cannot switch on a value of type EnumTest.EnumType. Only convertible int values or enum variables are permitted"

4. Export Ant Build file for the project and run the Ant Build.  Build successful.

5. Create a vanilla Java Project (no Drools) and add the same EnumTest class.  Eclipse project builds OK.

As the project builds OK via Ant, it appears that this is an issue with the Eclipse incremental builder conflicting with Drools 6.  As noted in my previous post, it appears that Eclipse may be reducing JDK compiler compliance level down to 1.5 or referencing JRE 1.5 in class path as a result of this conflict, as I've occasionally noticed it changing these settings in project properties.

Any ideas or clues why this may be the case and what is the best channel to report this Eclipse issue?  
Reply | Threaded
Open this post in threaded view
|

Re: Drools causes switch(enum e) to break?

SydneyTechHead
I've added this to a similarly reported issue with Eclipse and enums here:

https://bugs.eclipse.org/bugs/show_bug.cgi?id=413368

However, note that the reported issue is happening with vanilla Java projects.  I can compile OK in Eclipse with a standard project - I only have the issue when creating, or converting to, a Drools 6 project.

Any clues as to why Drools may be triggering this issue, or any cached settings I may be able to delete to clean up Eclipse, from the smart folks here will be greatly appreciated.
Reply | Threaded
Open this post in threaded view
|

Re: Drools causes switch(enum e) to break?

shankha
Could you please confirm if you continue to see the errors in Kepler or Mars.
I was able to reproduce the error on Kepler, but I do not see the error now.