Uploaded image for project: 'Apache NiFi'
  1. Apache NiFi
  2. NIFI-1265

Precompiling message-page.jsp causes runtime error in CentOS 6.7 and Fedora 23

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Resolved
    • Minor
    • Resolution: Fixed
    • None
    • 1.0.0, 1.0.0-Beta
    • Core UI
    • None

    Description

      During start up it appears that when message-page.jsp is precompiled and run in CentOS 6.7 or Fedora 23 the following method in ServletHolder (Jetty) fails with:

      2015-12-07 10:01:26,557 WARN [main] org.apache.nifi.web.server.JettyServer
      Failed to start web server... shutting down.
      java.lang.IllegalArgumentException: Comparison method violates its general
      contract!
      at java.util.ComparableTimSort.mergeHi(ComparableTimSort.java:866)
      ~[na:1.8.0_65]
      at java.util.ComparableTimSort.mergeAt(ComparableTimSort.java:483)
      ~[na:1.8.0_65]
      at
      java.util.ComparableTimSort.mergeForceCollapse(ComparableTimSort.java:422)
      ~[na:1.8.0_65]
      at java.util.ComparableTimSort.sort(ComparableTimSort.java:222)
      ~[na:1.8.0_65]
      at java.util.Arrays.sort(Arrays.java:1246) ~[na:1.8.0_65]
      at
      org.eclipse.jetty.servlet.ServletHandler.initialize(ServletHandler.java:865)
      ~[jetty-servlet-9.2.11.v20150529.jar:9.2.11.v20150529]
      at
      org.eclipse.jetty.servlet.ServletContextHandler.startContext(ServletContextHandler.java:298)
      ~[jetty-servlet-9.2.11.v20150529.jar:9.2.11.v20150529]
      at
      org.eclipse.jetty.webapp.WebAppContext.startWebapp(WebAppContext.java:1349)
      ~[jetty-webapp-9.2.11.v20150529.jar:9.2.11.v20150529]
      
      @Override
          public int compareTo(ServletHolder sh)
          {
              if (sh==this)
                  return 0;
              if (sh._initOrder<_initOrder)
                  return 1;
              if (sh._initOrder>_initOrder)
                  return -1;
      
              int c=(_className!=null && sh._className!=null)?_className.compareTo(sh._className):0;
              if (c==0)
                  c=_name.compareTo(sh._name);
                  return c;
          }
      

      After a quick glance it may be that this method is not transitive when falling back to comparing by className and name. From the Java API

      The implementor must also ensure that the relation is transitive: ((compare(x, y)>0) && (compare(y, z)>0)) implies compare(x, z)>0.
      

      This could fail with the following scenario:

      x._initOrder = -1
      x._className = null
      x._name = Login
      
      y._initOrder = -1
      y._className = org.apache.nifi.web.jsp.WEB_002dINF.pages.message_002dpage_jsp
      y._name = org.apache.nifi.web.jsp.WEB_002dINF.pages.message_002dpage_jsp
      
      z._initOrder = -1
      z._className = org.apache.nifi.web.servlet.DownloadSvg
      z._name = DownloadSvg
      

      Unfortunately, I am unable to replicate the exception. However, my observation from debugging show that when JSPs are precompiled the _className and _name are the same (like y above). When a Servlet is referenced in the web.xml it's name is overridden (like z above). And when a JSP is referenced in the web.xml the _className is null and the _name is set to the name from the web.xml (like x above).

      In the scenario outlined: X < Y and Y < Z but Z < X. When running locally I did not see the exception mentioned above but the resulting sort order was not correct as it ultimately depended on which elements were compared to each other.

      Attachments

        1. jetty.447816.patch
          1 kB
          Greg Senia

        Issue Links

          Activity

            People

              mcgilman Matt Gilman
              mcgilman Matt Gilman
              Votes:
              1 Vote for this issue
              Watchers:
              9 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: