(smartcardio) specification for CommandAPDU(ByteBuffer apdu) is insufficient

XMLWordPrintable

    • Type: Bug
    • Resolution: Duplicate
    • Priority: P3
    • None
    • Affects Version/s: 6
    • Component/s: security-libs
    • None

      Specification for javax.smartcardio.CommandAPDU.CommandAPDU(ByteBuffer apdu) is insufficient because it says nothing about the required state of ByteBuffer object passed to the constructor. Current implementation requires ByteBuffer object with a buffer's position pointed to the start of APDU array in the ByteBuffer.
      We believe that this should be specified in javadoc explicitly.

      Minimized test:
      --- Test.java ---
      import java.nio.ByteBuffer;
      import javax.smartcardio.CommandAPDU;

      public class Test {

          public static void main(String[] args) {
              byte[] apdu_array = {0,0,0,0};//case 1 APDU
              ByteBuffer buffer = ByteBuffer.allocate(apdu_array.length);
              buffer.put(apdu_array); // putting apdu data
              //buffer.position(0);
              CommandAPDU cAPDU = new CommandAPDU(buffer);
          }
      }
      --- Test.java ---

      Minimized test output:
      >java Test
      Exception in thread "main" java.lang.IllegalArgumentException: apdu must be at least 4 bytes long
          at javax.smartcardio.CommandAPDU.parse(CommandAPDU.java:301)
          at javax.smartcardio.CommandAPDU.<init>(CommandAPDU.java:188)
          at Test.main(Test.java:11)


      The IllegalArgumentException is thrown because the buffer's position pointed to the end of data.
      It's required to uncomment commented string to make it work.

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

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: