Skip to content

Commit f871502

Browse files
authored
Merge branch 'main' into fix-lint-2
2 parents 78ddac7 + df74d14 commit f871502

74 files changed

Lines changed: 4352 additions & 376 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.github/workflows/sdk-platform-java-ci.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,7 @@ jobs:
162162
JOB_TYPE: install
163163
- name: Integration Tests
164164
run: |
165-
bazelisk --batch test //sdk-platform-java/test/integration/...
165+
bazelisk --batch test //sdk-platform-java/test/integration/... --test_output=errors
166166
167167
bazel-25:
168168
needs: filter

generation_config.yaml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3039,10 +3039,9 @@ libraries:
30393039
release_level: stable
30403040
client_documentation: https://cloud.google.com/java/docs/reference/proto-google-common-protos/latest/history
30413041
distribution_name: com.google.api.grpc:proto-google-common-protos
3042-
excluded_dependencies: proto-google-common-protos,grpc-google-common-protos,proto-google-common-protos-parent
3042+
excluded_dependencies: grpc-google-common-protos,proto-google-common-protos,proto-google-common-protos-parent
30433043
excluded_poms: proto-google-common-protos-bom,proto-google-common-protos
30443044
library_type: OTHER
3045-
30463045
GAPICs:
30473046
- proto_path: google/api
30483047
- proto_path: google/apps/card/v1

java-bigquery/google-cloud-bigquery-jdbc/src/main/java/com/google/cloud/bigquery/exception/BigQueryConversionException.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ public class BigQueryConversionException extends SQLException {
2727
new BigQueryJdbcCustomLogger(BigQueryConversionException.class.getName());
2828

2929
public BigQueryConversionException(String message, Throwable cause) {
30-
super(message, cause);
31-
LOG.severe(message, this);
30+
super(BigQueryJdbcExceptionUtils.formatMessage(message, cause), cause);
31+
LOG.severe(this.getMessage(), this);
3232
}
3333
}

java-bigquery/google-cloud-bigquery-jdbc/src/main/java/com/google/cloud/bigquery/exception/BigQueryJdbcCoercionException.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ public class BigQueryJdbcCoercionException extends RuntimeException {
3434
* @param cause the actual cause which was thrown while performing the coercion.
3535
*/
3636
public BigQueryJdbcCoercionException(Exception cause) {
37-
super("Coercion error", cause);
38-
LOG.severe("Coercion error", this);
37+
super(BigQueryJdbcExceptionUtils.formatMessage("Coercion error", cause), cause);
38+
LOG.severe(this.getMessage(), this);
3939
}
4040
}

java-bigquery/google-cloud-bigquery-jdbc/src/main/java/com/google/cloud/bigquery/exception/BigQueryJdbcException.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -52,9 +52,9 @@ public BigQueryJdbcException(InterruptedException ex) {
5252
* @param ex The BigQueryException to be thrown.
5353
*/
5454
public BigQueryJdbcException(String message, BigQueryException ex) {
55-
super(message, ex);
55+
super(BigQueryJdbcExceptionUtils.formatMessage(message, ex), ex);
5656
this.bigQueryException = ex;
57-
LOG.severe(ex.getMessage(), this);
57+
LOG.severe(this.getMessage(), this);
5858
}
5959

6060
/**
@@ -64,8 +64,8 @@ public BigQueryJdbcException(String message, BigQueryException ex) {
6464
* @param cause Throwable that is being converted.
6565
*/
6666
public BigQueryJdbcException(String message, Throwable cause) {
67-
super(message, cause);
68-
LOG.severe(message, this);
67+
super(BigQueryJdbcExceptionUtils.formatMessage(message, cause), cause);
68+
LOG.severe(this.getMessage(), this);
6969
}
7070

7171
/**
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
/*
2+
* Copyright 2026 Google LLC
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package com.google.cloud.bigquery.exception;
18+
19+
/** Utility class for JDBC exceptions. */
20+
final class BigQueryJdbcExceptionUtils {
21+
22+
private BigQueryJdbcExceptionUtils() {
23+
// Utility class, prevent instantiation
24+
}
25+
26+
/**
27+
* Formats the exception message by appending the cause's message (or toString if null) on a
28+
* newline.
29+
*
30+
* @param message The custom detail message.
31+
* @param cause The underlying cause of the exception.
32+
* @return The formatted message.
33+
*/
34+
public static String formatMessage(String message, Throwable cause) {
35+
return message
36+
+ (cause != null
37+
? "\n" + (cause.getMessage() != null ? cause.getMessage() : cause.toString())
38+
: "");
39+
}
40+
}

java-bigquery/google-cloud-bigquery-jdbc/src/main/java/com/google/cloud/bigquery/exception/BigQueryJdbcRuntimeException.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -50,12 +50,12 @@ public BigQueryJdbcRuntimeException(Throwable ex) {
5050
* @param ex Throwable to be thrown.
5151
*/
5252
public BigQueryJdbcRuntimeException(String message, InterruptedException ex) {
53-
super(message, ex);
54-
LOG.severe(message, this);
53+
super(BigQueryJdbcExceptionUtils.formatMessage(message, ex), ex);
54+
LOG.severe(this.getMessage(), this);
5555
}
5656

5757
public BigQueryJdbcRuntimeException(String message, Throwable ex) {
58-
super(message, ex);
59-
LOG.severe(message, this);
58+
super(BigQueryJdbcExceptionUtils.formatMessage(message, ex), ex);
59+
LOG.severe(this.getMessage(), this);
6060
}
6161
}

java-bigquery/google-cloud-bigquery-jdbc/src/main/java/com/google/cloud/bigquery/exception/BigQueryJdbcSqlSyntaxErrorException.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ public BigQueryJdbcSqlSyntaxErrorException(BigQueryException ex) {
4040
}
4141

4242
public BigQueryJdbcSqlSyntaxErrorException(String message, BigQueryException ex) {
43-
super(message, ex);
44-
LOG.severe(message, this);
43+
super(BigQueryJdbcExceptionUtils.formatMessage(message, ex), ex);
44+
LOG.severe(this.getMessage(), this);
4545
}
4646
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
/*
2+
* Copyright 2026 Google LLC
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package com.google.cloud.bigquery.exception;
18+
19+
import static org.junit.jupiter.api.Assertions.assertEquals;
20+
21+
import com.google.cloud.bigquery.BigQueryException;
22+
import java.util.stream.Stream;
23+
import org.junit.jupiter.api.Test;
24+
import org.junit.jupiter.params.ParameterizedTest;
25+
import org.junit.jupiter.params.provider.Arguments;
26+
import org.junit.jupiter.params.provider.MethodSource;
27+
28+
public class BigQueryJdbcExceptionTest {
29+
30+
@FunctionalInterface
31+
interface ExceptionCreator {
32+
Throwable create(String message, Throwable cause);
33+
}
34+
35+
static Stream<Arguments> exceptionProvider() {
36+
return Stream.of(
37+
Arguments.of(
38+
(ExceptionCreator)
39+
(msg, cause) -> new BigQueryJdbcException(msg, (BigQueryException) cause)),
40+
Arguments.of((ExceptionCreator) BigQueryJdbcException::new),
41+
Arguments.of((ExceptionCreator) BigQueryJdbcRuntimeException::new),
42+
Arguments.of((ExceptionCreator) BigQueryConversionException::new),
43+
Arguments.of(
44+
(ExceptionCreator)
45+
(msg, cause) -> new BigQueryJdbcCoercionException((Exception) cause)),
46+
Arguments.of(
47+
(ExceptionCreator)
48+
(msg, cause) ->
49+
new BigQueryJdbcSqlSyntaxErrorException(msg, (BigQueryException) cause)));
50+
}
51+
52+
@ParameterizedTest
53+
@MethodSource("exceptionProvider")
54+
public void testExceptionMessageFormatting(ExceptionCreator creator) {
55+
String message = "Custom error message";
56+
Throwable cause = new BigQueryException(500, "Underlying error");
57+
58+
Throwable ex = creator.create(message, cause);
59+
60+
String expectedPrefix =
61+
ex instanceof BigQueryJdbcCoercionException ? "Coercion error" : message;
62+
String expectedMessage = expectedPrefix + "\n" + cause.getMessage();
63+
64+
assertEquals(expectedMessage, ex.getMessage());
65+
assertEquals(cause, ex.getCause());
66+
}
67+
68+
@Test
69+
public void testException_withCauseHavingNullMessage() {
70+
String message = "Custom error message";
71+
Throwable cause = new RuntimeException(); // Null message
72+
73+
BigQueryJdbcException ex = new BigQueryJdbcException(message, cause);
74+
75+
String expectedMessage = message + "\n" + cause.toString();
76+
assertEquals(expectedMessage, ex.getMessage());
77+
}
78+
}

java-bigquery/google-cloud-bigquery-jdbc/src/test/java/com/google/cloud/bigquery/jdbc/BigQueryTypeCoercerTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ public void shouldThrowCoercionException() {
7878
assertThrows(
7979
BigQueryJdbcCoercionException.class,
8080
() -> bigQueryTypeCoercer.coerceTo(Integer.class, 2147483648L));
81-
assertThat(exception.getMessage()).isEqualTo("Coercion error");
81+
assertThat(exception.getMessage()).isEqualTo("Coercion error\ninteger overflow");
8282
assertThat(exception.getCause()).isInstanceOf(ArithmeticException.class);
8383
}
8484

0 commit comments

Comments
 (0)