Name: gm110360 Date: 02/10/2004
FULL PRODUCT VERSION :
java version "1.5.0-beta"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.5.0-beta-b32c)
Java HotSpot(TM) Client VM (build 1.5.0-beta-b32c, mixed mode)
ADDITIONAL OS VERSION INFORMATION :
Microsoft Windows 2000 [Version 5.00.2195]
A DESCRIPTION OF THE PROBLEM :
If multiple threads are performing certain security or JCE operations simultaneously (e.g. generating key pairs), and if one or more of those threads is in the "interrupted" state, then an InterruptedException is thrown. I have encountered this behavior intermittently while performing encryption using the JCE (in a test server application), and also while generating key pairs (in the example program below). I'm not sure if this behavior is limited to calling security/JCE methods or not.
I should not be receiving an InterruptedException, because it is a checked exception, and is not declared to be thrown from the security/JCE methods that I am calling. Furthermore, the stack trace seems to be incorrect, and it varies between different Java versions and different test machines.
I'm unware of any documentation indicating that it is dangerous to leave a thread in the interrupted state while that thread is calling Java API methods. If it is indeed dangerous to do so, I feel that this should be clearly indicated in the Java thread documentation/tutorial.
The following link contains a discussion between developers regarding this problem:
Note: I also experience similiar behavior running the test program using the BouncyCastle security provider with Java 1.1
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
Run the attached program.
EXPECTED VERSUS ACTUAL BEHAVIOR :
I expect to see the message "Keys successfully generated" 5 times.
I receive the message "Keys successfully generated" once, and 4 InterruptedExceptions.
ERROR MESSAGES/STACK TRACES THAT OCCUR :
When compiled/run with Java 1.5.0:
When compiled/run with Java 1.4.2:
This bug can be reproduced always.
---------- BEGIN SOURCE ----------
public class GenerateKeyTest extends Thread
public void run()
interrupt(); // Comment out this line and it works OK
System.out.println("About to generate keys");
KeyPairGenerator kpg = KeyPairGenerator.getInstance("RSA");
System.out.println("Keys successfully generated");
catch (Exception e)
public static void main(String args)
for (int i = 0; i < 5; i++)
---------- END SOURCE ----------
CUSTOMER SUBMITTED WORKAROUND :
The workaround is to ensure that you never interrupt() a thread while it is calling any methods in the security classes (and possibly other Java API classes as well). This can be achieved with synchronization.
(Incident Review ID: 238237)