/** * @test * @bug 7088367 * @summary SourceDataLine.write and TargetDataLine.read don't throw ArrayIndexOutOfBoundsException * @author Alex Menkov */ import javax.sound.sampled.AudioSystem; import javax.sound.sampled.DataLine; import javax.sound.sampled.Line; import javax.sound.sampled.LineUnavailableException; import javax.sound.sampled.Mixer; import javax.sound.sampled.SourceDataLine; import javax.sound.sampled.TargetDataLine; public class DataLine_ArrayIndexOutOfBounds { static int total = 0; static int failed = 0; // shared buffer for all tests static final byte[] buffer = new byte[5000000]; // the class describes different test scenarios (buffer properties) static abstract class Scenario { abstract int getBufferOffset(DataLine line); abstract int getBufferLength(DataLine line); } // scenarios to tests static Scenario[] scenarios = new Scenario[]{ new Scenario() { public String toString() { return "offset is near Integer.MAX_VALUE"; } public int getBufferOffset(DataLine line) { return Integer.MAX_VALUE - 4096; } public int getBufferLength(DataLine line) { return 65536; } }, new Scenario() { public String toString() { return "offset is less than buffer.length, length is large"; } int getBufferOffset(DataLine line) { return buffer.length / 10; } int getBufferLength(DataLine line) { return Integer.MAX_VALUE - getBufferOffset(line) + 4096; } } }; public static void main(String[] args) throws Exception { Mixer.Info[] infos = AudioSystem.getMixerInfo(); log("" + infos.length + " mixers detected"); for (int i=0; i