You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tapestry.apache.org by hl...@apache.org on 2010/08/19 23:49:49 UTC

svn commit: r987325 - in /tapestry/tapestry5/trunk/tapestry-core/src: main/java/org/apache/tapestry5/internal/services/ test/app1/ test/groovy/org/apache/tapestry5/integration/app1/ test/java/org/apache/tapestry5/integration/app1/data/ test/java/org/ap...

Author: hlship
Date: Thu Aug 19 21:49:49 2010
New Revision: 987325

URL: http://svn.apache.org/viewvc?rev=987325&view=rev
Log:
TAP5-1222: Accessing a public field of a non-component object inside component code can result in a TransfomationException if the accessed field name matches the name of a component field

Added:
    tapestry/tapestry5/trunk/tapestry-core/src/test/app1/PublicFieldAccessDemo.tml
    tapestry/tapestry5/trunk/tapestry-core/src/test/groovy/org/apache/tapestry5/integration/app1/ClassTransformationTests.groovy
    tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/integration/app1/data/ResourcesHolder.java   (with props)
    tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/integration/app1/pages/PublicFieldAccessDemo.java   (with props)
Modified:
    tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/InternalClassTransformationImpl.java
    tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/integration/app1/pages/Index.java

Modified: tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/InternalClassTransformationImpl.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/InternalClassTransformationImpl.java?rev=987325&r1=987324&r2=987325&view=diff
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/InternalClassTransformationImpl.java (original)
+++ tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/InternalClassTransformationImpl.java Thu Aug 19 21:49:49 2010
@@ -2159,6 +2159,12 @@ public final class InternalClassTransfor
                 if (where instanceof CtConstructor)
                     return;
 
+                // It may be access to a public field of a data object somewhere and
+                // that's ignored TAP5-1222
+
+                if (!access.getClassName().equals(getClassName()))
+                    return;
+
                 boolean isRead = access.isReader();
                 String fieldName = access.getFieldName();
                 CtMethod method = (CtMethod) where;

Added: tapestry/tapestry5/trunk/tapestry-core/src/test/app1/PublicFieldAccessDemo.tml
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/test/app1/PublicFieldAccessDemo.tml?rev=987325&view=auto
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-core/src/test/app1/PublicFieldAccessDemo.tml (added)
+++ tapestry/tapestry5/trunk/tapestry-core/src/test/app1/PublicFieldAccessDemo.tml Thu Aug 19 21:49:49 2010
@@ -0,0 +1,11 @@
+<html t:type="Border" xmlns:t="http://tapestry.apache.org/schema/tapestry_5_0_0.xsd">
+
+
+  <h1>Public Field Access Demo</h1>
+
+  <p>
+    Result is:
+    <span id="message">${message}</span>
+  </p>
+
+</html>
\ No newline at end of file

Added: tapestry/tapestry5/trunk/tapestry-core/src/test/groovy/org/apache/tapestry5/integration/app1/ClassTransformationTests.groovy
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/test/groovy/org/apache/tapestry5/integration/app1/ClassTransformationTests.groovy?rev=987325&view=auto
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-core/src/test/groovy/org/apache/tapestry5/integration/app1/ClassTransformationTests.groovy (added)
+++ tapestry/tapestry5/trunk/tapestry-core/src/test/groovy/org/apache/tapestry5/integration/app1/ClassTransformationTests.groovy Thu Aug 19 21:49:49 2010
@@ -0,0 +1,29 @@
+// Copyright 2010 The Apache Software Foundation
+//
+// Licensed 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.
+
+package org.apache.tapestry5.integration.app1
+
+import org.apache.tapestry5.integration.TapestryCoreTestCase;
+import org.testng.annotations.Test;
+
+class ClassTransformationTests extends TapestryCoreTestCase
+{
+    /** TAP5-1222 */
+    @Test
+    void access_to_public_field_of_data_object_with_name_that_conflicts_with_component_field() {
+        clickThru "Public Field Access Demo"
+        
+        assertText "message", "success"
+    }
+}

Added: tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/integration/app1/data/ResourcesHolder.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/integration/app1/data/ResourcesHolder.java?rev=987325&view=auto
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/integration/app1/data/ResourcesHolder.java (added)
+++ tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/integration/app1/data/ResourcesHolder.java Thu Aug 19 21:49:49 2010
@@ -0,0 +1,27 @@
+// Copyright 2010 The Apache Software Foundation
+//
+// Licensed 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.
+
+package org.apache.tapestry5.integration.app1.data;
+
+public class ResourcesHolder
+{
+    // Name chosen to conflict with PublicFieldAccessDemo.resources
+    public final String resources;
+
+    public ResourcesHolder(String resources)
+    {
+        this.resources = resources;
+    }
+
+}

Propchange: tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/integration/app1/data/ResourcesHolder.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/integration/app1/pages/Index.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/integration/app1/pages/Index.java?rev=987325&r1=987324&r2=987325&view=diff
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/integration/app1/pages/Index.java (original)
+++ tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/integration/app1/pages/Index.java Thu Aug 19 21:49:49 2010
@@ -72,6 +72,8 @@ public class Index
     private static final List<Item> ITEMS = CollectionFactory
             .newList(
 
+                    new Item("PublicFieldAccessDemo", "Public Field Access Demo", "Demonstrates TAP5-1222 fix"),
+
                     new Item("ActivationRequestParameterDemo", "ActivationRequestParameter Annotation Demo",
                             "Use of @ActivationRequestParameter to encode page state into query parameters"),
 
@@ -444,10 +446,10 @@ public class Index
                             "Report Location of Unavailable Component"),
 
                     new Item("discardafterdemo", "@DiscardAfter Demo", "Demo using @DiscardAfter annotation"),
-                    
+
                     new Item("SelectDemo", "Select Demo", "Validation decoration for Select"),
-                    
-                    new Item("SelectModelFromObjectsAndPropertyNameDemo", "SelectModel from objects and property name", 
+
+                    new Item("SelectModelFromObjectsAndPropertyNameDemo", "SelectModel from objects and property name",
                             "Creating a SelectModel from a list of objects and a label property name")
 
             );

Added: tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/integration/app1/pages/PublicFieldAccessDemo.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/integration/app1/pages/PublicFieldAccessDemo.java?rev=987325&view=auto
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/integration/app1/pages/PublicFieldAccessDemo.java (added)
+++ tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/integration/app1/pages/PublicFieldAccessDemo.java Thu Aug 19 21:49:49 2010
@@ -0,0 +1,37 @@
+// Copyright 2010 The Apache Software Foundation
+//
+// Licensed 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.
+
+package org.apache.tapestry5.integration.app1.pages;
+
+import org.apache.tapestry5.ComponentResources;
+import org.apache.tapestry5.integration.app1.data.ResourcesHolder;
+import org.apache.tapestry5.ioc.annotations.Inject;
+
+public class PublicFieldAccessDemo
+{
+    @Inject
+    private ComponentResources resources;
+
+    private ResourcesHolder holder;
+
+    void setupRender()
+    {
+        holder = new ResourcesHolder("success");
+    }
+
+    public String getMessage()
+    {
+        return holder.resources;
+    }
+}

Propchange: tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/integration/app1/pages/PublicFieldAccessDemo.java
------------------------------------------------------------------------------
    svn:eol-style = native