From 8dfb3001f9e66af17fb57eed58fad331903e3523 Mon Sep 17 00:00:00 2001 From: Sakthivel Subramanian <179120858+sakthivelmanii@users.noreply.github.com> Date: Fri, 6 Nov 2026 12:11:38 +0000 Subject: [PATCH] test(spanner): unflake cloud-devrel/client-libraries/java/java-spanner/nightly/java8-samples Fix ClassCastException by correctly wrapping GAX exceptions using SpannerExceptionFactory. --- .../java/com/example/spanner/PgSpannerSample.java | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/java-spanner/samples/snippets/src/main/java/com/example/spanner/PgSpannerSample.java b/java-spanner/samples/snippets/src/main/java/com/example/spanner/PgSpannerSample.java index b3ad5cd08c44..b73ee3b1f1a3 100644 --- a/java-spanner/samples/snippets/src/main/java/com/example/spanner/PgSpannerSample.java +++ b/java-spanner/samples/snippets/src/main/java/com/example/spanner/PgSpannerSample.java @@ -214,7 +214,7 @@ static void createPostgreSqlDatabase( System.out.println("Created database [" + db.getName() + "]"); } catch (ExecutionException e) { // If the operation failed during execution, expose the cause. - throw (SpannerException) e.getCause(); + throw SpannerExceptionFactory.asSpannerException(e.getCause()); } catch (InterruptedException e) { // Throw when a thread is waiting, sleeping, or otherwise occupied, // and the thread is interrupted, either before or during the activity. @@ -320,7 +320,7 @@ static void addMarketingBudget(DatabaseAdminClient adminClient, DatabaseName dat System.out.println("Added MarketingBudget column"); } catch (ExecutionException e) { // If the operation failed during execution, expose the cause. - throw (SpannerException) e.getCause(); + throw SpannerExceptionFactory.asSpannerException(e.getCause()); } catch (InterruptedException e) { // Throw when a thread is waiting, sleeping, or otherwise occupied, // and the thread is interrupted, either before or during the activity. @@ -438,7 +438,7 @@ static void addIndex(DatabaseAdminClient adminClient, DatabaseName databaseName) System.out.println("Added AlbumsByAlbumTitle index"); } catch (ExecutionException e) { // If the operation failed during execution, expose the cause. - throw (SpannerException) e.getCause(); + throw SpannerExceptionFactory.asSpannerException(e.getCause()); } catch (InterruptedException e) { // Throw when a thread is waiting, sleeping, or otherwise occupied, // and the thread is interrupted, either before or during the activity. @@ -476,7 +476,7 @@ static void addStoringIndex(DatabaseAdminClient adminClient, DatabaseName databa System.out.println("Added AlbumsByAlbumTitle2 index"); } catch (ExecutionException e) { // If the operation failed during execution, expose the cause. - throw (SpannerException) e.getCause(); + throw SpannerExceptionFactory.asSpannerException(e.getCause()); } catch (InterruptedException e) { // Throw when a thread is waiting, sleeping, or otherwise occupied, // and the thread is interrupted, either before or during the activity. @@ -754,7 +754,7 @@ static void addLastUpdateTimestampColumn( System.out.println("Added LastUpdateTime as a timestamp column in Albums table."); } catch (ExecutionException e) { // If the operation failed during execution, expose the cause. - throw (SpannerException) e.getCause(); + throw SpannerExceptionFactory.asSpannerException(e.getCause()); } catch (InterruptedException e) { // Throw when a thread is waiting, sleeping, or otherwise occupied, // and the thread is interrupted, either before or during the activity. @@ -808,7 +808,7 @@ static void createTableWithTimestamp(DatabaseAdminClient dbAdminClient, System.out.println("Created Performances table in database: [" + databaseName + "]"); } catch (ExecutionException e) { // If the operation failed during execution, expose the cause. - throw (SpannerException) e.getCause(); + throw SpannerExceptionFactory.asSpannerException(e.getCause()); } catch (InterruptedException e) { // Throw when a thread is waiting, sleeping, or otherwise occupied, // and the thread is interrupted, either before or during the activity. @@ -1001,7 +1001,7 @@ static void createTableWithDatatypes(DatabaseAdminClient dbAdminClient, System.out.println("Created Venues table in database: [" + databaseName + "]"); } catch (ExecutionException e) { // If the operation failed during execution, expose the cause. - throw (SpannerException) e.getCause(); + throw SpannerExceptionFactory.asSpannerException(e.getCause()); } catch (InterruptedException e) { // Throw when a thread is waiting, sleeping, or otherwise occupied, // and the thread is interrupted, either before or during the activity.