From: Sascha Brawer <brawer@dandelis.ch>
To: David Holmes <dholmes@dltech.com.au>,
Chris Gray <chris@kiffer.eunet.be>, Andrew Haley <aph@redhat.com>
Cc: GNU Classpath <classpath@gnu.org>, <mauve-discuss@sources.redhat.com>
Subject: ClassLoader.findLoadedClass (was: ServiceFactory)
Date: Mon, 22 Mar 2004 08:14:00 -0000 [thread overview]
Message-ID: <20040322081359.4021@smtp.mail.ch.easynet.net> (raw)
In-Reply-To: <NFBBKALFDCPFIDBNKAPCIEFEDPAA.dholmes@dltech.com.au>
[-- Attachment #1: Type: text/plain, Size: 1341 bytes --]
David Holmes <dholmes@dltech.com.au> 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, brawer@dandelis.ch, http://www.dandelis.ch/people/brawer/
[-- Attachment #2.1: TestClass.java --]
[-- Type: text/plain, Size: 947 bytes --]
// Tags: not-a-test
// Copyright (C) 2004 Sascha Brawer <brawer@dandelis.ch>
// 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
{
}
[-- Attachment #2.2: findLoadedClass.java --]
[-- Type: text/plain, Size: 2023 bytes --]
// Tags: JDK1.2
// Uses: TestClass
// Copyright (C) 2004 Sascha Brawer <brawer@dandelis.ch>
// 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:brawer@dandelis.ch">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 {@link
* ClassLoader#findLoadedClass}.
*/
public Class callFindLoadedClass(String name)
{
return findLoadedClass(name);
}
}
}
next parent reply other threads:[~2004-03-22 8:14 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <NFBBKALFDCPFIDBNKAPCIEFEDPAA.dholmes@dltech.com.au>
2004-03-22 8:14 ` Sascha Brawer [this message]
2004-03-22 9:16 ` Sascha Brawer
2004-03-22 13:15 Robert Lougher
2004-03-23 0:44 ` David Holmes
2004-03-23 17:25 ` Archie Cobbs
2004-03-23 23:59 ` David Holmes
2004-03-24 10:40 Robert Lougher
2004-03-25 0:02 ` David Holmes
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20040322081359.4021@smtp.mail.ch.easynet.net \
--to=brawer@dandelis.ch \
--cc=aph@redhat.com \
--cc=chris@kiffer.eunet.be \
--cc=classpath@gnu.org \
--cc=dholmes@dltech.com.au \
--cc=mauve-discuss@sources.redhat.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).