Skip to content

Commit f3d7ba8

Browse files
committed
add severe logs before Exception throws
1 parent ce4969b commit f3d7ba8

13 files changed

Lines changed: 128 additions & 50 deletions

java-bigquery/google-cloud-bigquery-jdbc/src/main/java/com/google/cloud/bigquery/jdbc/BigQueryBaseArray.java

Lines changed: 26 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -71,28 +71,36 @@ public final int getBaseType() {
7171

7272
@Override
7373
public final Object getArray(Map<String, Class<?>> map) throws SQLException {
74-
LOG.severe(CUSTOMER_TYPE_MAPPING_NOT_SUPPORTED);
75-
throw new BigQueryJdbcSqlFeatureNotSupportedException(CUSTOMER_TYPE_MAPPING_NOT_SUPPORTED);
74+
BigQueryJdbcSqlFeatureNotSupportedException ex =
75+
new BigQueryJdbcSqlFeatureNotSupportedException(CUSTOMER_TYPE_MAPPING_NOT_SUPPORTED);
76+
LOG.severe(ex, CUSTOMER_TYPE_MAPPING_NOT_SUPPORTED);
77+
throw ex;
7678
}
7779

7880
@Override
7981
public final Object getArray(long index, int count, Map<String, Class<?>> map)
8082
throws SQLException {
81-
LOG.severe(CUSTOMER_TYPE_MAPPING_NOT_SUPPORTED);
82-
throw new BigQueryJdbcSqlFeatureNotSupportedException(CUSTOMER_TYPE_MAPPING_NOT_SUPPORTED);
83+
BigQueryJdbcSqlFeatureNotSupportedException ex =
84+
new BigQueryJdbcSqlFeatureNotSupportedException(CUSTOMER_TYPE_MAPPING_NOT_SUPPORTED);
85+
LOG.severe(ex, CUSTOMER_TYPE_MAPPING_NOT_SUPPORTED);
86+
throw ex;
8387
}
8488

8589
@Override
8690
public final ResultSet getResultSet(Map<String, Class<?>> map) throws SQLException {
87-
LOG.severe(CUSTOMER_TYPE_MAPPING_NOT_SUPPORTED);
88-
throw new BigQueryJdbcSqlFeatureNotSupportedException(CUSTOMER_TYPE_MAPPING_NOT_SUPPORTED);
91+
BigQueryJdbcSqlFeatureNotSupportedException ex =
92+
new BigQueryJdbcSqlFeatureNotSupportedException(CUSTOMER_TYPE_MAPPING_NOT_SUPPORTED);
93+
LOG.severe(ex, CUSTOMER_TYPE_MAPPING_NOT_SUPPORTED);
94+
throw ex;
8995
}
9096

9197
@Override
9298
public final ResultSet getResultSet(long index, int count, Map<String, Class<?>> map)
9399
throws SQLException {
94-
LOG.severe(CUSTOMER_TYPE_MAPPING_NOT_SUPPORTED);
95-
throw new BigQueryJdbcSqlFeatureNotSupportedException(CUSTOMER_TYPE_MAPPING_NOT_SUPPORTED);
100+
BigQueryJdbcSqlFeatureNotSupportedException ex =
101+
new BigQueryJdbcSqlFeatureNotSupportedException(CUSTOMER_TYPE_MAPPING_NOT_SUPPORTED);
102+
LOG.severe(ex, CUSTOMER_TYPE_MAPPING_NOT_SUPPORTED);
103+
throw ex;
96104
}
97105

98106
protected Object getArrayInternal(int fromIndex, int toIndexExclusive) {
@@ -110,8 +118,9 @@ protected Object getArrayInternal(int fromIndex, int toIndexExclusive) {
110118
protected void ensureValid() throws IllegalStateException {
111119
LOG.finest("++enter++");
112120
if (!this.valid) {
113-
LOG.severe(INVALID_ARRAY);
114-
throw new IllegalStateException(INVALID_ARRAY);
121+
IllegalStateException ex = new IllegalStateException(INVALID_ARRAY);
122+
LOG.severe(ex, INVALID_ARRAY);
123+
throw ex;
115124
}
116125
}
117126

@@ -132,11 +141,14 @@ protected Tuple<Integer, Integer> createRange(long index, int count, int size)
132141
// jdbc array follows 1 based array indexing
133142
long normalisedFromIndex = index - 1;
134143
if (normalisedFromIndex + count > size) {
144+
IllegalArgumentException ex =
145+
new IllegalArgumentException(
146+
String.format(
147+
"The array index is out of range: %d, number of elements: %d.",
148+
index + count, size));
135149
LOG.severe(
136-
"The array index is out of range: %d, number of elements: %d.", index + count, size);
137-
throw new IllegalArgumentException(
138-
String.format(
139-
"The array index is out of range: %d, number of elements: %d.", index + count, size));
150+
ex, "The array index is out of range: %d, number of elements: %d.", index + count, size);
151+
throw ex;
140152
}
141153
long toIndex = normalisedFromIndex + count;
142154
return Tuple.of((int) normalisedFromIndex, (int) toIndex);

java-bigquery/google-cloud-bigquery-jdbc/src/main/java/com/google/cloud/bigquery/jdbc/BigQueryBaseResultSet.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,7 @@ public void close() {
109109

110110
protected SQLException createCoercionException(
111111
int columnIndex, Class<?> targetClass, Exception cause) throws SQLException {
112+
LOG.severe(cause, "Coercion failed");
112113
checkClosed();
113114
StandardSQLTypeName type;
114115
String typeName;

java-bigquery/google-cloud-bigquery-jdbc/src/main/java/com/google/cloud/bigquery/jdbc/BigQueryBaseStruct.java

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -42,14 +42,18 @@ abstract class BigQueryBaseStruct implements java.sql.Struct {
4242

4343
@Override
4444
public final String getSQLTypeName() throws SQLException {
45-
LOG.severe(CUSTOMER_TYPE_MAPPING_NOT_SUPPORTED);
46-
throw new BigQueryJdbcSqlFeatureNotSupportedException(CUSTOMER_TYPE_MAPPING_NOT_SUPPORTED);
45+
BigQueryJdbcSqlFeatureNotSupportedException ex =
46+
new BigQueryJdbcSqlFeatureNotSupportedException(CUSTOMER_TYPE_MAPPING_NOT_SUPPORTED);
47+
LOG.severe(ex, CUSTOMER_TYPE_MAPPING_NOT_SUPPORTED);
48+
throw ex;
4749
}
4850

4951
@Override
5052
public final Object[] getAttributes(Map<String, Class<?>> map) throws SQLException {
51-
LOG.severe(CUSTOMER_TYPE_MAPPING_NOT_SUPPORTED);
52-
throw new BigQueryJdbcSqlFeatureNotSupportedException(CUSTOMER_TYPE_MAPPING_NOT_SUPPORTED);
53+
BigQueryJdbcSqlFeatureNotSupportedException ex =
54+
new BigQueryJdbcSqlFeatureNotSupportedException(CUSTOMER_TYPE_MAPPING_NOT_SUPPORTED);
55+
LOG.severe(ex, CUSTOMER_TYPE_MAPPING_NOT_SUPPORTED);
56+
throw ex;
5357
}
5458

5559
static boolean isStruct(Field currentSchema) {

java-bigquery/google-cloud-bigquery-jdbc/src/main/java/com/google/cloud/bigquery/jdbc/BigQueryDaemonPollingTask.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -113,8 +113,9 @@ else if (referenceQueueJsonRs != null) {
113113
reference.clear();
114114
}
115115
} else {
116-
LOG.severe("Null Reference Queue");
117-
throw new BigQueryJdbcRuntimeException("Null Reference Queue");
116+
BigQueryJdbcRuntimeException ex = new BigQueryJdbcRuntimeException("Null Reference Queue");
117+
LOG.severe(ex, "Null Reference Queue");
118+
throw ex;
118119
}
119120
} catch (InterruptedException ex) {
120121
LOG.severe(ex, "Interrupted in GC daemon task");

java-bigquery/google-cloud-bigquery-jdbc/src/main/java/com/google/cloud/bigquery/jdbc/BigQueryDatabaseMetaData.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2639,6 +2639,7 @@ public ResultSet getPrimaryKeys(String catalog, String schema, String table) thr
26392639
String formattedSql = replaceSqlParameters(sql, catalog, schema, table);
26402640
return this.statement.executeQuery(formattedSql);
26412641
} catch (SQLException e) {
2642+
LOG.severe(e, "Error executing getPrimaryKeys");
26422643
throw new BigQueryJdbcException(e);
26432644
}
26442645
}
@@ -2654,6 +2655,7 @@ public ResultSet getImportedKeys(String catalog, String schema, String table)
26542655
String formattedSql = replaceSqlParameters(sql, catalog, schema, table);
26552656
return this.statement.executeQuery(formattedSql);
26562657
} catch (SQLException e) {
2658+
LOG.severe(e, "Error executing getImportedKeys");
26572659
throw new BigQueryJdbcException(e);
26582660
}
26592661
}
@@ -2669,6 +2671,7 @@ public ResultSet getExportedKeys(String catalog, String schema, String table)
26692671
String formattedSql = replaceSqlParameters(sql, catalog, schema, table);
26702672
return this.statement.executeQuery(formattedSql);
26712673
} catch (SQLException e) {
2674+
LOG.severe(e, "Error executing getExportedKeys");
26722675
throw new BigQueryJdbcException(e);
26732676
}
26742677
}
@@ -2698,6 +2701,7 @@ public ResultSet getCrossReference(
26982701
foreignTable);
26992702
return this.statement.executeQuery(formattedSql);
27002703
} catch (SQLException e) {
2704+
LOG.severe(e, "Error executing getCrossReference");
27012705
throw new BigQueryJdbcException(e);
27022706
}
27032707
}

java-bigquery/google-cloud-bigquery-jdbc/src/main/java/com/google/cloud/bigquery/jdbc/BigQueryDriver.java

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,10 @@ public class BigQueryDriver implements Driver {
6464
try {
6565
register();
6666
} catch (SQLException e) {
67-
throw new ExceptionInInitializerError("Registering driver failed: " + e.getMessage());
67+
ExceptionInInitializerError ex =
68+
new ExceptionInInitializerError("Registering driver failed: " + e.getMessage());
69+
LOG.severe(ex, "Registering driver failed: " + e.getMessage());
70+
throw ex;
6871
}
6972
LoadBalancerRegistry.getDefaultRegistry().register(new PickFirstLoadBalancerProvider());
7073
}
@@ -95,8 +98,13 @@ public static BigQueryDriver getRegisteredDriver() throws IllegalStateException
9598
if (isRegistered()) {
9699
return registeredBigqueryJdbcDriver;
97100
}
98-
throw new IllegalStateException(
101+
IllegalStateException ex =
102+
new IllegalStateException(
103+
"Driver is not registered (or it has not been registered using Driver.register() method)");
104+
LOG.severe(
105+
ex,
99106
"Driver is not registered (or it has not been registered using Driver.register() method)");
107+
throw ex;
100108
}
101109

