Skip to content

Commit

Permalink
[CONJ-167] Driver is throwing IllegalArgumentException instead of ret…
Browse files Browse the repository at this point in the history
…urning null
  • Loading branch information
rusher committed Jul 21, 2015
1 parent ab3eb08 commit 7b629cd
Show file tree
Hide file tree
Showing 7 changed files with 22 additions and 31 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<artifactId>mariadb-java-client</artifactId>
<packaging>jar</packaging>
<name>mariadb-java-client</name>
<version>1.2.0</version>
<version>1.2.1-SNAPSHOT</version>
<description>JDBC driver for MariaDB and MySQL</description>
<url>https://mariadb.com/kb/en/mariadb/about-mariadb-connector-j/</url>
<properties>
Expand Down
2 changes: 2 additions & 0 deletions src/main/java/org/mariadb/jdbc/Driver.java
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,8 @@ public Connection connect(final String url, final Properties props) throws SQLEx
log.debug("Connecting to: " + url);
try {
JDBCUrl jdbcUrl = JDBCUrl.parse(url, props);
//
if (jdbcUrl == null) return null;
if (jdbcUrl.getHostAddresses() == null) {
log.info("MariaDB connector : missing Host address");
return null;
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/org/mariadb/jdbc/JDBCUrl.java
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ protected JDBCUrl(String database, List<HostAddress> addresses, Options options,

static boolean acceptsURL(String url) {
return (url != null) &&
(url.startsWith("jdbc:mariadb://") || url.startsWith("jdbc:mysql://"));
(url.startsWith("jdbc:mariadb:") || url.startsWith("jdbc:mysql:"));

}

Expand All @@ -141,7 +141,7 @@ public static JDBCUrl parse(final String url, Properties prop) {
}
}
}
throw new IllegalArgumentException("Invalid connection URL url " + url);
return null;
}

public void parseUrl(String url) {
Expand Down
6 changes: 3 additions & 3 deletions src/main/java/org/mariadb/jdbc/Version.java
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
package org.mariadb.jdbc;

public final class Version {
public static final String version = "1.2.0";
public static final String version = "1.2.1-SNAPSHOT";
public static final int majorVersion = 1;
public static final int minorVersion = 2;
public static final int patchVersion = 0;
public static final String qualifier = "";
public static final int patchVersion = 1;
public static final String qualifier = "SNAPSHOT";

}
Original file line number Diff line number Diff line change
Expand Up @@ -333,7 +333,6 @@ public void switchReadOnlyConnection(Boolean mustBeReadOnly) throws QueryExcepti
syncConnection(this.masterProtocol, this.secondaryProtocol);

currentProtocol = this.secondaryProtocol;
setSessionReadOnly(true);

log.trace("current connection is now secondary");
return;
Expand Down Expand Up @@ -612,7 +611,7 @@ public void run() {
}

public void checkIfTypeHaveChanged(SearchFilter searchFilter) throws QueryException {
if (masterProtocol.ping()) {
if (masterProtocol != null && masterProtocol.ping()) {
log.trace("PingLoop master ping ok");
}
}
Expand Down
30 changes: 13 additions & 17 deletions src/test/java/org/mariadb/jdbc/JdbcParserTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -79,12 +79,8 @@ public void testJDBCParserSimpleIPv4basic() {
}
@Test
public void testJDBCParserSimpleIPv4basicError() {
try {
JDBCUrl.parse(null);
Assert.fail();
}catch (IllegalArgumentException e) {
Assert.assertTrue(true);
}
JDBCUrl jdbcUrl = JDBCUrl.parse(null);
Assert.assertTrue(jdbcUrl == null);
}
@Test
public void testJDBCParserSimpleIPv4basicwithoutDatabase() {
Expand Down Expand Up @@ -157,21 +153,11 @@ public void testJDBCParserParameter() {
Assert.assertTrue(new HostAddress("slave1", 3308, "slave").equals(jdbcUrl.getHostAddresses().get(2)));
}

@Test
public void testJDBCParserParameterError() {
try {
JDBCUrl.parse(null);
Assert.fail();
}catch (IllegalArgumentException e) {
Assert.assertTrue(true);
}
}

@Test
public void testJDBCParserParameterErrorEqual() {
String url = "jdbc:mysql://address=(type=)(port=3306)(host=master1),address=(port=3307)(type=master)(host=master2),address=(type=slave)(host=slave1)(port=3308)/database?user=greg&password=pass";
try {
JDBCUrl.parse(null);
JDBCUrl.parse(url);
Assert.fail();
}catch (IllegalArgumentException e) {
Assert.assertTrue(true);
Expand Down Expand Up @@ -223,4 +209,14 @@ public void testJDBCParserHAModeLoadAurora() {
Assert.assertTrue(jdbc.getHaMode().equals(UrlHAMode.AURORA));
}

/**
* CONJ-167 : Driver is throwing IllegalArgumentException instead of returning null
*/
@Test
public void checkOtherDriverCompatibility() {
String url = "jdbc:h2:mem:RZM;DB_CLOSE_DELAY=-1";
JDBCUrl jdbc = JDBCUrl.parse(url);
Assert.assertTrue(jdbc == null);
}

}
6 changes: 0 additions & 6 deletions src/test/resources/logging.properties

This file was deleted.

0 comments on commit 7b629cd

Please sign in to comment.