From f941be203dcf596b932ecad767b8d60964fecf89 Mon Sep 17 00:00:00 2001 From: Fabian Meiswinkel Date: Wed, 31 May 2023 08:49:43 +0200 Subject: [PATCH] Address NullPointerException in CosmosDataItemSource ctor (#35201) * Address NullPointerException in CosmosDataItemSource ctor Address NullPointerException when Spark runtime hasn't been initialized when CosmosDataItemSource ctor is called * Update changelog * Update CosmosItemsDataSource.scala --- sdk/cosmos/azure-cosmos-spark_3-1_2-12/CHANGELOG.md | 3 ++- sdk/cosmos/azure-cosmos-spark_3-2_2-12/CHANGELOG.md | 1 + sdk/cosmos/azure-cosmos-spark_3-3_2-12/CHANGELOG.md | 1 + .../com/azure/cosmos/spark/CosmosItemsDataSource.scala | 6 ++++-- 4 files changed, 8 insertions(+), 3 deletions(-) diff --git a/sdk/cosmos/azure-cosmos-spark_3-1_2-12/CHANGELOG.md b/sdk/cosmos/azure-cosmos-spark_3-1_2-12/CHANGELOG.md index 93aac5fa338bb..3ac61e22597f0 100644 --- a/sdk/cosmos/azure-cosmos-spark_3-1_2-12/CHANGELOG.md +++ b/sdk/cosmos/azure-cosmos-spark_3-1_2-12/CHANGELOG.md @@ -14,7 +14,8 @@ #### Bugs Fixed * Fixed `IllegalArgumentException` when different throughput control group is defined on the same container - See [PR 34702](https://github.com/Azure/azure-sdk-for-java/pull/34702) - +* Addressed `NullPointerException` in `CosmosDataItemSource` constructor when Spark runtime initialization hasn't completed yet. - See [PR 35201](https://github.com/Azure/azure-sdk-for-java/pull/35201) + ### 4.18.1 (2023-04-10) #### Bugs Fixed diff --git a/sdk/cosmos/azure-cosmos-spark_3-2_2-12/CHANGELOG.md b/sdk/cosmos/azure-cosmos-spark_3-2_2-12/CHANGELOG.md index 82add19044373..edb6324de0eca 100644 --- a/sdk/cosmos/azure-cosmos-spark_3-2_2-12/CHANGELOG.md +++ b/sdk/cosmos/azure-cosmos-spark_3-2_2-12/CHANGELOG.md @@ -14,6 +14,7 @@ #### Bugs Fixed * Fixed `IllegalArgumentException` when different throughput control group is defined on the same container - See [PR 34702](https://github.com/Azure/azure-sdk-for-java/pull/34702) +* Addressed `NullPointerException` in `CosmosDataItemSource` constructor when Spark runtime initialization hasn't completed yet. - See [PR 35201](https://github.com/Azure/azure-sdk-for-java/pull/35201) ### 4.18.1 (2023-04-10) diff --git a/sdk/cosmos/azure-cosmos-spark_3-3_2-12/CHANGELOG.md b/sdk/cosmos/azure-cosmos-spark_3-3_2-12/CHANGELOG.md index b1088e2302370..83f54cf797b2b 100644 --- a/sdk/cosmos/azure-cosmos-spark_3-3_2-12/CHANGELOG.md +++ b/sdk/cosmos/azure-cosmos-spark_3-3_2-12/CHANGELOG.md @@ -14,6 +14,7 @@ #### Bugs Fixed * Fixed `IllegalArgumentException` when different throughput control group is defined on the same container - See [PR 34702](https://github.com/Azure/azure-sdk-for-java/pull/34702) +* Addressed `NullPointerException` in `CosmosDataItemSource` constructor when Spark runtime initialization hasn't completed yet. - See [PR 35201](https://github.com/Azure/azure-sdk-for-java/pull/35201) ### 4.18.1 (2023-04-10) diff --git a/sdk/cosmos/azure-cosmos-spark_3_2-12/src/main/scala/com/azure/cosmos/spark/CosmosItemsDataSource.scala b/sdk/cosmos/azure-cosmos-spark_3_2-12/src/main/scala/com/azure/cosmos/spark/CosmosItemsDataSource.scala index 6f89c4f97c67b..6568db5cbac97 100644 --- a/sdk/cosmos/azure-cosmos-spark_3_2-12/src/main/scala/com/azure/cosmos/spark/CosmosItemsDataSource.scala +++ b/sdk/cosmos/azure-cosmos-spark_3_2-12/src/main/scala/com/azure/cosmos/spark/CosmosItemsDataSource.scala @@ -23,8 +23,10 @@ import scala.collection.JavaConverters._ class CosmosItemsDataSource extends DataSourceRegister with TableProvider with BasicLoggingTrait { logInfo(s"Instantiated ${this.getClass.getSimpleName}") - assertOnSparkDriver() - private lazy val sparkSession = SparkSession.active + private lazy val sparkSession = { + assertOnSparkDriver() + SparkSession.active + } /** * Infer the schema of the table identified by the given options.