Skip to content

Conversation

@tranleduy2000
Copy link
Collaborator

Interrupt exceptions should be rethrows to top-level call.
Some internal libraries, like JAS and Apfloat, especially the Apfloat library catch the InterruptException, it also clears the current interrupt flag of current thread (I'm not understand why this is intentional).

If we catch all RuntimeException without rethrowing, it will prevent current thread from stopping and run forever.

public class ApfloatContext
    implements Cloneable
{
    /**
     * Checks if the current thread was interrupted. If yes, throws an
     * {@link ApfloatInterruptedException}.<p>
     *
     * This method calls {@link Thread#interrupted()} so if the thread was
     * interrupted, it clears the interrupted status.
     *
     * @throws ApfloatInterruptedException If the current thread was interrupted.
     *
     * @since 1.14.0
     */

    public static void checkInterrupted()
        throws ApfloatInterruptedException
    {
        if (Thread.interrupted())
        {
            throw new ApfloatInterruptedException("Interrupted", "interrupted");
        }
    }
}

@tranleduy2000 tranleduy2000 requested a review from axkr September 19, 2024 10:17
@axkr axkr merged commit 6f9581e into master Sep 19, 2024
4 checks passed
@tranleduy2000 tranleduy2000 deleted the rethrows-interrupt branch September 20, 2024 13:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants