aspose file tools
The moose likes Java in General and the fly likes how to use reflection when static members throw exception Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


Win a copy of Mongo DB Applied Patterns this week in the MongoDB forum
or a resume review from Five Year Itch in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » Java in General
Reply Bookmark "how to use reflection when static members throw exception" Watch "how to use reflection when static members throw exception" New topic
Author

how to use reflection when static members throw exception

Jeanne Boyarsky
internet detective
Marshal

Joined: May 26, 2003
Posts: 26138
    
  66

I feel like this has been asked before and I'm not finding the right search terms. (reflection and static are too narrow.) Can someone help an internet detective?

I'm trying to use reflection to get the Class object from a string package/class name. Using Class.forName works fine for most of my classes. The few that fail have a static field that calls a method that reads from a property file. Which fails because in my test environment that property isn't there.

I can't change the code that makes the static call. (And I need reflection for some analysis on it.) Is it possible to do this? How?


[Blog] [JavaRanch FAQ] [How To Ask Questions The Smart Way] [Book Promos]
Blogging on Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, OCAJP, OCPJP beta, TOGAF part 1 and part 2
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19214

Try commenting out these last two lines one by one. You can even use reflection, as long as you don't try to invoke the methods / get the field values / set the field values. But listing fields and methods, not a problem.


SCJP 1.4 - SCJP 6 - SCWCD 5
How To Ask Questions How To Answer Questions
Jeanne Boyarsky
internet detective
Marshal

Joined: May 26, 2003
Posts: 26138
    
  66

Thank you! I would have needed classloader in my search to find it.
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19214

You're welcome
 
I agree. Here's the link: http://jrebel.com/download
 
subject: how to use reflection when static members throw exception
 
Similar Threads
invoking static methods on Class
get all references to a Java method in source code
Can I put security perm on a class?
Is Reflection My Only Option?
array length?