diff --git a/core/src/main/java/org/jruby/RubyThread.java b/core/src/main/java/org/jruby/RubyThread.java index 5c5fe9f69f6..d0c32bd8877 100644 --- a/core/src/main/java/org/jruby/RubyThread.java +++ b/core/src/main/java/org/jruby/RubyThread.java @@ -331,8 +331,7 @@ private int getInterrupts() { } private IRubyObject pendingInterruptDeque(ThreadContext context, int timing) { - for (Iterator iterator = pendingInterruptQueue.iterator(); iterator.hasNext();) { - IRubyObject err = iterator.next(); + for (IRubyObject err = pendingInterruptQueue.peek(); err != null;) { int maskTiming = pendingInterruptCheckMask(context, err); switch (maskTiming) { @@ -340,7 +339,7 @@ private IRubyObject pendingInterruptDeque(ThreadContext context, int timing) { if (timing != INTERRUPT_ON_BLOCKING) break; case INTERRUPT_NONE: case INTERRUPT_IMMEDIATE: - iterator.remove(); + pendingInterruptQueue.clear(); return err; case INTERRUPT_NEVER: break;