import java.io.ByteArrayOutputStream;
import java.io.DataOutputStream;
import java.io.IOException;

import org.junit.Test;

public class JI9059415 {

	@Test 
	public void testArrayIndexOutOfBoundsException() throws IOException { 
		int size = Integer.MAX_VALUE / 3 + 1; 
		StringBuilder sb = new StringBuilder(size); 
		char c = 0x0800; // this character gives 3 bytes when encoded using UTF-8 
		for (int i = 0; i < size; ++i) { 
			sb.append(c); 
		} 
		ByteArrayOutputStream bos = new ByteArrayOutputStream(); 
		DataOutputStream dos = new DataOutputStream(bos); 
		String s = sb.toString(); 
		dos.writeUTF(s); //throws ArrayIndexOutOfBoundsException instead of expected UTFDataFormatException 
	} 

	@Test 
	public void testNegativeArraySizeException() throws IOException { 
		int size = Integer.MAX_VALUE / 2 + 1; 
		StringBuilder sb = new StringBuilder(size); 
		char c = 0x0800; // this character gives 3 bytes when encoded using UTF-8 
		for (int i = 0; i < size; ++i) { 
			sb.append(c); 
		} 
		ByteArrayOutputStream bos = new ByteArrayOutputStream(); 
		DataOutputStream dos = new DataOutputStream(bos); 
		String s = sb.toString(); 
		dos.writeUTF(s); //throws NegativeArraySizeException instead of expected UTFDataFormatException 
	} 
}
