• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Generate IllegalAccessException

 
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Bartender
Posts: 825
5
Python Ruby Java
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Please BeForthrightWhenCrossPostingToOtherSites (link).

Welcome to the Ranch!
 
Nirav Nagda
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am trying MockIto also and when I try to mock Field class

Field mockIT = Mockito.mock(Field.class);
Mockito.doCallRealMethod().when(mockIT).getInt(String.class);
mockIT.getInt(str);

output:

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
 
Do you pee on your compost? Does this tiny ad?
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic