[447816] - ServletHolder#compareTo not transitive
Updating compareTo to properly order when one _className is null and the other is not. Signed-off-by: Matt Gilman <matt.c.gilman@gmail.com>
This commit is contained in:
parent
717fc7819d
commit
abe5d090bb
|
@ -208,15 +208,29 @@ public class ServletHolder extends Holder<Servlet> implements UserIdentity.Scope
|
|||
{
|
||||
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;
|
||||
// consider _className, need to position properly when one is configured but not the other
|
||||
int c;
|
||||
if (_className==null && sh._className==null)
|
||||
c=0;
|
||||
else if (_className==null)
|
||||
c=-1;
|
||||
else if (sh._className==null)
|
||||
c=1;
|
||||
else
|
||||
c=_className.compareTo(sh._className);
|
||||
|
||||
// if _initOrder and _className are the same, consider the _name
|
||||
if (c==0)
|
||||
c=_name.compareTo(sh._name);
|
||||
return c;
|
||||
|
||||
return c;
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
|
|
|
@ -0,0 +1,55 @@
|
|||
//
|
||||
// ========================================================================
|
||||
// Copyright (c) 1995-2015 Mort Bay Consulting Pty. Ltd.
|
||||
// ------------------------------------------------------------------------
|
||||
// All rights reserved. This program and the accompanying materials
|
||||
// are made available under the terms of the Eclipse Public License v1.0
|
||||
// and Apache License v2.0 which accompanies this distribution.
|
||||
//
|
||||
// The Eclipse Public License is available at
|
||||
// http://www.eclipse.org/legal/epl-v10.html
|
||||
//
|
||||
// The Apache License v2.0 is available at
|
||||
// http://www.opensource.org/licenses/apache2.0.php
|
||||
//
|
||||
// You may elect to redistribute this code under either of these licenses.
|
||||
// ========================================================================
|
||||
//
|
||||
|
||||
package org.eclipse.jetty.servlet;
|
||||
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
|
||||
public class ServletHolderTest {
|
||||
|
||||
@Test
|
||||
public void testTransitiveCompareTo() throws Exception
|
||||
{
|
||||
// example of jsp-file referenced in web.xml
|
||||
final ServletHolder one = new ServletHolder();
|
||||
one.setInitOrder(-1);
|
||||
one.setName("Login");
|
||||
one.setClassName(null);
|
||||
|
||||
// example of pre-compiled jsp
|
||||
final ServletHolder two = new ServletHolder();
|
||||
two.setInitOrder(-1);
|
||||
two.setName("org.my.package.jsp.WEB_002dINF.pages.precompiled_002dpage_jsp");
|
||||
two.setClassName("org.my.package.jsp.WEB_002dINF.pages.precompiled_002dpage_jsp");
|
||||
|
||||
// example of servlet referenced in web.xml
|
||||
final ServletHolder three = new ServletHolder();
|
||||
three.setInitOrder(-1);
|
||||
three.setName("Download");
|
||||
three.setClassName("org.my.package.web.DownloadServlet");
|
||||
|
||||
// verify compareTo transitivity
|
||||
Assert.assertTrue(one.compareTo(two) < 0);
|
||||
Assert.assertTrue(two.compareTo(three) < 0);
|
||||
Assert.assertTrue(one.compareTo(three) < 0);
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue