Your achievements

Level 1

0% to

Level 2

Tip /
Sign in

Sign in to Community

to gain points, level up, and earn exciting badges like the new
Bedrock Mission!

Learn more

View all

Sign in to view all badges

StackOverflowError when using adaptTo()


Level 1

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:


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.osgi.framework.Constants;

import javax.servlet.ServletException;


   name = "",
   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");


1 Reply


Level 1

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;