meilisearch / meilisearch-java

Java client for Meilisearch

Home Page:https://meilisearch.com

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

InterruptException should not be ignored

junghoon-vans opened this issue · comments

Description
InterruptException in the waitForTask() method should not be ignored.
The current code is likely to delay thread termination or lose the thread's interrupt information.

Basic example

It is required to re-interrupt before throwing a MeilisearchTimeoutException.

void waitForTask(int taskUid, int timeoutInMs, int intervalInMs) throws MeilisearchException {
    // ...

    while (status == null
            || (!status.equals(TaskStatus.SUCCEEDED) && !status.equals(TaskStatus.FAILED))) {
        if (elapsedTime >= timeoutInMs) {
            throw new MeilisearchTimeoutException();
        }
        task = this.getTask(taskUid);
        status = task.getStatus();
        try {
            Thread.sleep(intervalInMs);
        } catch (Exception e) { // It is InterruptException
            Thread.currentThread().interrupt(); // re-interrupt line here.
            throw new MeilisearchTimeoutException();
        }
        elapsedTime = new Date().getTime() - startTime;
    }
}

Other

More information about this can be found in the following sonar rules RSPEC-2142.