Skip to content

Commit a607a26

Browse files
committed
[SPARK-20940][CORE] Replace IllegalAccessError with IllegalStateException
## What changes were proposed in this pull request? `IllegalAccessError` is a fatal error (a subclass of LinkageError) and its meaning is `Thrown if an application attempts to access or modify a field, or to call a method that it does not have access to`. Throwing a fatal error for AccumulatorV2 is not necessary and is pretty bad because it usually will just kill executors or SparkContext ([SPARK-20666](https://issues.apache.org/jira/browse/SPARK-20666) is an example of killing SparkContext due to `IllegalAccessError`). I think the correct type of exception in AccumulatorV2 should be `IllegalStateException`. ## How was this patch tested? Jenkins Author: Shixiong Zhu <shixiong@databricks.com> Closes #18168 from zsxwing/SPARK-20940. (cherry picked from commit 24db358) Signed-off-by: Shixiong Zhu <shixiong@databricks.com>
1 parent f59f9a3 commit a607a26

File tree

2 files changed

+3
-3
lines changed

2 files changed

+3
-3
lines changed

core/src/main/scala/org/apache/spark/util/AccumulatorV2.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ abstract class AccumulatorV2[IN, OUT] extends Serializable {
6868

6969
private def assertMetadataNotNull(): Unit = {
7070
if (metadata == null) {
71-
throw new IllegalAccessError("The metadata of this accumulator has not been assigned yet.")
71+
throw new IllegalStateException("The metadata of this accumulator has not been assigned yet.")
7272
}
7373
}
7474

@@ -265,7 +265,7 @@ private[spark] object AccumulatorContext {
265265
// Since we are storing weak references, we must check whether the underlying data is valid.
266266
val acc = ref.get
267267
if (acc eq null) {
268-
throw new IllegalAccessError(s"Attempted to access garbage collected accumulator $id")
268+
throw new IllegalStateException(s"Attempted to access garbage collected accumulator $id")
269269
}
270270
acc
271271
}

core/src/test/scala/org/apache/spark/AccumulatorSuite.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -210,7 +210,7 @@ class AccumulatorSuite extends SparkFunSuite with Matchers with LocalSparkContex
210210
assert(ref.get.isEmpty)
211211

212212
// Getting a garbage collected accum should throw error
213-
intercept[IllegalAccessError] {
213+
intercept[IllegalStateException] {
214214
AccumulatorContext.get(accId)
215215
}
216216

0 commit comments

Comments
 (0)