Usually a DRL file defines a package. Java classes declared to be in a package with the same name are accessible in the DRL, without an import. This is also true for classes with package visibility.
However, evaluation of constraints using fields from classes with package visibility only fails at runtime. A couple of stack dumps are shown below.
I'm not sure what the intended behaviour is, but if runtime execution is not possible, compilation ought to fail since the reason is known at compile time.
-W
Exception in thread "main" java.lang.IllegalAccessError: tried to access class anno.AnnIntRange from class org.drools.base.anno.AnnIntRange21716810$getAnnotation
at org.drools.base.anno.AnnIntRange21716810$getAnnotation.getValue(Unknown Source)
at org.drools.base.ClassFieldReader.getValue(ClassFieldReader.java:86)
at org.drools.rule.Declaration.getValue(Declaration.java:219)
at anno.Rule_ChkIntRange_0Eval1Invoker.evaluate(Rule_ChkIntRange_0Eval1Invoker.java:16)
at org.drools.rule.EvalCondition.isAllowed(EvalCondition.java:114)
at org.drools.reteoo.EvalConditionNode.assertLeftTuple(EvalConditionNode.java:173)
at org.drools.reteoo.SingleLeftTupleSinkAdapter.doPropagateAssertLeftTuple(SingleLeftTupleSinkAdapter.java:197)
at org.drools.reteoo.SingleLeftTupleSinkAdapter.propagateAssertLeftTuple(SingleLeftTupleSinkAdapter.java:72)
at org.drools.reteoo.JoinNode.assertLeftTuple(JoinNode.java:101)
at org.drools.reteoo.SingleLeftTupleSinkAdapter.doPropagateAssertLeftTuple(SingleLeftTupleSinkAdapter.java:197)
at org.drools.reteoo.SingleLeftTupleSinkAdapter.createAndPropagateAssertLeftTuple(SingleLeftTupleSinkAdapter.java:146)
at org.drools.reteoo.LeftInputAdapterNode.assertObject(LeftInputAdapterNode.java:154)
at org.drools.reteoo.SingleObjectSinkAdapter.propagateAssertObject(SingleObjectSinkAdapter.java:59)
at org.drools.reteoo.ObjectTypeNode.assertObject(ObjectTypeNode.java:193)
at org.drools.reteoo.EntryPointNode.assertObject(EntryPointNode.java:191)
at org.drools.common.NamedEntryPoint.insert(NamedEntryPoint.java:332)
at org.drools.common.NamedEntryPoint.insert(NamedEntryPoint.java:293)
at org.drools.common.AbstractWorkingMemory.insert(AbstractWorkingMemory.java:905)
at org.drools.common.AbstractWorkingMemory.insert(AbstractWorkingMemory.java:864)
at org.drools.impl.StatefulKnowledgeSessionImpl.insert(StatefulKnowledgeSessionImpl.java:255)
==================================================================
Exception in thread "main" org.drools.RuntimeDroolsException: [Error: could not access field: anno.AnnIntRange.method]
[Near : {... method.declaringClass ....}]
^
[Line: 1, Column: 1]
at org.drools.rule.ReturnValueRestriction.isAllowedCachedRight(ReturnValueRestriction.java:297)
at org.drools.rule.VariableConstraint.isAllowedCachedRight(VariableConstraint.java:121)
at org.drools.common.SingleBetaConstraints.isAllowedCachedRight(SingleBetaConstraints.java:136)
at org.drools.reteoo.JoinNode.assertObject(JoinNode.java:154)
at org.drools.reteoo.SingleObjectSinkAdapter.propagateAssertObject(SingleObjectSinkAdapter.java:59)
at org.drools.reteoo.ObjectTypeNode.assertObject(ObjectTypeNode.java:193)
at org.drools.reteoo.EntryPointNode.assertObject(EntryPointNode.java:191)
at org.drools.common.NamedEntryPoint.insert(NamedEntryPoint.java:332)
at org.drools.common.NamedEntryPoint.insert(NamedEntryPoint.java:293)
at org.drools.common.AbstractWorkingMemory.insert(AbstractWorkingMemory.java:905)
at org.drools.common.AbstractWorkingMemory.insert(AbstractWorkingMemory.java:864)
at org.drools.impl.StatefulKnowledgeSessionImpl.insert(StatefulKnowledgeSessionImpl.java:255)
at anno.Main.insertAnnotations(Main.java:90)
at anno.Main.makeFacts(Main.java:102)
at anno.Main.execute(Main.java:70)
at anno.Main.main(Main.java:119)
Caused by: [Error: could not access field: anno.AnnIntRange.method]
[Near : {... method.declaringClass ....}]
^
[Line: 1, Column: 1]
at org.mvel2.optimizers.impl.refl.ReflectiveAccessorOptimizer.getBeanProperty(ReflectiveAccessorOptimizer.java:550)
at org.mvel2.optimizers.impl.refl.ReflectiveAccessorOptimizer.compileGetChain(ReflectiveAccessorOptimizer.java:336)
at org.mvel2.optimizers.impl.refl.ReflectiveAccessorOptimizer.optimizeAccessor(ReflectiveAccessorOptimizer.java:141)
at org.mvel2.optimizers.dynamic.DynamicOptimizer.optimizeAccessor(DynamicOptimizer.java:67)
at org.mvel2.ast.ASTNode.optimize(ASTNode.java:161)
at org.mvel2.ast.ASTNode.getReducedValueAccelerated(ASTNode.java:117)
at org.mvel2.MVELRuntime.execute(MVELRuntime.java:89)
at org.mvel2.compiler.CompiledExpression.getValue(CompiledExpression.java:125)
at org.mvel2.compiler.CompiledExpression.getValue(CompiledExpression.java:118)
at org.mvel2.MVEL.executeExpression(MVEL.java:952)
at org.drools.base.extractors.MVELClassFieldReader.getValue(MVELClassFieldReader.java:153)
at org.drools.base.evaluators.EqualityEvaluatorsDefinition$ObjectEqualEvaluator.evaluate(EqualityEvaluatorsDefinition.java:1671)
at org.drools.rule.ReturnValueRestriction.isAllowedCachedRight(ReturnValueRestriction.java:292)
... 15 more