102110
/**
@@ -127,6 +135,7 @@ public Connection connect(String url, Properties info) throws SQLException {
127135
try {
128136
BigQueryJdbcUrlUtility.parseUrl(connectionUri);
129137
} catch (BigQueryJdbcRuntimeException e) {
138+
LOG.severe(e, "Failed to parse connection URL");
130139
throw new BigQueryJdbcException(e.getMessage(), e);
131140
}
132141

@@ -186,7 +195,9 @@ public Connection connect(String url, Properties info) throws SQLException {
186195
public boolean acceptsURL(String url) throws SQLException {
187196
LOG.finest("++enter++");
188197
if (url == null || url.isEmpty()) {
189-
throw new BigQueryJdbcException("Connection URL is null.");
198+
BigQueryJdbcException ex = new BigQueryJdbcException("Connection URL is null.");
199+
LOG.severe(ex, "Connection URL is null.");
200+
throw ex;
190201
}
191202
return url.startsWith("jdbc:bigquery:");
192203
}

java-bigquery/google-cloud-bigquery-jdbc/src/main/java/com/google/cloud/bigquery/jdbc/BigQueryJdbcOAuthUtility.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,7 @@ static Map<String, String> parseOAuthProperties(DataSource ds, String callerClas
121121
try {
122122
authType = AuthType.fromValue(ds.getOAuthType());
123123
} catch (NumberFormatException exception) {
124+
LOG.severe(exception, OAUTH_TYPE_ERROR_MESSAGE);
124125
throw new IllegalArgumentException(OAUTH_TYPE_ERROR_MESSAGE);
125126
}
126127
oauthProperties.put(BigQueryJdbcUrlUtility.OAUTH_TYPE_PROPERTY_NAME, String.valueOf(authType));
@@ -458,6 +459,7 @@ private static GoogleCredentials getGoogleUserAccountCredentials(
458459
Matcher m = p.matcher(response);
459460

460461
if (!m.find()) {
462+
LOG.severe("Could not retrieve the code for user auth");
461463
throw new BigQueryJdbcRuntimeException("Could not retrieve the code for user auth");
462464
}
463465
code = m.group();
@@ -467,6 +469,7 @@ private static GoogleCredentials getGoogleUserAccountCredentials(
467469
socket.close();
468470
serverSocket.close();
469471
} else {
472+
LOG.severe("User auth only supported in desktop environments");
470473
throw new BigQueryJdbcRuntimeException("User auth only supported in desktop environments");
471474
}
472475

java-bigquery/google-cloud-bigquery-jdbc/src/main/java/com/google/cloud/bigquery/jdbc/BigQueryJdbcProxyUtility.java

Lines changed: 24 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -71,11 +71,14 @@ static Map<String, String> parseProxyProperties(DataSource ds, String callerClas
7171
String proxyPort = ds.getProxyPort();
7272
if (proxyPort != null) {
7373
if (!Pattern.compile(validPortRegex).matcher(proxyPort).find()) {
74+
IllegalArgumentException ex =
75+
new IllegalArgumentException(
76+
String.format(
77+
"Illegal port number provided %s. Please provide a valid port number.",
78+
proxyPort));
7479
LOG.severe(
75-
"Illegal port number provided %s. Please provide a valid port number.", proxyPort);
76-
throw new IllegalArgumentException(
77-
String.format(
78-
"Illegal port number provided %s. Please provide a valid port number.", proxyPort));
80+
ex, "Illegal port number provided %s. Please provide a valid port number.", proxyPort);
81+
throw ex;
7982
}
8083
proxyProperties.put(BigQueryJdbcUrlUtility.PROXY_PORT_PROPERTY_NAME, proxyPort);
8184
}
@@ -91,25 +94,34 @@ static Map<String, String> parseProxyProperties(DataSource ds, String callerClas
9194
boolean isMissingProxyHostOrPortWhenProxySet =
9295
(proxyHost == null && proxyPort != null) || (proxyHost != null && proxyPort == null);
9396
if (isMissingProxyHostOrPortWhenProxySet) {
97+
IllegalArgumentException ex =
98+
new IllegalArgumentException(
99+
"Both ProxyHost and ProxyPort parameters need to be specified. No defaulting behavior"
100+
+ " occurs.");
94101
LOG.severe(
102+
ex,
95103
"Both ProxyHost and ProxyPort parameters need to be specified. No defaulting behavior occurs.");
96-
throw new IllegalArgumentException(
97-
"Both ProxyHost and ProxyPort parameters need to be specified. No defaulting behavior"
98-
+ " occurs.");
104+
throw ex;
99105
}
100106
boolean isMissingProxyUidOrPwdWhenAuthSet =
101107
(proxyUid == null && proxyPwd != null) || (proxyUid != null && proxyPwd == null);
102108
if (isMissingProxyUidOrPwdWhenAuthSet) {
103-
LOG.severe("Both ProxyUid and ProxyPwd parameters need to be specified for authentication.");
104-
throw new IllegalArgumentException(
105-
"Both ProxyUid and ProxyPwd parameters need to be specified for authentication.");
109+
IllegalArgumentException ex =
110+
new IllegalArgumentException(
111+
"Both ProxyUid and ProxyPwd parameters need to be specified for authentication.");
112+
LOG.severe(
113+
ex, "Both ProxyUid and ProxyPwd parameters need to be specified for authentication.");
114+
throw ex;
106115
}
107116
boolean isProxyAuthSetWithoutProxySettings = proxyUid != null && proxyHost == null;
108117
if (isProxyAuthSetWithoutProxySettings) {
118+
IllegalArgumentException ex =
119+
new IllegalArgumentException(
120+
"Proxy authentication provided via connection string with no proxy host or port set.");
109121
LOG.severe(
122+
ex,
110123
"Proxy authentication provided via connection string with no proxy host or port set.");
111-
throw new IllegalArgumentException(
112-
"Proxy authentication provided via connection string with no proxy host or port set.");
124+
throw ex;
113125
}
114126
return proxyProperties;
115127
}

java-bigquery/google-cloud-bigquery-jdbc/src/main/java/com/google/cloud/bigquery/jdbc/BigQueryJdbcUrlUtility.java

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -706,8 +706,11 @@ private static Map<String, String> parseUrlInternal(String url) {
706706
// Some tools can pass unknown keys. In order not to break compatibility, throw
707707
// an exception only with incorrect format, otherwise log an error.
708708
if (kv.length != 2) {
709-
throw new BigQueryJdbcRuntimeException(
710-
String.format("Wrong value or unknown setting: %s", safeRef));
709+
BigQueryJdbcRuntimeException ex =
710+
new BigQueryJdbcRuntimeException(
711+
String.format("Wrong value or unknown setting: %s", safeRef));
712+
LOG.severe(ex, "Wrong value or unknown setting: %s", safeRef);
713+
throw ex;
711714
} else {
712715
LOG.warning("Wrong value or unknown setting: %s", safeRef);
713716
continue;
@@ -754,6 +757,10 @@ static boolean convertIntToBoolean(String value, String propertyName) {
754757
}
755758

756759
} catch (NumberFormatException ex) {
760+
LOG.severe(
761+
ex,
762+
"Invalid value for %s. For Boolean connection properties, use 0 for false and 1 for true.",
763+
propertyName);
757764
throw new IllegalArgumentException(
758765
String.format(
759766
"Invalid value for %s. For Boolean connection properties, use 0 for false and 1 for"
@@ -766,11 +773,17 @@ static boolean convertIntToBoolean(String value, String propertyName) {
766773
} else if (integerValue == 0) {
767774
return false;
768775
} else {
769-
throw new IllegalArgumentException(
770-
String.format(
771-
"Invalid value for %s. For Boolean connection properties, use 0 for false and 1 for"
772-
+ " true.",
773-
propertyName));
776+
IllegalArgumentException ex =
777+
new IllegalArgumentException(
778+
String.format(
779+
"Invalid value for %s. For Boolean connection properties, use 0 for false and 1 for"
780+
+ " true.",
781+
propertyName));
782+
LOG.severe(
783+
ex,
784+
"Invalid value for %s. For Boolean connection properties, use 0 for false and 1 for true.",
785+
propertyName);
786+
throw ex;
774787
}
775788
}
776789

java-bigquery/google-cloud-bigquery-jdbc/src/main/java/com/google/cloud/bigquery/jdbc/BigQueryParameterHandler.java

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -104,8 +104,10 @@ void setParameter(int parameterIndex, Object value, Class type)
104104

105105
private void checkValidIndex(int parameterIndex) {
106106
if (parameterIndex > this.parametersArraySize) {
107-
LOG.severe("All parameters already provided.");
108-
throw new IndexOutOfBoundsException("All parameters already provided.");
107+
IndexOutOfBoundsException ex =
108+
new IndexOutOfBoundsException("All parameters already provided.");
109+
LOG.severe(ex, "All parameters already provided.");
110+
throw ex;
109111
}
110112
}
111113

@@ -153,8 +155,10 @@ void setParameter(
153155
LOG.finest("++enter++");
154156
LOG.finest("setParameter called by : %s", type.getName());
155157
if (paramName == null || paramName.isEmpty()) {
156-
LOG.severe("paramName cannot be null or empty");
157-
throw new IllegalArgumentException("paramName cannot be null or empty");
158+
IllegalArgumentException ex =
159+
new IllegalArgumentException("paramName cannot be null or empty");
160+
LOG.severe(ex, "paramName cannot be null or empty");
161+
throw ex;
158162
}
159163
BigQueryJdbcParameter parameter = null;
160164
for (BigQueryJdbcParameter p : parametersList) {

0 commit comments

Comments
 (0)