JML can't catch a violated precondition

149 Views Asked by At

In my class Test I've an array of five int named a, and the method addOne(int index) that add one to the selected cell. I wrote in JML a simple precondition to control the index passed to the method. Then I try to violate this precondition calling the method with a negative index and JML can't catch this error. What's wrong?

This is Test class:

public class Test {

 public int[] a;

 public Test(){
    a = new int[]{1,1,1,1,1};
 }

 //@ requires index>=0 && index<5;
 public void addOne(int index){
    a[index]+=1;
 }
} 

And this is the Main:

public static void main(String[] args) {
    Test t = new Test();
    t.addOne(-2);
}

That throw the exception: java.lang.ArrayIndexOutOfBoundsException: -2.

With any JML message.

0

There are 0 best solutions below