• Post Reply Bookmark Topic Watch Topic
  • New Topic

Big Reflection Problem(Eclipse sees values Reflection don't)  RSS feed

 
Ioan Berciu
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi!

I have this code:

Class cls = stream.getClass();
Field addressField = cls.getDeclaredField("address");
Field portField = cls.getDeclaredField("port");
this.dataAddress = (InetAddress)addressField.get((RecvSSRCInfo)stream);
this.dataPort = portField.getInt((RecvSSRCInfo)stream);

stream is of type com.sun.media.rtp.RecvSSRCInfo

In Eclipse on Expressions window(watch) I see the fileds address and port of stream object, they have the expected values also but when I try to get these values using reflection it throws NoSuchFieldException.

Can anyone please help with this?

Thank you!
 
Ernest Friedman-Hill
author and iconoclast
Sheriff
Posts: 24217
38
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
getDeclaredField() will return a Field only if the field is defined in the exact class you're probing, but not if it's defined in a superclass. Are you sure the fields aren't defined in a superclass?
 
Jim Yingst
Wanderer
Sheriff
Posts: 18671
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The address and port fields may be declared in a superclass of the class you're looking at. The getDeclaredXXX() methods only look for things declared in that particular class. You need to check up the inheritance tree yourself using getSuperclass().
 
Jim Yingst
Wanderer
Sheriff
Posts: 18671
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
EFH, this is revenge for yesterday, isn't it?
 
Ernest Friedman-Hill
author and iconoclast
Sheriff
Posts: 24217
38
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yup
 
Ioan Berciu
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi!
Thanks for pointing out that the fields might be in a super class.
They were!

Also I would like to add that the fileds were package accessible (no access modifier: private, public or protected infront of them). So to be able to get them I set the accessible flag of each field to true:

addressField.setAccessible(true);
portField.setAccessible(true);

Only afthere setting true on accessible flag I was able to get the values
Thanks all for repllying so quick.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!