This week's giveaway is in the Spring forum.
We're giving away four copies of REST with Spring (video course) and have Eugen Paraschiv on-line!
See this thread for details.
The moose likes Java in General and the fly likes Generate IllegalAccessException Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of REST with Spring (video course) this week in the Spring forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "Generate IllegalAccessException" Watch "Generate IllegalAccessException" New topic

Generate IllegalAccessException

Nirav Nagda

Joined: Dec 09, 2012
Posts: 5
I am testing an algorithm for StringSearch and the algorithm has many IllegalAccessExceptions in it.

I wanted to test that the code is working fine with the exceptions...and it is important also to test them as they call some functions when the exception occurs.

I just wanted to know how can i implicitly generate the exception.

I am trying to use the Java Security Manager but don't know how to use it to revoke the program's access to String class.

below is the code that I am testing:
try {
int o = offset.getInt(text);
char[] t = (char[]) value.get(text);
return instance.searchChars(t, textStart + o, textEnd + o,
getChars(pattern), processed)
- o;

} catch (IllegalAccessException ex) {
synchronized (activeStringAccess) {
activeStringAccess = new StringAccess();

in above code "offset.getInt(text)" generates the IllegalAccessException
I have tried to use MockIt but MockIt cannot mock the class for getInt i.e. Field.
Kemal Sokolovic

Joined: Jun 19, 2010
Posts: 825

Please BeForthrightWhenCrossPostingToOtherSites (link).

Welcome to the Ranch!

The quieter you are, the more you are able to hear.
Nirav Nagda

Joined: Dec 09, 2012
Posts: 5
I know but I did not get reply there and I am stuck up...

its like the solution there does work but the situation I am in the steps given there just fail

Can anyone here help
Nirav Nagda

Joined: Dec 09, 2012
Posts: 5
I am trying MockIto also and when I try to mock Field class

Field mockIT = Mockito.mock(Field.class);


Exception in thread "main" org.mockito.exceptions.base.MockitoException:
Cannot mock/spy class java.lang.reflect.Field
Mockito cannot mock/spy following:
- final classes
- anonymous classes
- primitive types

does any one know how can I go forward with this
I agree. Here's the link:
subject: Generate IllegalAccessException
It's not a secret anymore!