Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-4992463

ClassLoading fails if the Thread's interrupt status is set

    Details

    • Type: Bug
    • Status: Closed
    • Priority: P4
    • Resolution: Not an Issue
    • Affects Version/s: 5.0
    • Fix Version/s: None
    • Component/s: core-libs
    • Labels:
    • Subcomponent:
    • CPU:
      x86
    • OS:
      windows_2000

      Description

      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:

      http://groups.google.com/groups?hl=en&lr=&ie=UTF-8&oe=UTF-8&threadm=84544f8d.0312022135.4658490f%40posting.google.com&rnum=2

      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 :
      EXPECTED -
      I expect to see the message "Keys successfully generated" 5 times.
      ACTUAL -
      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:

      java.lang.InterruptedException
              at sun.security.jca.GetInstance.getServices(GetInstance.java:96)
              at java.security.KeyPairGenerator.getInstance(KeyPairGenerator.java:165)
              at GenerateKeyTest.run(GenerateKeyTest.java:11)

      When compiled/run with Java 1.4.2:

      java.lang.InterruptedException
              at sun.security.provider.SecureRandom.engineNextBytes
      SecureRandom.java: 168)
              at java.security.SecureRandom.nextBytes(SecureRandom.java:381)
              at COM.rsa.jsafe.SunJSSE_eq.a(DashoA6275)
              at COM.rsa.jsafe.SunJSSE_df.c(DashoA6275)
              at com.sun.net.ssl.internal.ssl.JS_KeyPairGenerator.generateKeyPair(Dash
      oA6275)
              at java.security.KeyPairGenerator$Delegate.generateKeyPair(KeyPairGenerator.java:475)
              at GenerateKeyTest.run(GenerateKeyTest.java:13)


      REPRODUCIBILITY :
      This bug can be reproduced always.

      ---------- BEGIN SOURCE ----------
      import java.security.KeyPairGenerator;

      public class GenerateKeyTest extends Thread
      {
        public void run()
        {
          try
          {
            interrupt(); // Comment out this line and it works OK
            System.out.println("About to generate keys");
            KeyPairGenerator kpg = KeyPairGenerator.getInstance("RSA");
            kpg.initialize(1024);
            kpg.generateKeyPair();
            System.out.println("Keys successfully generated");
          }
          catch (Exception e)
          {
            e.printStackTrace();
          }
        }

        public static void main(String[] args)
        {
          for (int i = 0; i < 5; i++)
            new GenerateKeyTest().start();
        }
      }

      ---------- 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)
      ======================================================================

        Attachments

          Issue Links

            Activity

              People

              • Assignee:
                Unassigned
                Reporter:
                gmanwanisunw Girish Manwani (Inactive)
              • Votes:
                0 Vote for this issue
                Watchers:
                2 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved:
                  Imported:
                  Indexed: