Extra catch-ignore for source attributes in case not possible #30138

This commit is contained in:
Johan Andrén 2021-04-09 14:01:49 +02:00 committed by GitHub
parent 031886a7b3
commit 0a226eb3ea
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 26 additions and 1 deletions

View file

@ -0,0 +1,21 @@
/*
* Copyright (C) 2009-2021 Lightbend Inc. <https://www.lightbend.com>
*/
package akka.stream
import akka.stream.scaladsl.Flow
import akka.stream.testkit.StreamSpec
class SourceLocationAttributeSpec extends StreamSpec {
"The SourceLocation attribute" must {
"not throw NPE" in {
// #30138
val f1 = Flow[Int].fold(0)(_ + _)
val f2 = Flow[Int].fold(0)(_ + _)
f1.join(f2).toString
}
}
}

View file

@ -21,6 +21,8 @@ import akka.util.{ ByteString, OptionVal }
import akka.util.JavaDurationConverters._
import akka.util.LineNumbers
import scala.util.control.NonFatal
/**
* Holds attributes which can be used to alter [[akka.stream.scaladsl.Flow]] / [[akka.stream.javadsl.Flow]]
* or [[akka.stream.scaladsl.GraphDSL]] / [[akka.stream.javadsl.GraphDSL]] materialization.
@ -308,7 +310,7 @@ object Attributes {
* for debugging. Included in the default toString of GraphStageLogic if present
*/
final class SourceLocation(lambda: AnyRef) extends Attribute {
lazy val locationName: String = {
lazy val locationName: String = try {
val locationName = LineNumbers(lambda) match {
case LineNumbers.NoSourceInfo => "unknown"
case LineNumbers.UnknownSourceFormat(_) => "unknown"
@ -317,6 +319,8 @@ object Attributes {
s"$filename:$from"
}
s"${lambda.getClass.getPackage.getName}-$locationName"
} catch {
case NonFatal(_) => "unknown" // location is not critical so give up without failing
}
override def toString: String = locationName