Uploaded image for project: 'Jenkins'
  1. Jenkins
  2. JENKINS-3069

NPE in WebSphere at start-up since v1.271

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Fixed
    • Icon: Blocker Blocker
    • _unsorted
    • None
    • Platform: All, OS: All

      v1.271 changes the security filter implementation in hudson. Unfortunately this
      causes NPE to be thrown at application start in WebSphere with the following
      stack trace:

      Failed to initialize Hudson
      java.lang.NullPointerException
      at hudson.model.Hudson.setSecurityRealm(Hudson.java:1333)
      at hudson.model.Hudson.load(Hudson.java:1696)
      at hudson.model.Hudson.<init>(Hudson.java:446)

      at hudson.WebAppMain$2.run(WebAppMain.java:160)

      The NPE is caused because the instance of HudsonFilter is not available at the
      initializing time of Hudson instance in the servlet context. This is probably
      caused by the fact that WebSphere loads and initializes Filters at the first
      call to the filter mapped resources and not at the start-up of the application.
      The related code segments are:

      WebAppMain tries to init Hudson in separate thread:

      new Thread("hudson initialization thread") {
      public void run() {
      try {
      try

      { context.setAttribute(APP,new Hudson(home,context)); }

      catch( IOException e )

      { throw new Error(e); }

      initing new Hudson calls load(), which in turn tries to set the security realm
      to the proxy filter (in hudson.model.Hudson):

      public void setSecurityRealm(SecurityRealm securityRealm) {
      if(securityRealm==null)
      securityRealm= SecurityRealm.NO_AUTHENTICATION;
      this.securityRealm = securityRealm;
      // reset the filters and proxies for the new SecurityRealm
      try

      { HudsonFilter.get(servletContext).reset(securityRealm); }

      catch (ServletException e) {
      // for binary compatibility, this method cannot throw a checked
      exception
      throw new AcegiSecurityException("Failed to configure filter",e) {};
      }
      }

      HudsonFilter.get(context) tries to find its own instance saved at the init time
      in its init(FilterConfig) method into the servlet context and fails because the
      filter hasn't been initialized yet (in hudson.security.HudsonFilter):

      public void init(FilterConfig filterConfig) throws ServletException

      { this.filterConfig = filterConfig; // this is how we make us available to the rest of Hudson. filterConfig.getServletContext().setAttribute(HudsonFilter.class.getName(),this); }

      /**

      • Gets the {@link HudsonFilter}

        created for the given

        {@link ServletContext}

        .
        */
        public static HudsonFilter get(ServletContext context)

        { return (HudsonFilter)context.getAttribute(HudsonFilter.class.getName()); }

      IMHO the implementation here relays upon the availability of the servlet filters
      at application start-up time, but this is container specific implementation,
      because the servlet specification does not define exactly at what time the
      container should load and initialize a filter, but only that this must be done
      prior to first call to mapped resource for this filter. Because of this I can't
      consider this as a WebSphere incompatibility.

            Unassigned Unassigned
            ilkomiliev ilkomiliev
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved: