Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 5 of 5

Thread: Generate IllegalAccessException

  1. #1
    Junior Member
    Join Date
    Dec 2012
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Generate IllegalAccessException

    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:
    #[code = java]
    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();
    }
    }
    [/code]
    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.


  2. #2
    Member
    Join Date
    Feb 2012
    Posts
    173
    Thanks
    6
    Thanked 10 Times in 10 Posts

    Default Re: Generate IllegalAccessException

    If you want more, then, your going to have to post more code. What type is "offset"?

    On an unrelated note post code using the # [code=java][/code] tags for formatting and making the code easier to read.

  3. #3
    Junior Member
    Join Date
    Dec 2012
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Generate IllegalAccessException

    Quote Originally Posted by aesguitar View Post
    If you want more, then, your going to have to post more code. What type is "offset"?

    On an unrelated note post code using the # [code=java][/code] tags for formatting and making the code easier to read.

    The offset is of type Field.

  4. #4
    Member
    Join Date
    Feb 2012
    Posts
    173
    Thanks
    6
    Thanked 10 Times in 10 Posts

    Default Re: Generate IllegalAccessException

    Ok, what type is "text"?

  5. #5
    Junior Member
    Join Date
    Dec 2012
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Generate IllegalAccessException

    Quote Originally Posted by aesguitar View Post
    If you want more, then, your going to have to post more code. What type is "offset"?

    On an unrelated note post code using the # [code=java][/code] tags for formatting and making the code easier to read.
    The text and pattern both are of type String

Similar Threads

  1. Generate users id
    By sante in forum Algorithms & Recursion
    Replies: 5
    Last Post: October 6th, 2011, 11:29 AM
  2. [SOLVED] Generate UserID?
    By sukuiichuu in forum What's Wrong With My Code?
    Replies: 5
    Last Post: September 18th, 2011, 08:50 PM
  3. loop generate?
    By minotaurus in forum Loops & Control Statements
    Replies: 3
    Last Post: March 14th, 2011, 02:41 PM
  4. How do you generate javadoc?
    By javapenguin in forum Java IDEs
    Replies: 15
    Last Post: November 27th, 2010, 08:12 PM

Tags for this Thread