David Holmes <[EMAIL PROTECTED]> wrote on Mon, 22 Mar 2004 09:22:43 +1000:
>From what I've read, the specification of findLoadedClass and definition of
>the class cache in terms of an initiating classloader, are intended to
>prevent a malicious classloader from breaking the lookup process. If each
>classloader delegates correctly to its parent then there is, as you say, no
>harm. However, if the parent does not play nicely then different class
>instances could be returned.
>
>This seems like a bug in the JDK implementation of findLoadedClass.
Please find attached a testcase for Mauve (put the two files into gnu/
testlet/java/lang/ClassLoader).
My understanding of the API spec [1] is that on line 51 of the testlet,
the result of calling findLoadedClass should be 'klass' because 'loader'
is an initiating loader for "gnu.testlet.java.lang.ClassLoader.TestClass".
[1] http://java.sun.com/j2se/1.5.0/docs/api/java/lang/
ClassLoader.html#findLoadedClass(java.lang.String)
On JDK 1.4.1_01, the testlet fails because the result returns null. Same
for JamVM, which is based on Classpath.
If people agree that both the JDK and the Classpath-based VMs are buggy,
I'd commit the test case into Mauve and file bug reports with Classpath
and Sun.
-- Sascha
Sascha Brawer, [EMAIL PROTECTED], http://www.dandelis.ch/people/brawer/
// Tags: not-a-test
// Copyright (C) 2004 Sascha Brawer <[EMAIL PROTECTED]>
// This file is part of Mauve.
// Mauve is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation; either version 2, or (at your option)
// any later version.
// Mauve is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
// You should have received a copy of the GNU General Public License
// along with Mauve; see the file COPYING. If not, write to
// the Free Software Foundation, 59 Temple Place - Suite 330,
// Boston, MA 02111-1307, USA.
package gnu.testlet.java.lang.ClassLoader;
/**
* Used by gnu.testlet.java.lang.ClassLoader.findLoadedClass.
*/
public class TestClass
{
}
// Tags: JDK1.2
// Uses: TestClass
// Copyright (C) 2004 Sascha Brawer <[EMAIL PROTECTED]>
// This file is part of Mauve.
// Mauve is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation; either version 2, or (at your option)
// any later version.
// Mauve is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
// You should have received a copy of the GNU General Public License
// along with Mauve; see the file COPYING. If not, write to
// the Free Software Foundation, 59 Temple Place - Suite 330,
// Boston, MA 02111-1307, USA.
package gnu.testlet.java.lang.ClassLoader;
import gnu.testlet.Testlet;
import gnu.testlet.TestHarness;
/**
* @author <a href="mailto:[EMAIL PROTECTED]">Sascha Brawer</a>
*/
public class findLoadedClass
implements Testlet
{
public void test(TestHarness h)
{
CustomClassLoader loader;
String name;
Class klass;
// Check #1: Ask a ClassLoader to load a class, then check
// whether its findLoadedClass method returns it.
//
// Fails with JDK 1.4.1_01 (for GNU/Linux on IA-32) because
// its ClassLoader.findLoadedClass returns null here.
loader = new CustomClassLoader();
name = "gnu.testlet.java.lang.ClassLoader.TestClass";
try
{
klass = loader.loadClass(name);
h.check(loader.callFindLoadedClass(name), klass);
}
catch (ClassNotFoundException cnfex)
{
h.check(false);
h.debug(cnfex);
}
}
private static class CustomClassLoader
extends ClassLoader
{
/**
* Returns the result of calling the protected method [EMAIL PROTECTED]
* ClassLoader#findLoadedClass}.
*/
public Class callFindLoadedClass(String name)
{
return findLoadedClass(name);
}
}
}
_______________________________________________
Classpath mailing list
[EMAIL PROTECTED]
http://mail.gnu.org/mailman/listinfo/classpath