Closed swayamraina closed 4 years ago
@benas Is this project under active development/maintenance? What do you think of this issue?
I'm in PTO this week with limited access to internet. I will get back to you asap.
Hi,
While testing out the code, I found that none of the annotations work if one declares the method as
private
and the following error message is returned at runtime.Exception in thread "main" java.lang.IllegalArgumentException: Rule 'XXX' must have at least one public method annotated with 'org.jeasy.rules.annotation.Action'
I think method access should not be a constraint for the rule engine as marking the method as
private
and annotating it means that the dev wants to restrict application level access to the method and only wants the rule-engine to use it.
Hi, the answer can be found of the class RuleDefinitionValidator#getMethods
which can only get the public methods of your rule class ( including inherited methods ). But why NOT rule#getClass()#getDeclaredMethods(excluding inherited methods)
?
because the Rule
is an interface. evaluate
and execute
are both public method.
Also, take a look at BasicRule
. we can extend BasicRule and override the evaluate
and execute
method. if the is one or more private action methods of BasicRule
, how do we organize our Orders
? we should start from Order(1) or Order(2)?
At last , checkout RuleDefinitionValidator#checkActionMethods
& isActionMethodWellDefined
@benas is that TRUE?
@swayamraina
this issue may also help . https://github.com/j-easy/easy-rules/issues/66
@benas did you get the time to look at this?
@swayamraina The reason for that is the following: When you create a POJO with annotations to define a rule, Easy Rules will create a dynamic proxy that implements the Rule
interface, in which the evaluate
/execute
methods are public. So any implementation of the interface must adhere to that contract (it is not possible to restrict visibility in the implementing class).
@zhhaojie What you said is correct. Thank you very much for the follow up on this issue!
Hi,
While testing out the code, I found that none of the annotations work if one declares the method as
private
and the following error message is returned at runtime.I think method access should not be a constraint for the rule engine as marking the method as
private
and annotating it means that the dev wants to restrict application level access to the method and only wants the rule-engine to use it.