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 2007/03/06 19:57:19 UTC
svn commit: r515252 - in /tapestry/tapestry5/tapestry-core/trunk/src:
main/java/org/apache/tapestry/internal/services/
main/resources/org/apache/tapestry/internal/services/ test/app1/WEB-INF/
test/java/org/apache/tapestry/integration/ test/java/org/apa...
Author: hlship
Date: Tue Mar 6 10:57:18 2007
New Revision: 515252
URL: http://svn.apache.org/viewvc?view=rev&rev=515252
Log:
TAPESTRY-1275: Recursive Components cause heap space overflow
Added:
tapestry/tapestry5/tapestry-core/trunk/src/test/app1/WEB-INF/RecursiveDemo.html
tapestry/tapestry5/tapestry-core/trunk/src/test/java/org/apache/tapestry/integration/app1/components/Recursive.java
tapestry/tapestry5/tapestry-core/trunk/src/test/java/org/apache/tapestry/integration/app1/pages/RecursiveDemo.java
tapestry/tapestry5/tapestry-core/trunk/src/test/resources/org/apache/tapestry/integration/app1/components/Recursive.html
Modified:
tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/internal/services/PageElementFactoryImpl.java
tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/internal/services/PageLoaderProcessor.java
tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/internal/services/ServicesMessages.java
tapestry/tapestry5/tapestry-core/trunk/src/main/resources/org/apache/tapestry/internal/services/ServicesStrings.properties
tapestry/tapestry5/tapestry-core/trunk/src/test/app1/WEB-INF/Start.html
tapestry/tapestry5/tapestry-core/trunk/src/test/java/org/apache/tapestry/integration/IntegrationTests.java
tapestry/tapestry5/tapestry-core/trunk/src/test/java/org/apache/tapestry/integration/LaunchCrusherTest.java
Modified: tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/internal/services/PageElementFactoryImpl.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/internal/services/PageElementFactoryImpl.java?view=diff&rev=515252&r1=515251&r2=515252
==============================================================================
--- tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/internal/services/PageElementFactoryImpl.java (original)
+++ tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/internal/services/PageElementFactoryImpl.java Tue Mar 6 10:57:18 2007
@@ -142,6 +142,11 @@
Instantiator instantiator = _componentInstantiatorSource.findInstantiator(finalClassName);
+ // This is actually a good place to check for recursive templates, here where we've resolved
+ // the component type to a fully qualified class name.
+
+ checkForRecursion(finalClassName, container, location);
+
// The container for any components is the loading component, regardless of
// how the component elements are nested within the loading component's
// template.
@@ -156,6 +161,26 @@
addMixins(result, instantiator);
return result;
+ }
+
+ private void checkForRecursion(String componentClassName, ComponentPageElement container,
+ Location location)
+ {
+ // Container may be null for a root element;
+
+ if (container == null)
+ return;
+
+ ComponentResources resources = container.getComponentResources();
+
+ while (resources != null)
+ {
+ if (resources.getComponentModel().getComponentClassName().equals(componentClassName))
+ throw new TapestryException(
+ ServicesMessages.componentRecursion(componentClassName), location, null);
+
+ resources = resources.getContainerResources();
+ }
}
public ComponentPageElement newRootComponentElement(Page page, String componentType)
Modified: tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/internal/services/PageLoaderProcessor.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/internal/services/PageLoaderProcessor.java?view=diff&rev=515252&r1=515251&r2=515252
==============================================================================
--- tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/internal/services/PageLoaderProcessor.java (original)
+++ tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/internal/services/PageLoaderProcessor.java Tue Mar 6 10:57:18 2007
@@ -209,13 +209,6 @@
return defaultBindingPrefix != null ? defaultBindingPrefix : informalParameterBindingPrefix;
}
- private void addRenderBodyElement()
- {
- PageElement element = newRenderBodyElement();
-
- _loadingElement.addToTemplate(element);
- }
-
private PageElement newRenderBodyElement()
{
return _pageElementFactory.newRenderBodyElement(_loadingElement);
Modified: tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/internal/services/ServicesMessages.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/internal/services/ServicesMessages.java?view=diff&rev=515252&r1=515251&r2=515252
==============================================================================
--- tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/internal/services/ServicesMessages.java (original)
+++ tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/internal/services/ServicesMessages.java Tue Mar 6 10:57:18 2007
@@ -387,4 +387,10 @@
{
return MESSAGES.format("request-exception", cause);
}
+
+ static String componentRecursion(String componentClassName)
+ {
+ return MESSAGES.format("component-recursion", componentClassName);
+
+ }
}
Modified: tapestry/tapestry5/tapestry-core/trunk/src/main/resources/org/apache/tapestry/internal/services/ServicesStrings.properties
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/tapestry-core/trunk/src/main/resources/org/apache/tapestry/internal/services/ServicesStrings.properties?view=diff&rev=515252&r1=515251&r2=515252
==============================================================================
--- tapestry/tapestry5/tapestry-core/trunk/src/main/resources/org/apache/tapestry/internal/services/ServicesStrings.properties (original)
+++ tapestry/tapestry5/tapestry-core/trunk/src/main/resources/org/apache/tapestry/internal/services/ServicesStrings.properties Tue Mar 6 10:57:18 2007
@@ -76,4 +76,6 @@
method-not-found=No public method '%s' in class %s (within property expression '%s').
no-such-property=Class %s does not contain a property named '%s' (within property expression '%s').
write-only-property=Property '%s' of class %s (within property expression '%s') is not readable (it has no read accessor method).
-request-exception=Processing of request failed with uncaught exception: %s
\ No newline at end of file
+request-exception=Processing of request failed with uncaught exception: %s
+component-recursion=The template for component %s is recursive (contains another direct or indirect reference to component %<s). \
+ This is not supported (components may not contain themselves).
\ No newline at end of file
Added: tapestry/tapestry5/tapestry-core/trunk/src/test/app1/WEB-INF/RecursiveDemo.html
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/tapestry-core/trunk/src/test/app1/WEB-INF/RecursiveDemo.html?view=auto&rev=515252
==============================================================================
--- tapestry/tapestry5/tapestry-core/trunk/src/test/app1/WEB-INF/RecursiveDemo.html (added)
+++ tapestry/tapestry5/tapestry-core/trunk/src/test/app1/WEB-INF/RecursiveDemo.html Tue Mar 6 10:57:18 2007
@@ -0,0 +1,5 @@
+<html t:type="Border" xmlns:t="http://tapestry.apache.org/schema/tapestry_5_0_0.xsd">
+
+ This page contains a <t:recursive>Recursive component</t:recursive>, so it will never be able to render itself.
+
+</html>
Modified: tapestry/tapestry5/tapestry-core/trunk/src/test/app1/WEB-INF/Start.html
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/tapestry-core/trunk/src/test/app1/WEB-INF/Start.html?view=diff&rev=515252&r1=515251&r2=515252
==============================================================================
--- tapestry/tapestry5/tapestry-core/trunk/src/test/app1/WEB-INF/Start.html (original)
+++ tapestry/tapestry5/tapestry-core/trunk/src/test/app1/WEB-INF/Start.html Tue Mar 6 10:57:18 2007
@@ -119,6 +119,10 @@
<li>
<a t:type="pagelink" page="ValidBeanEditorDemo">Client Validation Demo</a> --BeanEditor with validation enabled
</li>
+
+ <li>
+ <a href="recursivedemo">Recursive Demo</a> -- check for handling of recursive components
+ </li>
</ul>
</td>
</tr>
Modified: tapestry/tapestry5/tapestry-core/trunk/src/test/java/org/apache/tapestry/integration/IntegrationTests.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/tapestry-core/trunk/src/test/java/org/apache/tapestry/integration/IntegrationTests.java?view=diff&rev=515252&r1=515251&r2=515252
==============================================================================
--- tapestry/tapestry5/tapestry-core/trunk/src/test/java/org/apache/tapestry/integration/IntegrationTests.java (original)
+++ tapestry/tapestry5/tapestry-core/trunk/src/test/java/org/apache/tapestry/integration/IntegrationTests.java Tue Mar 6 10:57:18 2007
@@ -31,7 +31,7 @@
* my system, Skype is listening on localhost:80.
*/
@Test(timeOut = 50000, sequential = true, groups =
-{ "integration" }, enabled=true)
+{ "integration" }, enabled = true)
public class IntegrationTests extends AbstractIntegrationTestSuite
{
@Test
@@ -841,5 +841,16 @@
clickAndWait("submit");
assertTextPresent("First Name: [Howard]");
+ }
+
+ public void recursive_components_are_identified_as_errors()
+ {
+ open(BASE_URL);
+ clickAndWait("link=Recursive Demo");
+
+ assertTextPresent(
+ "An unexpected application exception has occurred.",
+ "The template for component org.apache.tapestry.integration.app1.components.Recursive is recursive (contains another direct or indirect reference to component org.apache.tapestry.integration.app1.components.Recursive). This is not supported (components may not contain themselves).",
+ "This component is <t:recursive>recursive</t:recursive>, so we\'ll see a failure.");
}
}
Modified: tapestry/tapestry5/tapestry-core/trunk/src/test/java/org/apache/tapestry/integration/LaunchCrusherTest.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/tapestry-core/trunk/src/test/java/org/apache/tapestry/integration/LaunchCrusherTest.java?view=diff&rev=515252&r1=515251&r2=515252
==============================================================================
--- tapestry/tapestry5/tapestry-core/trunk/src/test/java/org/apache/tapestry/integration/LaunchCrusherTest.java (original)
+++ tapestry/tapestry5/tapestry-core/trunk/src/test/java/org/apache/tapestry/integration/LaunchCrusherTest.java Tue Mar 6 10:57:18 2007
@@ -1,3 +1,17 @@
+// Copyright 2007 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.tapestry.integration;
import static java.lang.String.format;
Added: tapestry/tapestry5/tapestry-core/trunk/src/test/java/org/apache/tapestry/integration/app1/components/Recursive.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/tapestry-core/trunk/src/test/java/org/apache/tapestry/integration/app1/components/Recursive.java?view=auto&rev=515252
==============================================================================
--- tapestry/tapestry5/tapestry-core/trunk/src/test/java/org/apache/tapestry/integration/app1/components/Recursive.java (added)
+++ tapestry/tapestry5/tapestry-core/trunk/src/test/java/org/apache/tapestry/integration/app1/components/Recursive.java Tue Mar 6 10:57:18 2007
@@ -0,0 +1,20 @@
+// Copyright 2007 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.tapestry.integration.app1.components;
+
+public class Recursive
+{
+
+}
Added: tapestry/tapestry5/tapestry-core/trunk/src/test/java/org/apache/tapestry/integration/app1/pages/RecursiveDemo.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/tapestry-core/trunk/src/test/java/org/apache/tapestry/integration/app1/pages/RecursiveDemo.java?view=auto&rev=515252
==============================================================================
--- tapestry/tapestry5/tapestry-core/trunk/src/test/java/org/apache/tapestry/integration/app1/pages/RecursiveDemo.java (added)
+++ tapestry/tapestry5/tapestry-core/trunk/src/test/java/org/apache/tapestry/integration/app1/pages/RecursiveDemo.java Tue Mar 6 10:57:18 2007
@@ -0,0 +1,20 @@
+// Copyright 2007 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.tapestry.integration.app1.pages;
+
+public class RecursiveDemo
+{
+
+}
Added: tapestry/tapestry5/tapestry-core/trunk/src/test/resources/org/apache/tapestry/integration/app1/components/Recursive.html
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/tapestry-core/trunk/src/test/resources/org/apache/tapestry/integration/app1/components/Recursive.html?view=auto&rev=515252
==============================================================================
--- tapestry/tapestry5/tapestry-core/trunk/src/test/resources/org/apache/tapestry/integration/app1/components/Recursive.html (added)
+++ tapestry/tapestry5/tapestry-core/trunk/src/test/resources/org/apache/tapestry/integration/app1/components/Recursive.html Tue Mar 6 10:57:18 2007
@@ -0,0 +1,9 @@
+<div xmlns:t="http://tapestry.apache.org/schema/tapestry_5_0_0.xsd">
+
+ <p>
+ This component is <t:recursive>recursive</t:recursive>, so we'll see a failure.
+ </p>
+
+ <t:body/>
+
+</div>