• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

how to use reflection when static members throw exception

 
Jeanne Boyarsky
author & internet detective
Marshal
Posts: 34656
366
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?
 
Rob Spoor
Sheriff
Pie
Posts: 20545
56
Chrome Eclipse IDE Java Windows
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Jeanne Boyarsky
author & internet detective
Marshal
Posts: 34656
366
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you! I would have needed classloader in my search to find it.
 
Rob Spoor
Sheriff
Pie
Posts: 20545
56
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You're welcome
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic