Whitebox.setInternalState doesn't work with final properties?

1,111 views
Skip to first unread message

newto...@gmail.com

unread,
Jul 28, 2013, 9:21:40 AM7/28/13
to powe...@googlegroups.com
Hi,

I need to assign a mock to a private static final field, and was under the impression that Whitebox.setInternalState would handle that.

However, when the field is final, if fails with an IllegalAccessException.

Thoughts?


Johan Haleby

unread,
Jul 28, 2013, 3:41:22 PM7/28/13
to powe...@googlegroups.com
That's because the field is static and final at the same time and thus you can't change the value (unless you change the value in memory which Whitebox doesn't support). Whitebox uses reflection and thus cannot change static final fields.

By suppressing static initializers you can remove set the value to a default state (such as null) if that would help.

/Johan





--
You received this message because you are subscribed to the Google Groups "PowerMock" group.
To unsubscribe from this group and stop receiving emails from it, send an email to powermock+...@googlegroups.com.
To post to this group, send email to powe...@googlegroups.com.
Visit this group at http://groups.google.com/group/powermock.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

Reply all
Reply to author
Forward
0 new messages