Skip to content

Commit

Permalink
IllegalStateException -> SparkException.internalError
Browse files Browse the repository at this point in the history
  • Loading branch information
ankurdave committed Nov 9, 2024
1 parent 69cf66f commit 1b3cd27
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ package org.apache.spark.util
import java.io.OutputStream
import java.nio.ByteBuffer

import org.apache.spark.SparkException
import org.apache.spark.storage.StorageUtils
import org.apache.spark.unsafe.Platform

Expand Down Expand Up @@ -67,7 +68,7 @@ private[spark] class DirectByteBufferOutputStream(capacity: Int) extends OutputS

private def checkNotClosed(): Unit = {
if (buffer == null) {
throw new IllegalStateException(
throw SparkException.internalError(
"Cannot call methods on a closed DirectByteBufferOutputStream")
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

package org.apache.spark.util

import org.apache.spark.SparkFunSuite
import org.apache.spark.{SparkException, SparkFunSuite}

class DirectByteBufferOutputStreamSuite extends SparkFunSuite {
test("use after close") {
Expand All @@ -28,11 +28,11 @@ class DirectByteBufferOutputStreamSuite extends SparkFunSuite {
o.close()

// Using `o` after close should throw an exception rather than crashing.
assertThrows[IllegalStateException] { o.write(123) }
assertThrows[IllegalStateException] { o.write(new Array[Byte](size), 0, size) }
assertThrows[IllegalStateException] { o.reset() }
assertThrows[IllegalStateException] { o.size() }
assertThrows[IllegalStateException] { o.toByteBuffer }
assertThrows[SparkException] { o.write(123) }
assertThrows[SparkException] { o.write(new Array[Byte](size), 0, size) }
assertThrows[SparkException] { o.reset() }
assertThrows[SparkException] { o.size() }
assertThrows[SparkException] { o.toByteBuffer }

// Using `b` after `o` is closed may crash.
// val arr = new Array[Byte](size)
Expand Down

0 comments on commit 1b3cd27

Please sign in to comment.