Author: cbrisson
Date: Sun Oct 14 13:33:57 2018
New Revision: 1843836
URL: http://svn.apache.org/viewvc?rev=1843836&view=rev
Log:
[VELOCITY-855] Fix methods caching for references of type Class
Added:
velocity/engine/trunk/velocity-engine-core/src/test/java/org/apache/velocity/test/issues/Velocity855TestCase.java
(with props)
Modified:
velocity/engine/trunk/velocity-engine-core/src/main/java/org/apache/velocity/runtime/parser/node/ASTIdentifier.java
velocity/engine/trunk/velocity-engine-core/src/main/java/org/apache/velocity/util/ClassUtils.java
Modified:
velocity/engine/trunk/velocity-engine-core/src/main/java/org/apache/velocity/runtime/parser/node/ASTIdentifier.java
URL:
http://svn.apache.org/viewvc/velocity/engine/trunk/velocity-engine-core/src/main/java/org/apache/velocity/runtime/parser/node/ASTIdentifier.java?rev=1843836&r1=1843835&r2=1843836&view=diff
==============================================================================
---
velocity/engine/trunk/velocity-engine-core/src/main/java/org/apache/velocity/runtime/parser/node/ASTIdentifier.java
(original)
+++
velocity/engine/trunk/velocity-engine-core/src/main/java/org/apache/velocity/runtime/parser/node/ASTIdentifier.java
Sun Oct 14 13:33:57 2018
@@ -137,6 +137,7 @@ public class ASTIdentifier extends Simpl
*/
IntrospectionCacheData icd = context.icacheGet(this);
+ Class clazz = o instanceof Class ? (Class)o : o.getClass();
/*
* if we have the cache data and the class of the object we are
@@ -145,7 +146,7 @@ public class ASTIdentifier extends Simpl
* that is fixed in the template :)
*/
- if ( icd != null && (o != null) && (icd.contextData ==
o.getClass()) )
+ if ( icd != null && (o != null) && (icd.contextData == clazz) )
{
vg = (VelPropertyGet) icd.thingy;
}
@@ -161,7 +162,7 @@ public class ASTIdentifier extends Simpl
if (vg != null && vg.isCacheable() && (o != null))
{
icd = new IntrospectionCacheData();
- icd.contextData = o.getClass();
+ icd.contextData = clazz;
icd.thingy = vg;
context.icachePut(this,icd);
}
Modified:
velocity/engine/trunk/velocity-engine-core/src/main/java/org/apache/velocity/util/ClassUtils.java
URL:
http://svn.apache.org/viewvc/velocity/engine/trunk/velocity-engine-core/src/main/java/org/apache/velocity/util/ClassUtils.java?rev=1843836&r1=1843835&r2=1843836&view=diff
==============================================================================
---
velocity/engine/trunk/velocity-engine-core/src/main/java/org/apache/velocity/util/ClassUtils.java
(original)
+++
velocity/engine/trunk/velocity-engine-core/src/main/java/org/apache/velocity/util/ClassUtils.java
Sun Oct 14 13:33:57 2018
@@ -181,12 +181,13 @@ public class ClassUtils {
*/
MethodCacheKey mck = new MethodCacheKey(methodName, paramClasses);
IntrospectionCacheData icd = context.icacheGet(mck);
+ Class clazz = o instanceof Class ? (Class)o : o.getClass();
/*
* like ASTIdentifier, if we have cache information, and the Class of
* Object o is the same as that in the cache, we are safe.
*/
- if (icd != null && (o != null && icd.contextData == o.getClass()))
+ if (icd != null && (o != null && icd.contextData == clazz))
{
/*
@@ -205,7 +206,7 @@ public class ClassUtils {
if ((method != null) && (o != null))
{
icd = new IntrospectionCacheData();
- icd.contextData = o.getClass();
+ icd.contextData = clazz;
icd.thingy = method;
context.icachePut(mck, icd);
Added:
velocity/engine/trunk/velocity-engine-core/src/test/java/org/apache/velocity/test/issues/Velocity855TestCase.java
URL:
http://svn.apache.org/viewvc/velocity/engine/trunk/velocity-engine-core/src/test/java/org/apache/velocity/test/issues/Velocity855TestCase.java?rev=1843836&view=auto
==============================================================================
---
velocity/engine/trunk/velocity-engine-core/src/test/java/org/apache/velocity/test/issues/Velocity855TestCase.java
(added)
+++
velocity/engine/trunk/velocity-engine-core/src/test/java/org/apache/velocity/test/issues/Velocity855TestCase.java
Sun Oct 14 13:33:57 2018
@@ -0,0 +1,46 @@
+package org.apache.velocity.test.issues;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+import org.apache.velocity.VelocityContext;
+import org.apache.velocity.test.BaseTestCase;
+
+/**
+ * This class tests VELOCITY-855.
+ */
+public class Velocity855TestCase extends BaseTestCase
+{
+
+ public Velocity855TestCase(String name)
+ {
+ super(name);
+ }
+
+ protected void setUpContext(VelocityContext context)
+ {
+ context.put("elementKind", javax.lang.model.element.ElementKind.class);
+ context.put("typeKind", javax.lang.model.type.TypeKind.class);
+ }
+
+ public void testSpaceBeforeRParen()
+ {
+ assertEvalEquals("ENUM DECLARED", "$elementKind.valueOf('ENUM')
$typeKind.valueOf('DECLARED')");
+ }
+}
Propchange:
velocity/engine/trunk/velocity-engine-core/src/test/java/org/apache/velocity/test/issues/Velocity855TestCase.java
------------------------------------------------------------------------------
svn:executable = *