4 Replies Latest reply on Sep 30, 2004 9:34 AM by bill.burke

    Aspect for replacing Class.forName()?

    duslow

      Has anyone already written an Aspect for replacing Class.forName() with Thread.currentThread().getContextClassLoader().loadClass()?

      This would be useful for deploying 3rd party jars in JBoss where one doesn't have the source nor do they want, or legally can't decompile the classes to make the change.

      Seems to me that this could included as one of the default aspects included in the JBoss distribution since it seems to be a common problem users run into.

      I'm not sure of all the steps involved since I'm by no means an aspect expert. The thought just occurred to me and I thought I'd bounce it off you aspect experts to see if it's feasible.

      Dustin

        • 1. Re: Aspect for replacing Class.forName()?
          bill.burke

          Can you spec this out more? I don't understand what you mean.

          Bill

          • 2. Re: Aspect for replacing Class.forName()?
            duslow

            One example is what Adrian wrote about in this thread http://www.jboss.org/index.html?module=bb&op=viewtopic&t=50041Class.forName()

            The important snippet is ..

            "You should always use Thread.currentThread().getContextClassLoader().loadClass() which avoids Sun's broken caching.

            But I have never seen this not load a class, only load an old class giving you a variant of ClassCastException."

            I've had similiar issues when bundling 3rd party JDBC drivers in, for example, an ear file. The typical workaround for the problems caused by with Class.forName("SomeClass") is to put the jar in the /lib directory instead of the ear.

            I was just thinking that it would be helpful (especially with closed source 3rd party libs) to have a default JBoss Aspect that could be turned on to automatically replace Class.forName("SomeClass") with Thread.currentThread().getContextClassLoader().loadClass("SomeClass").

            Dustin

            • 3. Re: Aspect for replacing Class.forName()?
              duslow

              (My apologies for a double post .. my last post was cut off)

              One example is what Adrian wrote about in this thread http://www.jboss.org/index.html?module=bb&op=viewtopic&t=50041Class.forName()

              The important snippet is ..

              "You should always use Thread.currentThread().getContextClassLoader().loadClass() which avoids Sun's broken caching.

              But I have never seen this not load a class, only load an old class giving you a variant of ClassCastException."

              I've had similiar issues when bundling 3rd party JDBC drivers in, for example, an ear file. The typical workaround for the problems caused by with Class.forName("SomeClass") is to put the jar in the server_target/lib directory instead of the ear.

              I was just thinking that it would be helpful (especially with closed source 3rd party libs) to have a default JBoss Aspect that could be turned on to automatically replace Class.forName("SomeClass") with Thread.currentThread().getContextClassLoader().loadClass("SomeClass").

              Dustin

              • 4. Re: Aspect for replacing Class.forName()?
                bill.burke

                oh, ok, good idea....

                i