title: Why Tiles REGEXP wildcard definition cause endless jsp including error
body: <p>I use tiles 2.2.2 with Struts2 2.2.3, since Struts2-Tiles plugin is quite old, its implementation uses many Tiles deprecated API, and I want to try REGEXP wildcard, so I implement my own listener below:</p>
  
  <p><strong>MyTilesContainerFactory</strong></p>
  
  <pre><code>package tiles;
  
  import org.apache.tiles.definition.pattern.DefinitionPatternMatcherFactory;
  import org.apache.tiles.definition.pattern.PatternDefinitionResolver;
  import org.apache.tiles.definition.pattern.PrefixedPatternDefinitionResolver;
  import org.apache.tiles.definition.pattern.regexp.RegexpDefinitionPatternMatcherFactory;
  import org.apache.tiles.definition.pattern.wildcard.WildcardDefinitionPatternMatcherFactory;
  import org.apache.tiles.factory.BasicTilesContainerFactory;
  
  
  public class MyTilesContainerFactory extends BasicTilesContainerFactory {
  
    @Override
    protected &lt;T&gt; PatternDefinitionResolver&lt;T&gt; createPatternDefinitionResolver(Class&lt;T&gt; customizationKeyClass) {
  
      DefinitionPatternMatcherFactory wildcardFactory = new WildcardDefinitionPatternMatcherFactory();
      DefinitionPatternMatcherFactory regexpFactory = new RegexpDefinitionPatternMatcherFactory();
      PrefixedPatternDefinitionResolver&lt;T&gt; resolver = new PrefixedPatternDefinitionResolver&lt;T&gt;();
      resolver.registerDefinitionPatternMatcherFactory("WILDCARD", wildcardFactory);
      resolver.registerDefinitionPatternMatcherFactory("REGEXP", regexpFactory);
      return resolver;
    }
  }
  </code></pre>
  
  <p><strong>MyTilesInitializer</strong></p>
  
  <pre><code>package tiles;
  
  import org.apache.tiles.TilesApplicationContext;
  import org.apache.tiles.factory.AbstractTilesContainerFactory;
  import org.apache.tiles.startup.AbstractTilesInitializer;
  
  
  public class MyTilesInitializer extends AbstractTilesInitializer {
  
    @Override
    protected AbstractTilesContainerFactory createContainerFactory(TilesApplicationContext context) {
      return new MyTilesContainerFactory();
    }
  
  }
  </code></pre>
  
  <p><strong>MyTilesListener</strong></p>
  
  <pre><code>package tiles;
  
  import org.apache.tiles.startup.TilesInitializer;
  import org.apache.tiles.web.startup.AbstractTilesListener;
  
  
  public class MyTilesListener extends AbstractTilesListener {
  
    @Override
    protected TilesInitializer createTilesInitializer() {
      return new MyTilesInitializer();
    }
  
  
  }
  </code></pre>
  
  <p>Then I define my tiles.xml</p>
  
  <pre><code>&lt;tiles-definitions&gt;
    &lt;definition name="REGEXP:(.*)" template="/WEB-INF/tiles/basicLayout.jsp"&gt;
      &lt;put-attribute name="header" value="/WEB-INF/tiles/header.jsp" /&gt;
      &lt;put-attribute name="content" value="/WEB-INF/pages/{1}.jsp" /&gt;
      &lt;put-attribute name="footer" value="/WEB-INF/tiles/footer.jsp" /&gt;
    &lt;/definition&gt;
  &lt;/tiles-definitions&gt;
  </code></pre>
  
  <p>When I try a action that returns a tiles result, it ends up with an infinite loop, a jsp include error.</p>
  
  <pre><code>SEVERE: Servlet.service() for servlet jsp threw exception
  java.lang.StackOverflowError
      at java.io.UnixFileSystem.getBooleanAttributes0(Native Method)
      at java.io.UnixFileSystem.getBooleanAttributes(UnixFileSystem.java:228)
      at java.io.File.exists(File.java:733)
      at sun.misc.URLClassPath$FileLoader.getResource(URLClassPath.java:999)
      at sun.misc.URLClassPath.getResource(URLClassPath.java:169)
      at java.net.URLClassLoader$1.run(URLClassLoader.java:194)
      at java.security.AccessController.doPrivileged(Native Method)
      at java.net.URLClassLoader.findClass(URLClassLoader.java:190)
      at java.lang.ClassLoader.loadClass(ClassLoader.java:307)
      at java.lang.ClassLoader.loadClass(ClassLoader.java:248)
      at java.lang.ClassLoader.defineClass1(Native Method)
      at java.lang.ClassLoader.defineClassCond(ClassLoader.java:632)
      at java.lang.ClassLoader.defineClass(ClassLoader.java:616)
      at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:141)
      at java.net.URLClassLoader.defineClass(URLClassLoader.java:283)
      at java.net.URLClassLoader.access$000(URLClassLoader.java:58)
      at java.net.URLClassLoader$1.run(URLClassLoader.java:197)
      at java.security.AccessController.doPrivileged(Native Method)
      at java.net.URLClassLoader.findClass(URLClassLoader.java:190)
      at java.lang.ClassLoader.loadClass(ClassLoader.java:307)
      at java.lang.ClassLoader.loadClass(ClassLoader.java:248)
      at org.apache.jasper.compiler.ErrorDispatcher.createJavacError(ErrorDispatcher.java:526)
      at org.apache.jasper.servlet.JspServletWrapper.handleJspException(JspServletWrapper.java:490)
      at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:416)
      at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:337)
      at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:266)
      at javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
      at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
      at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
      at org.apache.catalina.core.ApplicationDispatcher.invoke(ApplicationDispatcher.java:630)
      at org.apache.catalina.core.ApplicationDispatcher.doInclude(ApplicationDispatcher.java:535)
      at org.apache.catalina.core.ApplicationDispatcher.include(ApplicationDispatcher.java:472)
      at org.apache.jasper.runtime.JspRuntimeLibrary.include(JspRuntimeLibrary.java:968)
      at org.apache.jasper.runtime.PageContextImpl.doInclude(PageContextImpl.java:638)
      at org.apache.jasper.runtime.PageContextImpl.include(PageContextImpl.java:632)
      at org.apache.tiles.jsp.context.JspTilesRequestContext.include(JspTilesRequestContext.java:103)
      at org.apache.tiles.jsp.context.JspTilesRequestContext.dispatch(JspTilesRequestContext.java:96)
      at org.apache.tiles.renderer.impl.TemplateAttributeRenderer.write(TemplateAttributeRenderer.java:44)
      at org.apache.tiles.renderer.impl.AbstractBaseAttributeRenderer.render(AbstractBaseAttributeRenderer.java:106)
      at org.apache.tiles.impl.BasicTilesContainer.render(BasicTilesContainer.java:670)
      at org.apache.tiles.impl.BasicTilesContainer.render(BasicTilesContainer.java:690)
      at org.apache.tiles.impl.BasicTilesContainer.render(BasicTilesContainer.java:644)
      at org.apache.tiles.impl.BasicTilesContainer.render(BasicTilesContainer.java:627)
      at org.apache.tiles.impl.BasicTilesContainer.render(BasicTilesContainer.java:321)
      at org.apache.tiles.renderer.impl.DefinitionAttributeRenderer.write(DefinitionAttributeRenderer.java:56)
      at org.apache.tiles.renderer.impl.AbstractBaseAttributeRenderer.render(AbstractBaseAttributeRenderer.java:106)
      at org.apache.tiles.renderer.impl.ChainedDelegateAttributeRenderer.write(ChainedDelegateAttributeRenderer.java:76)
      at org.apache.tiles.renderer.impl.AbstractBaseAttributeRenderer.render(AbstractBaseAttributeRenderer.java:106)
      at org.apache.tiles.impl.BasicTilesContainer.render(BasicTilesContainer.java:670)
      at org.apache.tiles.impl.BasicTilesContainer.render(BasicTilesContainer.java:336)
      at org.apache.tiles.template.InsertAttributeModel.renderAttribute(InsertAttributeModel.java:210)
      at org.apache.tiles.template.InsertAttributeModel.end(InsertAttributeModel.java:126)
      at org.apache.tiles.jsp.taglib.InsertAttributeTag.doTag(InsertAttributeTag.java:311)
      at org.apache.jsp.WEB_002dINF.tiles.basicLayout_jsp._jspx_meth_tiles_005finsertAttribute_005f0(basicLayout_jsp.java:128)
      at org.apache.jsp.WEB_002dINF.tiles.basicLayout_jsp._jspService(basicLayout_jsp.java:93)
      at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
      at javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
      at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:374)
      at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:337)
      at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:266)
      at javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
      at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
      at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
      at org.apache.catalina.core.ApplicationDispatcher.invoke(ApplicationDispatcher.java:630)
      at org.apache.catalina.core.ApplicationDispatcher.doInclude(ApplicationDispatcher.java:535)
      at org.apache.catalina.core.ApplicationDispatcher.include(ApplicationDispatcher.java:472)
      at org.apache.jasper.runtime.JspRuntimeLibrary.include(JspRuntimeLibrary.java:968)
      at org.apache.jasper.runtime.PageContextImpl.doInclude(PageContextImpl.java:638)
      at org.apache.jasper.runtime.PageContextImpl.include(PageContextImpl.java:632)
      at org.apache.tiles.jsp.context.JspTilesRequestContext.include(JspTilesRequestContext.java:103)
      at org.apache.tiles.jsp.context.JspTilesRequestContext.dispatch(JspTilesRequestContext.java:96)
      at org.apache.tiles.renderer.impl.TemplateAttributeRenderer.write(TemplateAttributeRenderer.java:44)
      at org.apache.tiles.renderer.impl.AbstractBaseAttributeRenderer.render(AbstractBaseAttributeRenderer.java:106)
      at org.apache.tiles.impl.BasicTilesContainer.render(BasicTilesContainer.java:670)
      at org.apache.tiles.impl.BasicTilesContainer.render(BasicTilesContainer.java:690)
      at org.apache.tiles.impl.BasicTilesContainer.render(BasicTilesContainer.java:644)
      at org.apache.tiles.impl.BasicTilesContainer.render(BasicTilesContainer.java:627)
      at org.apache.tiles.impl.BasicTilesContainer.render(BasicTilesContainer.java:321)
      at org.apache.tiles.renderer.impl.DefinitionAttributeRenderer.write(DefinitionAttributeRenderer.java:56)
      at org.apache.tiles.renderer.impl.AbstractBaseAttributeRenderer.render(AbstractBaseAttributeRenderer.java:106)
      at org.apache.tiles.renderer.impl.ChainedDelegateAttributeRenderer.write(ChainedDelegateAttributeRenderer.java:76)
      at org.apache.tiles.renderer.impl.AbstractBaseAttributeRenderer.render(AbstractBaseAttributeRenderer.java:106)
      at org.apache.tiles.impl.BasicTilesContainer.render(BasicTilesContainer.java:670)
      at org.apache.tiles.impl.BasicTilesContainer.render(BasicTilesContainer.java:336)
      at org.apache.tiles.template.InsertAttributeModel.renderAttribute(InsertAttributeModel.java:210)
      at org.apache.tiles.template.InsertAttributeModel.end(InsertAttributeModel.java:126)
      at org.apache.tiles.jsp.taglib.InsertAttributeTag.doTag(InsertAttributeTag.java:311)
      at org.apache.jsp.WEB_002dINF.tiles.basicLayout_jsp._jspx_meth_tiles_005finsertAttribute_005f0(basicLayout_jsp.java:128)
      at org.apache.jsp.WEB_002dINF.tiles.basicLayout_jsp._jspService(basicLayout_jsp.java:93)
      at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
      at javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
  </code></pre>
  
  <p>Could any one give me advice? I have to say that if I didn't use wildcard definition, the same definition works fine. Thanks a lot.</p>