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

(smartcardio) CardTerminal Ctor does not throw NPE for null parameter

    • Icon: Bug Bug
    • Resolution: Duplicate
    • Icon: P3 P3
    • None
    • 6
    • security-libs
    • None

      Problem description:
      ====================

      The javadoc for constructor of the javax.smartcardio.CardTerminal class
      states as follows:
      ---Excerpt-from-spec---
      protected CardTerminal(TerminalFactory factory)
      Constructs a new CardTerminal object.

      This constructor is called by subclasses only. Application should call terminals() or getTerminal() to obtain a CardTerminal object.


      Parameters:
      factory - the TerminalFactory that created this terminal

      Throws:
      NullPointerException - if factory is null

      ---End-of-Excerpt-from-spec---

      However, NullPointerException is not thrown if factory is null.

      Please run the minimized test to reproduce failure.

      Minimized test:
      ===============

      --- test.java ---
      import javax.smartcardio.CardTerminal;
      import javax.smartcardio.TerminalFactory;
      import javax.smartcardio.Card;
      import javax.smartcardio.CardException;

      public class test {
          public static void main(String[] args) {
              try {
                  CardTerminal term = new StubCardTerminal((TerminalFactory)null);
                  System.out.println("Failed. NullPointerException was not thrown.");
              } catch (NullPointerException e) {
                  System.out.println("Passed.");
              }
          }
      }
      --- test.java ---

      --- StubCardTerminal.java ---
      import javax.smartcardio.CardTerminal;
      import javax.smartcardio.TerminalFactory;
      import javax.smartcardio.Card;
      import javax.smartcardio.CardException;

      public class StubCardTerminal extends CardTerminal {

          public StubCardTerminal(TerminalFactory factory) {
              super(factory);
          }

          public String getName() {
              return "JCKCardTerminal";
          }

          public Card connect(String protocol) throws CardException {
              return null;
          }

          public boolean isCardPresent() throws CardException {
              return false;
          }

          public boolean waitForCardPresent(long timeout) throws CardException{
              return false;
          }

          public boolean waitForCardAbsent(long timeout) throws CardException {
              return true;
          }

      }
      --- StubCardTerminal.java ---



      Minimized test output:
      ======================
      [vs158239@vsmelov CardTerminal]$ javac *.java
      [vs158239@vsmelov CardTerminal]$ java -cp ./ test
      Failed. NullPointerException was not thrown.
      [vs158239@vsmelov CardTerminal]$ java -version
      java version "1.6.0-beta2"
      Java(TM) SE Runtime Environment (build 1.6.0-beta2-b84)
      Java HotSpot(TM) Client VM (build 1.6.0-beta2-b84, mixed mode)

            andreas Andreas Sterbenz
            vsmelovsunw Vladimir Smelov (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: