United StatesChange Country, Oracle Worldwide Web Sites Communities I am a... I want to...
Bug ID: JDK-6963006 smartcardio is not mt safe - javax.smartcardio.CardException: wait mismatch
JDK-6963006 : smartcardio is not mt safe - javax.smartcardio.CardException: wait mismatch

Details
Type:
Bug
Submit Date:
2010-06-22
Status:
Resolved
Updated Date:
2012-10-23
Project Name:
JDK
Resolved Date:
2011-04-20
Component:
security-libs
OS:
windows
Sub-Component:
javax.smartcardio
CPU:
x86
Priority:
P3
Resolution:
Fixed
Affected Versions:
6u20
Fixed Versions:
6u25-rev (b21)

Related Reports
Backport:
Backport:
Backport:

Sub Tasks

Description
When trying to check from a thread whether a smartcard has been already
removed while a read/write operation is taking place in another thread
the following exception occurs:

   javax.smartcardio.CardException: wait mismatch
      at sun.security.smartcardio.TerminalImpl.waitForCard(TerminalImpl.java:103)
      at sun.security.smartcardio.TerminalImpl.waitForCardAbsent(TerminalImpl.java:120)
      at TerminalImplExample.run(TerminalImplExample.java:116)

This is an exception which should never happen, please see the source code
of waitForCard() in 
/ws/j2se/src/share/classes/sun/security/smartcardio/TerminalImpl.java

            // should never happen
            if (wantPresent != present) {
                throw new CardException("wait mismatch");

Since it does happen, I'd consider this a bug. A test case is available.
See the attached zip file TerminalImplExample.zip. It requires a card reader.

The reason why the exception occured is that waitForCard() is not prepared to 
handle other card state changes than SCARD_STATE_PRESENT = 0x0020;
With the test case we can see that for example 0x0122 occurs, which means
CHANGED PRESENT INUSE.

                                    

Comments
EVALUATION

comments from PDE review on the fix listed:
1. I think the String[] "SCARD_STATES" and probably also the dumpStatus(int) method belongs to the PCSC class better.
2. The dumpStatus(int) calls should be controlled by a system property setting. Normally, debug info like this are disabled by default.
3. Some indentation doesn't look right? For example, line 108-110 shouldn't have the same indentation?
4. The way remaining timeout is calculated on line 111 doesn't look right. The way you calculate it would lead to earlier timeout.

Detailed description is in the Activites section
                                     
2010-11-19
SUGGESTED FIX

Code review request:
http://jpsesvr.sfbay.sun.com:8080/ctetools/html/ViewDetail.jsp?index=3927

Putback request:
https://jetsvr.sfbay.sun.com:8443/BugApproval/ViewDetail.jsp?index=10458&mode=view
                                     
2011-02-03



Hardware and Software, Engineered to Work Together