[rules-users] 'From' Compilation Error with Interface Inheritance

Sam Romano samrom3 at gmail.com
Wed Feb 23 10:10:25 EST 2011


Hey Everyone,

I am wondering if anyone is seeing this error I am. We are finally in
the process of upgrading from 5.0.1 to 5.1 final and some of our
existing rules are generating some cryptic error messages during the
KnowledgeBuilder stage.

I was finally able to recreate the error without using our code in a
blank Drools project using Drools 5.1 final, Java 6, so I'll present
the error using that example.

Here is the error message we get on compilation:

Unable to determine the used declarations.
[Error: not a statement, or badly formed structure]
[Near : {... Unknown ....}]
             ^
[Line: 1, Column: 0] : [Rule name='A stand alone rule']
Unable to build expression for 'from' : [Error: Failed to compile: 1
compilation error(s):
 - (1,11) unqualified type in strict mode for: $someObject]
[Near : {... Unknown ....}]
             ^
[Line: 1, Column: 0] 'SomeUtilClass.getSomeObject($someObject)' :
[Rule name='A stand alone rule']

This error only seems to happen within the LHS using the from
conditional element. Here is the rule it is talking about:

rule "A stand alone rule"
	when
		$someObject : SomeClass();
		$returnVal : Object() from SomeUtilClass.getSomeObject($someObject);
	then
		System.out.println("Fired");
end

Here are the definitions of the interfaces and utilities I'm using:

public interface SomeClass extends ClassB {
}
public interface ClassB extends ClassA {
}
public interface ClassA {
}

public class SomeUtilClass
{
  public static Object getSomeObject(ClassA object)
  {
    return null;
  }
}

Some interesting points to make: I can only get this error to occur
with interfaces. If you change SomeClass, ClassB and ClassA to public
class, this error does not occur. Also, interestingly, if you change
the definition of SomeClass to:

public interface SomeClass extends ClassA, ClassB {
}

The compilation errors goes away. However, if you switch the order of
ClassA and ClassB in this declaration, the error comes right back.

Another way I've found to get around this is to cast to ClassA in the
from expression as well, like so:
SomeClass.getSomeObject((ClassA)$someObject);

If you change the method signature for getSomeObject to
getSomeObject(ClassB object), then this also compiles fine.... It
seems that Drools is not picking up interface inheritance for
grandfather interfaces or higher level ancestors.

It almost seems like this is a possible MVEL error, but this error
only happens within the "from" conditional elements. If I put a
similar construct for my method call using an eval such as eval(
SomeUtilClass.getSomeObject($someObject) != null); then it compiles
fine. I tried digging into the MVELDialect, but got lost pretty
quickly.

By the way, this error does not come up in the 5.0.1 or prior
baselines. It does, however, comes up in every version after (5.1,
5.2M1). I've tried switching MVEL to non-strict mode explicitly and
that still did not change the outcome of this. What I don't
understand, obviously, is that the code I'm writing is not invalid
java code, so why is it suddenly failing in the newer versions? Also,
without having to change our code, is there another possible
workaround for this within the Drools or MVEL configurations?

Thanks for any support you can provide on this,

-- 
Sam Romano
(samrom3 at gmail.com)



More information about the rules-users mailing list