JDK-6318474 : Unexcepted exception thrown "java.lang.IllegalArgumentException: invalid loop start point: 30389"
  • Type: Bug
  • Component: client-libs
  • Sub-Component: javax.sound
  • Affected Version: 6
  • Priority: P3
  • Status: Closed
  • Resolution: Not an Issue
  • OS: generic
  • CPU: generic
  • Submitted: 2005-09-01
  • Updated: 2011-01-19
  • Resolved: 2005-09-02
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
JDK 6
6Resolved
Related Reports
Relates :  
Description
import javax.sound.midi.*;
import java.io.*;

public class test302 extends TRTest {

    private int failed = 0;
    private Sequence s = null;
    private Sequencer seq = null;

    public test302() {
	theTestFocus = "MIDI sequencer";
	theTestDescription = "Verify that sequencer looping works correctly (4204105).";
        printTestInfo();
    }


    // returns if the sequencer looped back or continued past the endpoint
    private boolean waitForEndPoint() throws Exception {
	long endPoint = seq.getLoopEndPoint();
	if (endPoint == -1) {
            endPoint = seq.getTickLength() - 1;
	}
        long pos = seq.getTickPosition();
	int noMovement = 0;
	long oldPos = pos;
	while (true) {
            long thisPos = seq.getTickPosition();
            if (thisPos < oldPos) {
		// looped back
		return true;
            }
            else if (thisPos >= endPoint) {
		// reached end point
		return false;
            }
            sleep(10);
            if (oldPos == thisPos) {
		noMovement++;
		if (noMovement > 100) {
			out("ERROR: Sequencer did not advance for a long time!");
			failed++;
			break;
		}
            } else {
		oldPos = thisPos;
            }
	}
	return false;
    }

    private void loopTest(long start, long end, int times) throws Exception {
	out("Loop: start="+start+"  end="+end+"	 loopCount="+times);
	seq.setLoopStartPoint(start);
	seq.setLoopEndPoint(end);
	seq.setLoopCount(times);
	seq.setTickPosition(start);
	if (!seq.isRunning()) {
		out("Starting sequencer");
		seq.start();
	}
	boolean loopedBack = false;
	for (int i = times; i > 0; i--) {
		out("Loop "+i+"... waiting...");
		loopedBack = waitForEndPoint();
		if (!loopedBack) {
			out("  ERROR: Did not loop back!");
			failed++;
			break;
		}
	}
    }

    private void loopTest() throws Exception {
	int start = 45 * 4 *120 - 10;
	loopTest(start, start + (120 * 12), 3);
	loopTest(start, start + (120 * 12), 0);
	seq.stop();
	loopTest(start, start + (120 * 12), 1);
	loopTest(start, start + (120 * 12), 1);
	loopTest(0, 120 * 12, 2);
	seq.stop();
	loopTest(0, 120 * 6, 6);
	long end = seq.getTickLength();
	loopTest(end-(120*12), end-1, 3);
	loopTest(end-(120*8), -1, 3);
//This is the line where the test failed.  'end' is equal to 30389
	loopTest(end-(120*12), end, 3);
    }

    public boolean runTest() {
	Transmitter transmitter = null;
	Receiver testReceiver = null;
	 Synthesizer syn = null;
	 Receiver synReceiver = null;
        try {
            // dvorak9.mid is 1:44 min:sec long -- should be enough for all kinds of testing
	File file = SoundFinder.getSoundFile("MIDI/dvorak9.mid");
	s = MidiSystem.getSequence(file);
	seq = MidiSystem.getSequencer(false);
	seq.open();
	seq.setSequence(s);

	transmitter = seq.getTransmitter();
	try {
			syn = MidiSystem.getSynthesizer();
			syn.open();
			synReceiver = syn.getReceiver();
			transmitter.setReceiver(synReceiver);
	} catch(Exception e) {
			out("Cannot get synthesizer: "+e);
			if (synReceiver != null) {
				synReceiver.close();
				synReceiver = null;
			}
			if (syn != null) {
				syn.close();
				syn = null;
			}
            }
	if (synReceiver == null) {
			out("No synthesizer available. Using test Receiver.");
			testReceiver = new TestReceiver();
			transmitter.setReceiver(testReceiver);
            }

	out("Starting sequence.");
	seq.start();
	out("Waiting for 1 second");
	sleep(1000);

	loopTest();

	} catch (Throwable t) {
			t.printStackTrace();
			out("Exception caused this test to fail.");
			failed++;
        }
	 out("Closing devices");
	 if (synReceiver != null) synReceiver.close();
	 if (syn != null) syn.close();
	 if (testReceiver != null) testReceiver.close();
        if (transmitter != null) transmitter.close();
	if (seq != null) seq.close();
	 return (failed==0);
    }

    private static Object lock = new Object();
    private static void sleep(int milliseconds) {
	// prevent locking forever
	if (milliseconds <= 0) {
		milliseconds = 10;
	}
	try {
			Thread.sleep(milliseconds);
	} catch (InterruptedException e) {
			e.printStackTrace();
            }
    }

    private static void out(String s) {
	System.out.println(s);
	 System.out.flush();
    }


    private static class TestReceiver implements Receiver {
	public void send(MidiMessage message, long timestamp) {
        }

	public void close() {
        }
    }


    //_______________________________________________
    //	Method: main
    //_______________________________________________
    public static void main(String[] args) {
	TRTest thisTest = new test302();

	boolean result = thisTest.runTest();
	 if (result) {
	System.out.println("Passed");
	 } else {
	System.out.println("FAILED!");
        }
	 if (result) {
	System.exit(0);
	 } else {
	System.exit(1);
        }
    }

Comments
EVALUATION This is not a JavaSound bug, it's test bug. Really exception thrown 2 lines more early: loopTest(0, 120 * 6, 6); long end = seq.getTickLength(); loopTest(end-(120*12), end-1, 3); <- this line thrown the exception in the loopTest method you set loop start & end point. start point = end-(120*12) == 30389, but end point keeps its value from previous call (prev. loopTest set end point to 120*6 = 720). So you try set start point behind end point and Sequencer.setLoopStartPoint throws exception as documentation specifies. To prevent this reset end point ( seq.setLoopEndPoint(-1) ) before set start point.
02-09-2005