Summary
-------
The `java.awt.Robot.delay(int)` method is under-specified and has surprising behavior. The method is re-specified to clearly specify how it behaves with thread interruption and the side effect of printing a stack trace is removed.
Problem
-------
- If the `delay` method is invoked with the interrupt status set, or a thread blocked in `delay` is interrupted, then it clears the interrupt status, prints a stack trace, and completes without waiting the specified time.
- Due to the method being synchronized, if several threads invoke `delay` on the same Robot instance then they will queue up and delay sequentially.
Solution
--------
- Do not print the stack trace to stderr
- Re-assert the "interrupt" flag if the thread was interrupted
- Remove the synchronization to avoid queueing
- Clarify the spec on what happens if the thread is interrupted
Specification
-------------
src/java.desktop/share/classes/java/awt/Robot.java
/**
* Sleeps for the specified time.
- * To catch any {@code InterruptedException}s that occur,
- * {@code Thread.sleep()} may be used instead.
+ * <p>
+ * If the invoking thread is interrupted while waiting, then it will
+ * return immediately with the interrupt status set. This method
+ * does nothing if invoked with the interrupt status set.
*........
*........
*/
- public synchronized void delay(int ms) {
+ public void delay(int ms) {