diff --git itests/hive-unit/src/test/java/org/apache/hive/jdbc/TestJdbcDriver2.java itests/hive-unit/src/test/java/org/apache/hive/jdbc/TestJdbcDriver2.java index 74fd53f..e761d90 100644 --- itests/hive-unit/src/test/java/org/apache/hive/jdbc/TestJdbcDriver2.java +++ itests/hive-unit/src/test/java/org/apache/hive/jdbc/TestJdbcDriver2.java @@ -259,8 +259,8 @@ public void testBadURL() throws Exception { private void checkBadUrl(String url) throws SQLException { try{ DriverManager.getConnection(url, "", ""); - fail("should have thrown IllegalArgumentException but did not "); - }catch(IllegalArgumentException i){ + fail("should have thrown SQLException but did not "); + }catch(SQLException i){ assertTrue(i.getMessage().contains("Bad URL format. Hostname not found " + " in authority part of the url")); } diff --git jdbc/pom.xml jdbc/pom.xml index 016e01f..cf8b62b 100644 --- jdbc/pom.xml +++ jdbc/pom.xml @@ -110,6 +110,8 @@ ${basedir}/src/java + ${basedir}/src/test + diff --git jdbc/src/java/org/apache/hive/jdbc/Utils.java jdbc/src/java/org/apache/hive/jdbc/Utils.java index f711d51..7c43b90 100644 --- jdbc/src/java/org/apache/hive/jdbc/Utils.java +++ jdbc/src/java/org/apache/hive/jdbc/Utils.java @@ -141,11 +141,11 @@ public static void verifySuccess(TStatus status, boolean withInfo) throws SQLExc * @param uri * @return */ - public static JdbcConnectionParams parseURL(String uri) throws IllegalArgumentException { + public static JdbcConnectionParams parseURL(String uri) throws SQLException { JdbcConnectionParams connParams = new JdbcConnectionParams(); if (!uri.startsWith(URL_PREFIX)) { - throw new IllegalArgumentException("Bad URL format"); + throw new SQLException("Bad URL format"); } // For URLs with no other configuration @@ -162,7 +162,7 @@ public static JdbcConnectionParams parseURL(String uri) throws IllegalArgumentEx // The missing "/" common typo while using secure mode, eg of such url - // jdbc:hive2://localhost:10000;principal=hive/HiveServer2Host@YOUR-REALM.COM if((jdbcURI.getAuthority() != null) && (jdbcURI.getHost()==null)) { - throw new IllegalArgumentException("Bad URL format. Hostname not found " + throw new SQLException("Bad URL format. Hostname not found " + " in authority part of the url: " + jdbcURI.getAuthority() + ". Are you missing a '/' after the hostname ?"); } diff --git jdbc/src/test/org/apache/hive/jdbc/TestUtils.java jdbc/src/test/org/apache/hive/jdbc/TestUtils.java new file mode 100644 index 0000000..943b35e --- /dev/null +++ jdbc/src/test/org/apache/hive/jdbc/TestUtils.java @@ -0,0 +1,20 @@ +package org.apache.hive.jdbc; + +import java.sql.SQLException; + +import org.apache.hive.jdbc.Utils; +import org.junit.Test; + +public class TestUtils { + + @Test(expected = SQLException.class) + public void testParseURLwithoutPrefix() throws SQLException { + Utils.parseURL("jdbc:h2:~/test"); + } + + @Test(expected = SQLException.class) + public void testParseURLwithUnintentionalEmbeddedMode() throws SQLException { + Utils.parseURL("jdbc:hive2://localhost:10000;principal=hive/HiveServer2Host@YOUR-REALM.COM"); + } + +}