Skip to content
Permalink
Browse files

[CONJ-616] correcting possible NPE in case of master down and option …

…"allowMasterDownConnection" is set

(cherry picked from commit 0013ee9)
  • Loading branch information...
rusher committed Sep 3, 2018
1 parent 47c7960 commit f82b7039c45542bdec836254188b864f4e5fdcba
Showing with 21 additions and 13 deletions.
  1. +21 −13 src/main/java/org/mariadb/jdbc/internal/failover/impl/MastersSlavesListener.java
@@ -52,6 +52,20 @@

package org.mariadb.jdbc.internal.failover.impl;

import static org.mariadb.jdbc.internal.util.SqlStates.CONNECTION_EXCEPTION;

import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.net.SocketException;
import java.sql.SQLException;
import java.sql.SQLNonTransientConnectionException;
import java.util.ArrayDeque;
import java.util.ArrayList;
import java.util.Collections;
import java.util.LinkedList;
import java.util.List;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicInteger;
import org.mariadb.jdbc.HostAddress;
import org.mariadb.jdbc.MariaDbConnection;
import org.mariadb.jdbc.MariaDbStatement;
@@ -70,17 +84,6 @@
import org.mariadb.jdbc.internal.util.scheduler.DynamicSizedSchedulerInterface;
import org.mariadb.jdbc.internal.util.scheduler.SchedulerServiceProviderHolder;

import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.net.SocketException;
import java.sql.SQLException;
import java.sql.SQLNonTransientConnectionException;
import java.util.*;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicInteger;

import static org.mariadb.jdbc.internal.util.SqlStates.CONNECTION_EXCEPTION;


/**
* this class handle the operation when multiple hosts.
@@ -227,16 +230,21 @@ public boolean versionGreaterOrEqual(int major, int minor, int patch) {
@Override
public boolean sessionStateAware() {
Protocol protocol = (currentProtocol != null) ? currentProtocol : secondaryProtocol;
if (protocol == null) return false;
return protocol.sessionStateAware();
}

@Override
public String getCatalog() throws SQLException {
return (currentProtocol != null) ? currentProtocol.getCatalog() : secondaryProtocol.getDatabase();
Protocol protocol = (currentProtocol != null) ? currentProtocol : secondaryProtocol;
if (protocol == null) return urlParser.getDatabase();
return protocol.getCatalog();
}

public int getMajorServerVersion() {
return (currentProtocol != null) ? currentProtocol.getMajorServerVersion() : secondaryProtocol.getMajorServerVersion();
Protocol protocol = (currentProtocol != null) ? currentProtocol : secondaryProtocol;
if (protocol == null) return 5;
return protocol.getMajorServerVersion();
}

public boolean isMasterConnection() {

0 comments on commit f82b703

Please sign in to comment.
You can’t perform that action at this time.