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

DriverManager.getConnection throws IllegalArgumentException

    XMLWordPrintable

Details

    • Bug
    • Resolution: Future Project
    • P5
    • None
    • 6
    • core-libs

    Description

      FULL PRODUCT VERSION :
      java version "1.6.0-rc"
      Java(TM) SE Runtime Environment (build 1.6.0-rc-b104)
      Java HotSpot(TM) Client VM (build 1.6.0-rc-b104, mixed mode, sharing)


      ADDITIONAL OS VERSION INFORMATION :
      Microsoft Windows XP [Version 5.1.2600]

      A DESCRIPTION OF THE PROBLEM :
      If the JdbcObc bridge is asked to use charset UTF-16, DriverManager.getConnection throws an IllegalArgumentException.

      In JDK 1.4 and 1.5, the same call threw a SQLException (correctly, I believe).

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      See source code. Run source code against any valid ODBC data source. I used a Microsoft Access database registered using system DSN 'MondrianFoodMart'.

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      I expect a SQLException to be thrown.
      ACTUAL -
      An IllegalArgumentException is thrown.

      ERROR MESSAGES/STACK TRACES THAT OCCUR :
      Exception in thread "main" java.lang.IllegalArgumentException: Illegal replacement
              at java.nio.charset.CharsetEncoder.replaceWith(CharsetEncoder.java:268)
              at sun.jdbc.odbc.JdbcOdbcObject.CharsToBytes(JdbcOdbcObject.java:280)
              at sun.jdbc.odbc.JdbcOdbc.SQLDriverConnect(JdbcOdbc.java:3063)
              at sun.jdbc.odbc.JdbcOdbcConnection.initialize(JdbcOdbcConnection.java:323)
              at sun.jdbc.odbc.JdbcOdbcDriver.connect(JdbcOdbcDriver.java:174)
              at java.sql.DriverManager.getConnection(DriverManager.java:582)
              at java.sql.DriverManager.getConnection(DriverManager.java:154)
              at mondrian.BugTestcase.main(BugTestcase.java:33)

      REPRODUCIBILITY :
      This bug can be reproduced always.

      ---------- BEGIN SOURCE ----------
          public static void main(String[] args) throws SQLException {
              Properties info = new Properties();

              // JdbcOdbc bridge does not support UDF-16, so we know this will cause
              // an error. But it should be a SQLException. Between 1.5.0_10 and
              // 1.6.0-rc, it became an IllegalArgumentException.
              info.setProperty("charSet", "UTF-16");
              try {
                  Connection connection = DriverManager.getConnection("jdbc:odbc:MondrianFoodMart", info);
              } catch (SQLException e) {
                  System.out.println("Received SQLException. This is behavior in JDK 1.4 and 1.5.");
              } catch (IllegalArgumentException e) {
                  System.out.println("Received IllegalArgumentException. This is (incorrect?) behavior in JDK 1.6.");
                  throw e;
              }
          }

      ---------- END SOURCE ----------

      CUSTOMER SUBMITTED WORKAROUND :
      Catch the IllegalArgumentException.

      Attachments

        Activity

          People

            lancea Lance Andersen
            ndcosta Nelson Dcosta (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: