3

Consider a simple use case for the ExpressionEvaluator class of the Janino library, i.e. when using it to guess the parameters of an expression, as follows:

public static String[] getParameters(String expression) { // Suppress exceptions
    try {
        return ExpressionEvaluator.guessParameterNames(
                new Scanner(null, new StringReader(expression)));
    } catch (Exception e) {
    }

    return null;
}

While the above works very well (100%) for any type of expression I have used it with (including some very obscure ones), if any of the parameters starts with a capital letter, it is omitted.

For example, the expression

aVar + Another

will produce only 1 parameter (aVar) if passed to the above method, whereas the other parameter (Another) is ignored.

Is there any explanation for this behavior (e.g., are variables starting with a capital letter assumed to be class names)?

Most importantly, can the described behavior be bypassed anyhow (e.g., via some configuration option)?


UPDATE

Apparently the limitation is more general and affects all parameters starting with a capital letter. This is a known Janino limitation (or feature), as explained in JANINO-151 and mentioned in a relevant discussion.

Indeed, the source code of the guessParameterNames() method of the Janino ExpressionEvaluator class confirms this.

Seki
  • 11,135
  • 7
  • 46
  • 70
PNS
  • 19,295
  • 32
  • 96
  • 143

0 Answers0