Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
[CONJ-775] correcting possible NPE with badly formed connection string
  • Loading branch information
rusher committed Mar 25, 2020
1 parent c5a016d commit ab2e8db
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 17 deletions.
Expand Up @@ -1318,17 +1318,25 @@ public void connectWithoutProxy() throws SQLException {
}

// CONJ-293 : handle name-pipe without host
if (hosts.isEmpty() && options.pipe != null) {
try {
createConnection(null, username);
return;
} catch (SQLException exception) {
if (hosts.isEmpty()) {
if (options.pipe != null) {
try {
createConnection(null, username);
return;
} catch (SQLException exception) {
throw ExceptionFactory.INSTANCE.create(
String.format(
"Could not connect to named pipe '%s' : %s%s",
options.pipe, exception.getMessage(), getTraces()),
"08000",
exception);
}
} else {
throw ExceptionFactory.INSTANCE.create(
String.format(
"Could not connect to named pipe '%s' : %s%s",
options.pipe, exception.getMessage(), getTraces()),
"08000",
exception);
"No host is defined and pipe option is not set. "
+ "Check if connection string respect format "
+ "(jdbc:(mysql|mariadb):[replication:|loadbalance:|sequential:|aurora:]//<hostDescription>[,<hostDescription>...]/[database][?<key1>=<value1>[&<key2>=<value2>]])",
"08000");
}
}

Expand Down Expand Up @@ -1606,10 +1614,6 @@ public PacketInputStream getReader() {
return reader;
}

public PacketOutputStream getWriter() {
return writer;
}

public boolean isEofDeprecated() {
return eofDeprecated;
}
Expand Down
Expand Up @@ -71,7 +71,6 @@
import org.mariadb.jdbc.internal.com.send.parameters.ParameterHolder;
import org.mariadb.jdbc.internal.failover.FailoverProxy;
import org.mariadb.jdbc.internal.io.input.PacketInputStream;
import org.mariadb.jdbc.internal.io.output.PacketOutputStream;
import org.mariadb.jdbc.internal.util.ServerPrepareStatementCache;
import org.mariadb.jdbc.internal.util.dao.ClientPrepareResult;
import org.mariadb.jdbc.internal.util.dao.ServerPrepareResult;
Expand Down Expand Up @@ -300,8 +299,6 @@ void resetStateAfterFailover(

PacketInputStream getReader();

PacketOutputStream getWriter();

boolean isEofDeprecated();

int getAutoIncrementIncrement() throws SQLException;
Expand Down
10 changes: 10 additions & 0 deletions src/test/java/org/mariadb/jdbc/ParserTest.java
Expand Up @@ -75,6 +75,16 @@ public static void initClass() throws SQLException {
createTable("table2", "id2 int auto_increment primary key");
}

@Test
public void malformedUrlException() throws SQLException {
try {
DriverManager.getConnection("jdbc:mariadb:///" + hostname);
fail("must have thrown exception");
} catch (SQLException sqle) {
assertTrue(sqle.getMessage().contains("No host is defined and pipe option is not set"));
}
}

@Test
public void poolVerification() throws Exception {
ArrayList<HostAddress> hostAddresses = new ArrayList<>();
Expand Down

0 comments on commit ab2e8db

Please sign in to comment.