<AWT Dev> [12] Review Request: 8210231 Robot.delay() catches InterruptedException and prints stacktrace to stderr.

Philip Race philip.race at oracle.com
Sun Jul 7 23:51:05 UTC 2019


  646      * If the invoking thread is interrupted while waiting, then its interrupt
  647      * status will be set and this method returns immediately.

This is OK except for sounding a bit odd, in that  if a thread is 
interrupted why
do you need to set it again ? Rather explain the implementation I'd 
phrase this as

  646      * If the invoking thread is interrupted while waiting, then it will
  647      * return immediately with the interrupt status set.

2) However I am still worried by this change of behaviour.
We have a sequence of Robot.delay() calls in a typical test and if one
of them gets interrupted, then the next one will also return immediately ..
since the status is already but right before it returns it will again
reset the interrupt status and so the same happens to the next one :-

Consider this :-

public class I {
  public static void main(String[] args) {
    try {
    } catch (InterruptedException e) {

java I
java.lang.InterruptedException: sleep interrupted
     at java.lang.Thread.sleep(Native Method)
     at I.main(I.java:5)

Are we to update all Robot tests to clear the interrupt status before 
calling delay ?

Or should delay clear the status on entry to delay ?

Or something else ?


On 4/14/19, 8:24 PM, Sergey Bylokhov wrote:
> Hello,
> Here is another proposal:
> Bug: https://bugs.openjdk.java.net/browse/JDK-8210231
> Fix: http://cr.openjdk.java.net/~serb/8210231/webrev.01/
> 1. This version describes what happens if the thread will be 
> interrupted while waiting.
> 2. The reference to the "Thread.sleep()" was removed, because it is 
> not a part of the spec for the current method.
> 3. "synchronized" keyword was removed, because of this bug: "if two 
> threads call delay(1000) at around the same time then one of them will 
> be a delay for 2000ms".
>> Hello.
>> Please review the fix for jdk12.
>> Bug: https://bugs.openjdk.java.net/browse/JDK-8210231
>> Webrev: http://cr.openjdk.java.net/~serb/8210231/webrev.00
>> The Robot.delay() is a simple wrapper on top of Thread.sleep(), which 
>> ignores the InterruptedException. But in case of InterruptedException 
>> it prints the stack trace, which is unspecified behavior.
>> In the fix the "printStackTrace()" was removed, and the interrupted 
>> state of the thread is restored.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mail.openjdk.java.net/pipermail/awt-dev/attachments/20190707/460195b0/attachment.html>

More information about the awt-dev mailing list