[1.1.4] App::close(): should return true if success, false in other cases --- fixed 2019-01-16 build#186

Bug #1811938 reported by RaiMan on 2019-01-16
8
This bug affects 1 person
Affects Status Importance Assigned to Milestone
Sikuli
Critical
RaiMan

Bug Description

I am building a SikuliX automation script in Java and confused about the expected results of the .close() method. Inside of Sikuli's App class, the close method is as follows:

  /**
   * tries to close the app defined by this App instance, waits max given seconds for the app to no longer be running
   *
   * @return this or null on failure
   */
  public boolean close(int waitTime) {
    if (!isRunning()) {
      log("App.close: not running: %s", this);
      return false;
    }
    if (_osUtil.close(this)) {
      int timeTowait = maxWait;
      if (waitTime > 0) {
        timeTowait = waitTime;
      }
      while (isRunning(0) && timeTowait > 0) {
        timeTowait--;
      }
    }
    if (!isValid()) {
      log("App.close: %s", this);
    } else {
      log("App.close: did not work: %s", this);
      return true;
    }
    return false;
  }

The part in question for me is the return. My understanding is that, since it returns a boolean, it would be true if the close was a success, and false if the close failed. However, this code does the opposite. Based on my flawed(?) understanding of this logic, I initially wrote my code like so,

if (myApp.close()) {
    System.out.println("closed.");
    isAppClosed = true;
} else {
    System.out.println("NOT closed!");
    isAppClosed = false;
}

This is having the opposite result of what I want, as the application is successfully closing, BUT the test is failing because "NOT closed" is being printed.

Have I found a bug, or am I missing something?

Thanks.

I cross-posted on Stackoverflow here: https://stackoverflow.com/q/54201161/185967

RaiMan (raimund-hocke) on 2019-01-16
Changed in sikuli:
status: New → Fix Committed
importance: Undecided → Critical
assignee: nobody → RaiMan (raimund-hocke)
milestone: none → 1.1.4
summary: [1.1.4] App::close(): should return true if success, false in other
- cases
+ cases --- fixed 2019-01-16 build#186
To post a comment you must log in.
This report contains Public information  Edit
Everyone can see this information.

Other bug subscribers