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

(smartcardio) CardTerminal.connect() throws CardException instead of CardNotPresentException

    Details

      Backports

        Description

        Problem description:
        ====================
        Method "public abstract javax.smartcardio.CardTerminal.connect(String protocol)" of Sun's implementation of "PC/SC" smartcard reader I/O engine works wrong on Linux. In case when card is absent in card reader this method throws CardException instead of CardNotPresentException, in the same time method "javax.smartcardio.CardTerminal.isCardPresent()" works properly - it returns "false".
        This bug is specific for Linux only, it is absent on Windows.

        Test system description:
        SuSE 10.0 out of box on Intel Pentium IV;
        GemPCTwin (serial version) smartcard reader.
        PC/SC framework and drivers from GemPlus site (SuSE package):
        http://support.gemplus.com/gemdownload/readers/drivers.aspx?prodid=13&osid=11

        There is a minimized test below:
        Minimized test:
        ===============
        ---test.java---
        import javax.smartcardio.*;
        public class test {

            public static void main(String[] args) {
                CardTerminals terminals = TerminalFactory.getDefault().terminals();
                try {
                    if (!terminals.list().isEmpty()) {
                        CardTerminal terminal = terminals.list().get(0);
                        
                        if(!terminal.isCardPresent()) {
                            System.out.println("CardTerminal.isCardPresent():"
                                    + terminal.isCardPresent());
                            try {
                                Card card = terminal.connect("*");
                            } catch (CardNotPresentException e) {
                                System.out.println("Bug is absent: " + e);
                            } catch(CardException e) {
                                e.printStackTrace();
                            }
                            
                        } else {
                            System.out.println("Bug cannot be reproduced: Card is"
                                    + " present");
                        }
                        
                    } else {
                        System.out.println("Bug cannot be reproduced:There are no"
                                + " any card terminals");
                    }
                } catch(CardException e) {
                    
                }

            }
        }

        ---test.java---

        Minimized test output:
        ======================
        [vs158239@vsmelov bug]$ javac test.java
        [vs158239@vsmelov bug]$ java -cp ./ test
        CardTerminal.isCardPresent():false
        javax.smartcardio.CardException: connect() failed
                at sun.security.smartcardio.TerminalImpl.connect(TerminalImpl.java:67)
                at test.main(test.java:14)
        Caused by: sun.security.smartcardio.PCSCException: SCARD_E_NO_SMARTCARD
                at sun.security.smartcardio.PCSC.SCardConnect(Native Method)
                at sun.security.smartcardio.CardImpl.<init>(CardImpl.java:65)
                at sun.security.smartcardio.TerminalImpl.connect(TerminalImpl.java:61)
                ... 1 more

          Activity

          Hide
          fhho Frances Ho added a comment -
          Please assign someone to look into this conformance issue.
          Show
          fhho Frances Ho added a comment - Please assign someone to look into this conformance issue.
          Hide
          dbessono Dmitry Bessonov added a comment -
          This is a conformance issue,
          the following testcase will fail due to this
          api/javax_smartcardio/CardTerminal/index.html#Exceptions[CNPE2001]
          Show
          dbessono Dmitry Bessonov added a comment - This is a conformance issue, the following testcase will fail due to this api/javax_smartcardio/CardTerminal/index.html#Exceptions[CNPE2001]
          Hide
          hgupdate HG Updates added a comment -
          URL: http://hg.openjdk.java.net/jdk9/dev/jdk/rev/556549260289
          User: igerasim
          Date: 2016-08-30 12:32:37 +0000
          Show
          hgupdate HG Updates added a comment - URL: http://hg.openjdk.java.net/jdk9/dev/jdk/rev/556549260289 User: igerasim Date: 2016-08-30 12:32:37 +0000
          Hide
          hgupdate HG Updates added a comment -
          URL: http://hg.openjdk.java.net/jdk9/jdk9/jdk/rev/556549260289
          User: lana
          Date: 2016-09-07 20:26:15 +0000
          Show
          hgupdate HG Updates added a comment - URL: http://hg.openjdk.java.net/jdk9/jdk9/jdk/rev/556549260289 User: lana Date: 2016-09-07 20:26:15 +0000

            People

            • Assignee:
              igerasim Ivan Gerasimov
              Reporter:
              vsmelovsunw Vladimir Smelov (Inactive)
            • Votes:
              0 Vote for this issue
              Watchers:
              7 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved:
                Imported:
                Indexed: