464438 ClassFileTransformer support in org.eclipse.jetty.webapp.WebAppClassLoader broken

This commit is contained in:
Jan Bartel 2015-04-13 14:37:17 +10:00
parent 4fbdafb9e9
commit 92a3f17532
2 changed files with 22 additions and 3 deletions

View File

@ -519,10 +519,14 @@ public class WebAppClassLoader extends URLClassLoader
try
{
content = url.openStream();
byte[] bytes =IO.readBytes(content);
byte[] bytes = IO.readBytes(content);
for (ClassFileTransformer transformer : _transformers)
bytes=transformer.transform(this,name,null,null,bytes);
{
byte[] tmp = transformer.transform(this,name,null,null,bytes);
if (tmp != null)
bytes = tmp;
}
clazz=defineClass(name,bytes,0,bytes.length);
}

View File

@ -137,7 +137,22 @@ public class WebAppClassLoaderTest
assertEquals(_loader,iter.next());
assertEquals("org.acme.other.ClassInClassesC",iter.next());
assertFalse(iter.hasNext());
}
@Test
public void testNullClassFileTransformer () throws Exception
{
_loader.addTransformer(new ClassFileTransformer()
{
public byte[] transform(ClassLoader loader, String className, Class<?> classBeingRedefined, ProtectionDomain protectionDomain, byte[] classfileBuffer)
throws IllegalClassFormatException
{
return null;
}
});
assertTrue(canLoadClass("org.acme.webapp.ClassInJarA"));
}
@Test