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

Incorrect exception thrown by javax.xml.bind.DatatypeConverter

    Details

    • Subcomponent:
    • CPU:
      generic
    • OS:
      generic

      Description

      FULL PRODUCT VERSION :
      java version "1.8.0_101"
      Java(TM) SE Runtime Environment (build 1.8.0_101-b13)
      Java HotSpot(TM) 64-Bit Server VM (build 25.101-b13, mixed mode)

      ADDITIONAL OS VERSION INFORMATION :
      Darwin Andrews-MacBook-Pro.local 16.0.0 Darwin Kernel Version 16.0.0: Mon Aug 29 17:56:20 PDT 2016; root:xnu-3789.1.32~3/RELEASE_X86_64 x86_64

      A DESCRIPTION OF THE PROBLEM :
      When passing a string with invalid Base64, an IllegalArgumentException should be thrown, according to the docs:
      https://docs.oracle.com/javase/7/docs/api/javax/xml/bind/DatatypeConverter.html#parseBase64Binary(java.lang.String)

      Instead, for many strings e.g. "Qxx==", a java.lang.ArrayIndexOutOfBoundsException is thrown instead.

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      Run this program:

      import javax.xml.bind.DatatypeConverter;

      public class Test {
        public static void main(String[] args) {
          System.out.print(DatatypeConverter.parseBase64Binary("Qxx=="));
          //javax.xml.bind.DatatypeConverter.printDecimal(null);
        }
      }

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      IllegalArgumentException
      ACTUAL -
      ArrayIndexOutOfBoundsException

      ERROR MESSAGES/STACK TRACES THAT OCCUR :
      Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 1
      at javax.xml.bind.DatatypeConverterImpl._parseBase64Binary(DatatypeConverterImpl.java:715)
      at javax.xml.bind.DatatypeConverterImpl.parseBase64Binary(DatatypeConverterImpl.java:434)
      at javax.xml.bind.DatatypeConverter.parseBase64Binary(DatatypeConverter.java:342)
      at Test.main(Test.java:5)

      REPRODUCIBILITY :
      This bug can be reproduced always.

      ---------- BEGIN SOURCE ----------
      import javax.xml.bind.DatatypeConverter;

      public class Test {
        public static void main(String[] args) {
          System.out.print(DatatypeConverter.parseBase64Binary("Qxx=="));
          //javax.xml.bind.DatatypeConverter.printDecimal(null);
        }
      }
      ---------- END SOURCE ----------

        Attachments

          Activity

            People

            • Assignee:
              zli Zheng Jun Li (Inactive)
              Reporter:
              webbuggrp Webbug Group
            • Votes:
              0 Vote for this issue
              Watchers:
              5 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: