https://bz.apache.org/bugzilla/show_bug.cgi?id=58629

            Bug ID: 58629
           Summary: Container is not initialized while starting tomcat in
                    embedded mode.
           Product: Tomcat 9
           Version: 9.0.0.M1
          Hardware: PC
            Status: NEW
          Severity: normal
          Priority: P2
         Component: Catalina
          Assignee: dev@tomcat.apache.org
          Reporter: gandhi.sa...@live.com

Created attachment 33284
  --> https://bz.apache.org/bugzilla/attachment.cgi?id=33284&action=edit
Patch for the solution.

For earliar versions, following code works. But for tomcat 9 , It is giving
null pointer exception while starting the server.

    Tomcat tomcat = new Tomcat();
    tomcat.setHostname("localhost");
    tomcat.setPort(8080);
    tomcat.setBaseDir("D:/softwares/servers/STUDY_TOMCAT");
    tomcat.start();


Exception in thread "main" org.apache.catalina.LifecycleException: Failed to
start component [StandardServer[-1]]
    at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:159)
    at org.apache.catalina.startup.Tomcat.start(Tomcat.java:345)
    at com.gandhisagar.test.TomcatStart.main(TomcatStart.java:13)
Caused by: org.apache.catalina.LifecycleException: Failed to start component
[StandardService[Tomcat]]
    at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:159)
    at
org.apache.catalina.core.StandardServer.startInternal(StandardServer.java:769)
    at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:155)
    ... 2 more
Caused by: org.apache.catalina.LifecycleException: Failed to start component
[org.apache.catalina.mapper.MapperListener@685f4c2e]
    at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:159)
    at
org.apache.catalina.core.StandardService.startInternal(StandardService.java:451)
    at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:155)
    ... 4 more
Caused by: java.lang.NullPointerException
    at
org.apache.catalina.mapper.MapperListener.findDefaultHost(MapperListener.java:261)
    at
org.apache.catalina.mapper.MapperListener.startInternal(MapperListener.java:102)
    at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:155)
    ... 6 more


Solution:

While debugging the issue we found that , Container is not getting initialized
properly. So we need to call corg.apache.catalina.startup.Tomcat.getEngine()
while starting the server in embedded mode. So that same code will work with
Tomcat 9.0

(Attaching the patch with the bug)

-- 
You are receiving this mail because:
You are the assignee for the bug.

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscr...@tomcat.apache.org
For additional commands, e-mail: dev-h...@tomcat.apache.org

Reply via email to