Skip to content

Commit

Permalink
SI-7474 Record extra errors in Throwable#suppressedExceptions
Browse files Browse the repository at this point in the history
... in parallel collection operations.

Followup to bcbe38d, which did away with the the approach to
use a composite exception when more than one error happened.
  • Loading branch information
retronym committed Mar 29, 2016
1 parent ca606e6 commit d40f1b8
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 12 deletions.
11 changes: 4 additions & 7 deletions src/library/scala/collection/parallel/Tasks.scala
Expand Up @@ -66,13 +66,10 @@ trait Task[R, +Tp] {
}

private[parallel] def mergeThrowables(that: Task[_, _]) {
// TODO: As soon as we target Java >= 7, use Throwable#addSuppressed
// to pass additional Throwables to the caller, e. g.
// if (this.throwable != null && that.throwable != null)
// this.throwable.addSuppressed(that.throwable)
// For now, we just use whatever Throwable comes across “first”.
if (this.throwable == null && that.throwable != null)
this.throwable = that.throwable
if (this.throwable != null && that.throwable != null)
this.throwable.addSuppressed(that.throwable)
else if (this.throwable == null && that.throwable != null)
this.throwable = that.throwable
}

// override in concrete task implementations to signal abort to other tasks
Expand Down
1 change: 0 additions & 1 deletion test/files/run/t5375.check
@@ -1 +0,0 @@
Runtime exception
16 changes: 12 additions & 4 deletions test/files/run/t5375.scala
@@ -1,8 +1,16 @@
object Test extends App {
val foos = (1 to 1000).toSeq
try
foos.par.map(i => if (i % 37 == 0) sys.error("i div 37") else i)
catch {
case ex: RuntimeException => println("Runtime exception")
try {
foos.par.map(i => if (i % 37 == 0) throw new MultipleOf37Exception(i) else i)
assert(false)
} catch {
case ex: MultipleOf37Exception =>
assert(ex.getSuppressed.size > 0)
assert(ex.getSuppressed.forall(_.isInstanceOf[MultipleOf37Exception]))
assert(ex.i == 37)
assert(ex.getSuppressed.map(_.asInstanceOf[MultipleOf37Exception].i).toList == List(74, 148, 259, 518))
case _: Throwable =>
assert(false)
}
class MultipleOf37Exception(val i: Int) extends RuntimeException
}

0 comments on commit d40f1b8

Please sign in to comment.