Thanks Arrin, this worked perfectly.  The Repository
class was the missing link.  I found that in the
environment I am working in the classes loaded by BCEL
are not in the classpath, which is why I was not able the
use Class.forName, but the Repository provides equivalent
functionality for my purposes.

-Elliot

-----Original Message-----
From: Arrin Daley [mailto:[EMAIL PROTECTED] 
Sent: Wednesday, December 05, 2007 2:54 PM
To: BCEL Users List
Subject: Re: InstructionHandle to Declared Exceptions

Hi Elliot

You could try using 'Repository.loadClass' to load a
class (which should use your existing class loading
hierarchy) this will produce a 'JavaClass' object from
which you will be able to create a 'ClassGen' to get a
'MethodGen', or create a 'MethodGen' from the 'Method' 
(JavaClass.getMethods() then search for name or
signature) your concerned with. From there 'MethodGen'
has a method 'getExceptions()' 
which returns an array of Strings for the exception
names. I think Repository uses the normal java class
loading mechanisms so if these were causing your troubles
this may still be the case if so have a look at the
interface 'org.apache.bcel.util.Repository'
implementations of which allow you to specify a
classloader or generally have other options.

Hope this helps

Bye Arrin

Elliot Barlas wrote:

>I have an InstructionHandle containing an InvokeVirtual
instruction and 
>I would like to get the list of all declared exceptions
thrown by the 
>virtual method invocation.  I have tried the following:
>
>1. Get the InvokeVirtual instruction from handle 2. Get
the 
>ReferenceType from the instruction 3. Cast the
ReferenceType to an 
>ObjectType when safe to do so.
>4. Get the class name from the ObjectType 5. Get the
Class object from 
>the class name via
>Class.forName(className)
>6. Get an array of methods for the Class 7. Get the
method name from 
>the InvokeVirtual instruction 8. Find the
java.lang.reflect.Method in 
>the array with the given name 9. Get an array of
exception Classes from 
>the method
>
>This should be sufficient, but in the environment that I
am working in, 
>there are multiple class loaders and the class lookup
(Class.forName) 
>is failing.  Does anyone know how to do something
equivalent in BCEL 
>alone without requiring the use of Java reflection or
class lookups?
>
>Thanks,
>Elliot
>
>  
>

--
Conventional wisdom says to know your limits. To know
your limits you need to find them first. Finding you
limits generally involves getting in over your head and
hoping you live long enough to benefit from the
experience. That's the fun part.


---------------------------------------------------------
------------
To unsubscribe, e-mail:
[EMAIL PROTECTED]
For additional commands, e-mail:
[EMAIL PROTECTED]


---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to