Electrical Fire

Quality Assurance

Sample Test 3

  

This simple test checks if an index is within the bounds of the array. if it isn't then aaload should throw an ArrayIndex-OutOfBounds-Exception.

class IndexOutOfBounds
{
	static final int len=10;

	int method()
	{
		Object arrayref[] = new Object[len];
		Oject obj;

		try {
			obj = arrayref[-1];
			return 2;
		} catch (ArrayIndexOutOfBoundsException e){
			}
		
		try {
			obj = arrayref[len];
			return 2;
		} catch (ArrayIndexOutOfBoundsException e) {
			}

		return 0;
	}
	
	public static void main(String[] args)
	{
		if ( method() == 0 ) System.out.println("passed");
		else System.out.println("failed");
	}

}