Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8210231

Robot.delay() catches InterruptedException and prints stacktrace to stderr

    Details

    • Subcomponent:
    • Resolved In Build:
      b07
    • CPU:
      x86_64
    • OS:
      windows_10

      Description

      ADDITIONAL SYSTEM INFORMATION :
      x64-based PC
      Microsoft Windows 10 Pro (10.0.17134 build 17134)
      java version "1.8.0_181"
      Java(TM) SE Runtime Environment (build 1.8.0_181-b13)
      Java HotSpot(TM) 64-Bit Server VM (build 25.181-b13, mixed mode)

      A DESCRIPTION OF THE PROBLEM :
      The java.awt.Robot.delay() method calls Thread.sleep(), which has the potential of throwing an InterruptedException. If that exception occurs, Robot.delay() catches it and outputs the exception's stacktrace to the standard error stream. The JavaDoc does not mention anything about the stderr writes.

      REGRESSION : Last worked in version 8u181

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      This problem occurs at random times. But it is possible to induce it by calling Robot.delay() and then having another thread interrupt the sleeping thread.

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      Since the JavaDoc does not mention stderr writes, I suggest that Robot.delay() capture and bury the exception. This is preferable to modifying Robot.delay() to throw the exception since that method redefinition would break existing code.
      ACTUAL -
      Robot.delay() outputs the InterruptedException stacktrace to the standard error stream.

      ---------- BEGIN SOURCE ----------
      Robot robot = new Robot();
      robot.delay(10000);

      or

      robot.mouseWheel(5); // see Workaround for explanation
      ---------- END SOURCE ----------

      CUSTOMER SUBMITTED WORKAROUND :
      Note that Robot.delay() is used internally by other Robot methods. For instance, mouseWheel() -> afterEvent() -> autoDelay() -> delay(). This means that a programmer cannot alleviate this problem by simply using Thread.sleep() in place of Robot.delay().

      However, the standard error stream can be redirected to prevent the user from seeing a sporadic exception message in the output console.

      FREQUENCY : rarely


        Attachments

          Issue Links

            Activity

              People

              • Assignee:
                serb Sergey Bylokhov
                Reporter:
                webbuggrp Webbug Group
              • Votes:
                0 Vote for this issue
                Watchers:
                3 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved: