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.