StackOverflowError when using adaptTo()



Hi all

I have a simple servlet which tries to adapt the SlingHttpServletRequest to an interface called TestEnvironment. The interface has one concrete implementation called ConcreteTestEnvironment which is annotated as sling model. When adapting the request I get a StackOverflowError. Do you know why? I'm using AEM 6.3 without service packs.

My versions are:

  • Apache Sling Models Implementation 1.3.9.r1784960
  • Apache Sling Models API 1.3.2

Here the code:

package ch.ti8m.ubs.fim.test;

import ch.ti8m.ubs.fim.test.models.TestEnvironment;
import org.apache.felix.scr.annotations.Component;
import org.apache.felix.scr.annotations.Properties;
import org.apache.felix.scr.annotations.Property;
import org.apache.felix.scr.annotations.Service;
import org.apache.sling.api.SlingHttpServletRequest;
import org.apache.sling.api.SlingHttpServletResponse;
import org.apache.sling.api.servlets.SlingAllMethodsServlet;
import org.osgi.framework.Constants;

import javax.servlet.ServletException;
import java.io.IOException;


   name = "ch.ti8m.ubs.fim.test.Servlet",
   metatype = true)



   @Property(name = Constants.SERVICE_VENDOR, value = "ti8m"),
   @Property(name = Constants.SERVICE_DESCRIPTION, value = "Servlet"),
   @Property(name = "sling.servlet.methods", value = {"GET"}),
   @Property(name = "sling.servlet.paths", value = "/bin/fim/test/servlet"),

public class Servlet extends SlingAllMethodsServlet {

   protected void doGet(SlingHttpServletRequest request, SlingHttpServletResponse response)

   throws ServletException, IOException {

  TestEnvironment env = request.adaptTo(TestEnvironment.class);

   response.getWriter().write("Servlet called");






Here the other classes. I cant edit my answer...

public interface TestEnvironment {

  SlingHttpServletRequest getRequest();

@Model(adaptables = SlingHttpServletRequest.class, adapters = TestEnvironment.class)

public class ConcreteTestEnvironment implements TestEnvironment {

   SlingHttpServletRequest request;
   public SlingHttpServletRequest getRequest() {

   return request;