From 6ef9108cf692c870b7dfaf15ee350074ba99761f Mon Sep 17 00:00:00 2001 From: Jan Bartel Date: Thu, 24 Oct 2013 15:08:04 +1100 Subject: [PATCH] 415118 WebAppClassLoader.getResource(name) should strip .class from name --- .../jetty/webapp/WebAppClassLoader.java | 11 +++++++++-- .../jetty/webapp/WebAppClassLoaderTest.java | 18 +++++++++++++++++- 2 files changed, 26 insertions(+), 3 deletions(-) diff --git a/jetty-webapp/src/main/java/org/eclipse/jetty/webapp/WebAppClassLoader.java b/jetty-webapp/src/main/java/org/eclipse/jetty/webapp/WebAppClassLoader.java index 3235b52f701..4e3cf835449 100644 --- a/jetty-webapp/src/main/java/org/eclipse/jetty/webapp/WebAppClassLoader.java +++ b/jetty-webapp/src/main/java/org/eclipse/jetty/webapp/WebAppClassLoader.java @@ -336,8 +336,15 @@ public class WebAppClassLoader extends URLClassLoader { URL url= null; boolean tried_parent= false; - boolean system_class=_context.isSystemClass(name); - boolean server_class=_context.isServerClass(name); + + //If the resource is a class name with .class suffix, strip it off before comparison + //as the server and system patterns are specified without a .class suffix + String tmp = name; + if (tmp != null && tmp.endsWith(".class")) + tmp = tmp.substring(0, tmp.length()-6); + + boolean system_class=_context.isSystemClass(tmp); + boolean server_class=_context.isServerClass(tmp); if (system_class && server_class) return null; diff --git a/jetty-webapp/src/test/java/org/eclipse/jetty/webapp/WebAppClassLoaderTest.java b/jetty-webapp/src/test/java/org/eclipse/jetty/webapp/WebAppClassLoaderTest.java index 41c6413df09..179a904bd11 100644 --- a/jetty-webapp/src/test/java/org/eclipse/jetty/webapp/WebAppClassLoaderTest.java +++ b/jetty-webapp/src/test/java/org/eclipse/jetty/webapp/WebAppClassLoaderTest.java @@ -19,6 +19,7 @@ package org.eclipse.jetty.webapp; import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertTrue; import java.net.URL; @@ -121,9 +122,24 @@ public class WebAppClassLoaderTest assertTrue(canLoadClass("org.acme.webapp.ClassInJarA")); assertTrue(canLoadClass("org.acme.webapp.ClassInJarB")); assertTrue(canLoadClass("org.acme.other.ClassInClassesC")); - assertTrue(cantLoadClass("org.eclipse.jetty.webapp.Configuration")); assertTrue(cantLoadClass("org.eclipse.jetty.webapp.JarScanner")); + + oldSysC=_context.getSystemClasses(); + newSysC=new String[oldSysC.length+1]; + newSysC[0]="org.acme.webapp.ClassInJarA"; + System.arraycopy(oldSysC,0,newSysC,1,oldSysC.length); + _context.setSystemClasses(newSysC); + + assertNotNull(_loader.getResource("org/acme/webapp/ClassInJarA.class")); + _context.setSystemClasses(oldSysC); + + oldServC=_context.getServerClasses(); + newServC=new String[oldServC.length+1]; + newServC[0]="org.acme.webapp.ClassInJarA"; + System.arraycopy(oldServC,0,newServC,1,oldServC.length); + _context.setServerClasses(newServC); + assertNotNull(_loader.getResource("org/acme/webapp/ClassInJarA.class")); } @Test