Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.java.programmer > #6661

Detecting if a class is already known

Path csiph.com!x330-a1.tempe.blueboxinc.net!newsfeed.hal-mli.net!feeder3.hal-mli.net!nx02.iad01.newshosting.com!newshosting.com!news-out.readnews.com!transit3.readnews.com!postnews.google.com!l7g2000vbz.googlegroups.com!not-for-mail
From Ross <rossclement@gmail.com>
Newsgroups comp.lang.java.programmer
Subject Detecting if a class is already known
Date Fri, 29 Jul 2011 09:47:11 -0700 (PDT)
Organization http://groups.google.com
Lines 34
Message-ID <c58b6bca-daa4-4942-b466-768344bf26b1@l7g2000vbz.googlegroups.com> (permalink)
NNTP-Posting-Host 80.176.151.208
Mime-Version 1.0
Content-Type text/plain; charset=ISO-8859-1
X-Trace posting.google.com 1311958127 26771 127.0.0.1 (29 Jul 2011 16:48:47 GMT)
X-Complaints-To groups-abuse@google.com
NNTP-Posting-Date Fri, 29 Jul 2011 16:48:47 +0000 (UTC)
Complaints-To groups-abuse@google.com
Injection-Info l7g2000vbz.googlegroups.com; posting-host=80.176.151.208; posting-account=e1CBswoAAACHfb-egdiJeDKz3WQXJQFe
User-Agent G2/1.0
X-Google-Web-Client true
X-Google-Header-Order HUALESNKRC
X-HTTP-UserAgent Mozilla/5.0 (Macintosh; Intel Mac OS X 10.6; rv:5.0.1) Gecko/20100101 Firefox/5.0.1,gzip(gfe)
Xref x330-a1.tempe.blueboxinc.net comp.lang.java.programmer:6661

Show key headers only | View raw


Hi all.

I'm building a plugin loader. I want this loader to be able to load
from .jar files, which may contain multiple classes per plugin. So,
all of these classes need to be loaded in.

However, I don't want to load classes that already exist, e.g. I don't
want there to be the possibility of plugins loading classes which
would conflict with classes already part of the application.

I can easily check if classes are already present in the classpath by
using a method such as:

  private boolean known( String className )
  {
    try
    {
      Class c = Class.forName( className );
      return true;
    }
    catch( ClassNotFoundException cnfe )
    {
      return false;
    }
  }

This will cause a plugin to be rejected if it includes any class which
can be found. But, since plugins should really contain classes defined
in a unique package, I don't think this will cause a problem.

Is there a better way of identifying if plugins are redefining
existing classes, or otherwise creating a potential problem? Or, is
there no possibility of a potential conflict due to the way that
custom classloaders work?

Back to comp.lang.java.programmer | Previous | NextNext in thread | Find similar


Thread

Detecting if a class is already known Ross <rossclement@gmail.com> - 2011-07-29 09:47 -0700
  Re: Detecting if a class is already known markspace <-@.> - 2011-07-29 10:44 -0700
    Re: Detecting if a class is already known Lew <lewbloch@gmail.com> - 2011-08-02 07:51 -0700
  Re: Detecting if a class is already known Arne Vajhøj <arne@vajhoej.dk> - 2011-08-05 22:21 -0400

csiph-web