Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Support of static functions with varargs #11

Open
ishegelman opened this issue Mar 13, 2023 · 0 comments
Open

Support of static functions with varargs #11

ishegelman opened this issue Mar 13, 2023 · 0 comments

Comments

@ishegelman
Copy link

Expression Language API allows one to use a FunctionMapper to register a static function mapped to a Method. For example, ${str:format(...)} could be mapped to String.format() function.

However, this does not work for methods with varargs. Thus, evaluation of ${str:format('%s%s', 'a', 'b')} fails with:

jakarta.el.ELException: Function 'str:format' specifies 2 params, but 3 were supplied

	at org.glassfish.expressly.lang.ExpressionBuilder.visit(ExpressionBuilder.java:244)
	at org.glassfish.expressly.parser.SimpleNode.accept(SimpleNode.java:157)
	at org.glassfish.expressly.lang.ExpressionBuilder.prepare(ExpressionBuilder.java:195)
	at org.glassfish.expressly.lang.ExpressionBuilder.build(ExpressionBuilder.java:206)
	at org.glassfish.expressly.lang.ExpressionBuilder.createValueExpression(ExpressionBuilder.java:255)
	at org.glassfish.expressly.ExpressionFactoryImpl.createValueExpression(ExpressionFactoryImpl.java:95)

By contrast, varargs methods are supported for Java Beans. If "str" was registered as a String bean, then the following expression would work (note the '.' instead of the ':'): ${str.format('%s%s', 'a', 'b')}.

There are two issues in expressly code:

  1. org.glassfish.expressly.parser.AstFunction.getValue() contains a loop that coerces function arguments to the proper method parameter data types. This loop does not handle varargs. Instead, you may consider using jakarta.el.ELUtil.buildParameters() which does support varargs.
  2. org.glassfish.expressly.lang.ExpressionBuilder.visit() compares the number of provided function arguments to the number of parameters of the method implementing this function. This logic does not consider variable number of arguments for varargs methods.
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant