You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@velocity.apache.org by "Thomas Mortagne (Jira)" <ji...@apache.org> on 2020/01/05 19:26:00 UTC

[jira] [Comment Edited] (VELOCITY-924) Bad cache handling for java.lang.Class methods

    [ https://issues.apache.org/jira/browse/VELOCITY-924?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17008402#comment-17008402 ] 

Thomas Mortagne edited comment on VELOCITY-924 at 1/5/20 7:25 PM:
------------------------------------------------------------------

OK maybe it needs some specific configuration then:
* configuration: https://github.com/xwiki/xwiki-commons/blob/master/xwiki-commons-core/xwiki-commons-velocity/src/main/java/org/xwiki/velocity/internal/DefaultVelocityConfiguration.java#L103
* test case on XWiki side: https://github.com/xwiki/xwiki-commons/blob/master/xwiki-commons-core/xwiki-commons-velocity/src/test/java/org/xwiki/velocity/internal/DefaultVelocityEngineTest.java#L399
* failling test result https://ci.xwiki.org/job/XWiki/job/xwiki-commons/job/master/1025/testReport/junit/org.xwiki.velocity.internal/DefaultVelocityEngineTest/Commons_Builds___main___Build_for_Main___testClassMethods/


was (Author: tmortagne):
OK maybe it needs some specific configuration then:
* configuration: https://github.com/xwiki/xwiki-commons/blob/master/xwiki-commons-core/xwiki-commons-velocity/src/main/java/org/xwiki/velocity/internal/DefaultVelocityConfiguration.java#L103
* test case on XWiki side: https://github.com/xwiki/xwiki-commons/blob/master/xwiki-commons-core/xwiki-commons-velocity/src/test/java/org/xwiki/velocity/internal/DefaultVelocityEngineTest.java#L399
* failing test https://ci.xwiki.org/job/XWiki/job/xwiki-commons/job/master/1025/testReport/junit/org.xwiki.velocity.internal/DefaultVelocityEngineTest/Commons_Builds___main___Build_for_Main___testClassMethods/

> Bad cache handling for java.lang.Class methods
> ----------------------------------------------
>
>                 Key: VELOCITY-924
>                 URL: https://issues.apache.org/jira/browse/VELOCITY-924
>             Project: Velocity
>          Issue Type: Bug
>          Components: Engine
>    Affects Versions: 2.2
>            Reporter: Thomas Mortagne
>            Priority: Blocker
>              Labels: regression
>
> Requirement:
> A binding $var containing an object which class (org.xwiki.MyClass) implementing a {{String getName()}} method.
> The following code:
> {code}
> $var.class.getName()
> $var.getName()
> {code}
> fail with:
> {noformat}
> Caused by: org.apache.velocity.exception.MethodInvocationException: Invocation of method 'getName' in  class org.xwiki.MyClass threw exception java.lang.IllegalArgumentException: object is not an instance of declaring class at mytemplaye[line 1, column 26]
> 	at org.apache.velocity.runtime.parser.node.ASTMethod.handleInvocationException(ASTMethod.java:306)
> 	at org.apache.velocity.runtime.parser.node.ASTMethod.execute(ASTMethod.java:239)
> 	at org.apache.velocity.runtime.parser.node.ASTReference.execute(ASTReference.java:369)
> 	at org.apache.velocity.runtime.parser.node.ASTReference.render(ASTReference.java:490)
> 	at org.apache.velocity.runtime.parser.node.SimpleNode.render(SimpleNode.java:423)
> 	at org.apache.velocity.Template.merge(Template.java:358)
> 	at org.apache.velocity.Template.merge(Template.java:262)
> 	at org.xwiki.velocity.internal.DefaultVelocityEngine.evaluate(DefaultVelocityEngine.java:271)
> 	... 69 more
> Caused by: java.lang.IllegalArgumentException: object is not an instance of declaring class
> 	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
> 	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
> 	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
> 	at java.lang.reflect.Method.invoke(Method.java:498)
> 	at org.apache.velocity.util.introspection.UberspectImpl$VelMethodImpl.doInvoke(UberspectImpl.java:565)
> 	at org.apache.velocity.util.introspection.UberspectImpl$VelMethodImpl.invoke(UberspectImpl.java:548)
> 	at org.apache.velocity.runtime.parser.node.ASTMethod.execute(ASTMethod.java:219)
> 	... 75 more
> {noformat}
> The reason is that ClassUtils.getMethod cache does not make any difference between an instance of Class<org.xwiki.MyClass> and and instance of org.xwiki.MyClass so when ASTMethod#execute ask for the second getName() it end up with Class#getName() instead of MyClass#getName().
> Was working fine in 1.7.



--
This message was sent by Atlassian Jira
(v8.3.4#803005)

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@velocity.apache.org
For additional commands, e-mail: dev-help@velocity.apache.org