You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tapestry.apache.org by hl...@apache.org on 2008/02/23 02:04:15 UTC
svn commit: r630371 - in /tapestry/tapestry5/trunk/tapestry-ioc/src:
main/java/org/apache/tapestry/ioc/ test/java/org/apache/tapestry/ioc/
Author: hlship
Date: Fri Feb 22 17:04:11 2008
New Revision: 630371
URL: http://svn.apache.org/viewvc?rev=630371&view=rev
Log:
TAPESTRY-2117: Circular @SubModule will crash the IOC container with OutOfMemoryException
Added:
tapestry/tapestry5/trunk/tapestry-ioc/src/test/java/org/apache/tapestry/ioc/HelterModule.java
tapestry/tapestry5/trunk/tapestry-ioc/src/test/java/org/apache/tapestry/ioc/SkelterModule.java
Modified:
tapestry/tapestry5/trunk/tapestry-ioc/src/main/java/org/apache/tapestry/ioc/RegistryBuilder.java
tapestry/tapestry5/trunk/tapestry-ioc/src/test/java/org/apache/tapestry/ioc/IntegrationTest.java
Modified: tapestry/tapestry5/trunk/tapestry-ioc/src/main/java/org/apache/tapestry/ioc/RegistryBuilder.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-ioc/src/main/java/org/apache/tapestry/ioc/RegistryBuilder.java?rev=630371&r1=630370&r2=630371&view=diff
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-ioc/src/main/java/org/apache/tapestry/ioc/RegistryBuilder.java (original)
+++ tapestry/tapestry5/trunk/tapestry-ioc/src/main/java/org/apache/tapestry/ioc/RegistryBuilder.java Fri Feb 22 17:04:11 2008
@@ -1,4 +1,4 @@
-// Copyright 2006, 2007 The Apache Software Foundation
+// Copyright 2006, 2007, 2008 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.
@@ -21,6 +21,7 @@
import org.apache.tapestry.ioc.internal.RegistryImpl;
import org.apache.tapestry.ioc.internal.RegistryWrapper;
import org.apache.tapestry.ioc.internal.services.ClassFactoryImpl;
+import org.apache.tapestry.ioc.internal.util.CollectionFactory;
import static org.apache.tapestry.ioc.internal.util.CollectionFactory.newList;
import org.apache.tapestry.ioc.internal.util.OneShotLock;
import org.apache.tapestry.ioc.services.ClassFactory;
@@ -30,10 +31,11 @@
import java.lang.reflect.AnnotatedElement;
import java.util.Arrays;
import java.util.List;
+import java.util.Set;
/**
- * Used to construct the IoC {@link org.apache.tapestry.ioc.Registry}. This class is <em>not</em>
- * thread-safe. The Registry, once created, <em>is</em> thread-safe.
+ * Used to construct the IoC {@link org.apache.tapestry.ioc.Registry}. This class is <em>not</em> thread-safe. The
+ * Registry, once created, <em>is</em> thread-safe.
*/
public final class RegistryBuilder
{
@@ -52,6 +54,8 @@
private final ClassFactory _classFactory;
+ private final Set<Class> _addedModuleClasses = CollectionFactory.newSet();
+
public RegistryBuilder()
{
this(Thread.currentThread().getContextClassLoader());
@@ -83,6 +87,8 @@
_lock.check();
// TODO: Some way to ensure that duplicate modules are not being added.
+ // Part of TAPESTRY-2117 is in add(Class...) and that may be as much as we can
+ // do as there is no concept of ModuleDef identity.
_modules.add(moduleDef);
}
@@ -96,6 +102,12 @@
while (!queue.isEmpty())
{
Class c = queue.remove(0);
+
+ // Quietly ignore previously added classes.
+
+ if (_addedModuleClasses.contains(c)) continue;
+
+ _addedModuleClasses.add(c);
ModuleDef def = new DefaultModuleDefImpl(c, _logger, _classFactory);
add(def);
Added: tapestry/tapestry5/trunk/tapestry-ioc/src/test/java/org/apache/tapestry/ioc/HelterModule.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-ioc/src/test/java/org/apache/tapestry/ioc/HelterModule.java?rev=630371&view=auto
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-ioc/src/test/java/org/apache/tapestry/ioc/HelterModule.java (added)
+++ tapestry/tapestry5/trunk/tapestry-ioc/src/test/java/org/apache/tapestry/ioc/HelterModule.java Fri Feb 22 17:04:11 2008
@@ -0,0 +1,27 @@
+// Copyright 2008 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.ioc;
+
+import org.apache.tapestry.ioc.annotations.SubModule;
+
+
+@SubModule(SkelterModule.class)
+public class HelterModule
+{
+ public Runnable buildHelter()
+ {
+ return null;
+ }
+}
Modified: tapestry/tapestry5/trunk/tapestry-ioc/src/test/java/org/apache/tapestry/ioc/IntegrationTest.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-ioc/src/test/java/org/apache/tapestry/ioc/IntegrationTest.java?rev=630371&r1=630370&r2=630371&view=diff
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-ioc/src/test/java/org/apache/tapestry/ioc/IntegrationTest.java (original)
+++ tapestry/tapestry5/trunk/tapestry-ioc/src/test/java/org/apache/tapestry/ioc/IntegrationTest.java Fri Feb 22 17:04:11 2008
@@ -1,4 +1,4 @@
-// Copyright 2006, 2007 The Apache Software Foundation
+// Copyright 2006, 2007, 2008 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.
@@ -25,8 +25,7 @@
import java.util.*;
/**
- * A few tests that are easiest (or even just possible) by building a Registry and trying out a few
- * things.
+ * A few tests that are easiest (or even just possible) by building a Registry and trying out a few things.
*/
public class IntegrationTest extends IOCInternalTestCase
{
@@ -134,8 +133,7 @@
}
/**
- * Along the way, we also test a few other things, such as decorator matching and automatic
- * dependency resolution.
+ * Along the way, we also test a few other things, such as decorator matching and automatic dependency resolution.
*/
@Test
public void public_service_decorator_order()
@@ -168,8 +166,8 @@
}
/**
- * We don't have to do as many public/private etc. tests for the other types of configuration,
- * because the code paths are so similar.
+ * We don't have to do as many public/private etc. tests for the other types of configuration, because the code
+ * paths are so similar.
*/
@Test
@@ -280,8 +278,8 @@
}
/**
- * This test fails at times and I'm not sure why. It's some kind of interaction with other tests
- * but hard to figure out. Damn ThreadLocals!
+ * This test fails at times and I'm not sure why. It's some kind of interaction with other tests but hard to figure
+ * out. Damn ThreadLocals!
*/
@Test
public void registry_thread_cleanup()
@@ -700,8 +698,7 @@
}
/**
- * A cursory test for {@link ServiceActivityScoreboard}, just to see if any data has been
- * collected.
+ * A cursory test for {@link ServiceActivityScoreboard}, just to see if any data has been collected.
*/
@Test
public void service_activity_scoreboard()
@@ -769,4 +766,19 @@
}
+ /**
+ * TAPESTRY-2117
+ */
+ @Test
+ public void circular_module_references_are_ignored()
+ {
+ Registry r = buildRegistry(HelterModule.class);
+
+ Runnable helter = r.getService("Helter", Runnable.class);
+ Runnable skelter = r.getService("Skelter", Runnable.class);
+
+ assertNotSame(helter, skelter);
+
+ r.shutdown();
+ }
}
Added: tapestry/tapestry5/trunk/tapestry-ioc/src/test/java/org/apache/tapestry/ioc/SkelterModule.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-ioc/src/test/java/org/apache/tapestry/ioc/SkelterModule.java?rev=630371&view=auto
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-ioc/src/test/java/org/apache/tapestry/ioc/SkelterModule.java (added)
+++ tapestry/tapestry5/trunk/tapestry-ioc/src/test/java/org/apache/tapestry/ioc/SkelterModule.java Fri Feb 22 17:04:11 2008
@@ -0,0 +1,26 @@
+// Copyright 2008 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.ioc;
+
+import org.apache.tapestry.ioc.annotations.SubModule;
+
+@SubModule(HelterModule.class)
+public class SkelterModule
+{
+ public Runnable buildSkelter()
+ {
+ return null;
+ }
+}