Extra catch-ignore for source attributes in case not possible #30138
This commit is contained in:
parent
031886a7b3
commit
0a226eb3ea
2 changed files with 26 additions and 1 deletions
|
|
@ -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
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -21,6 +21,8 @@ import akka.util.{ ByteString, OptionVal }
|
||||||
import akka.util.JavaDurationConverters._
|
import akka.util.JavaDurationConverters._
|
||||||
import akka.util.LineNumbers
|
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]]
|
* 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.
|
* 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
|
* for debugging. Included in the default toString of GraphStageLogic if present
|
||||||
*/
|
*/
|
||||||
final class SourceLocation(lambda: AnyRef) extends Attribute {
|
final class SourceLocation(lambda: AnyRef) extends Attribute {
|
||||||
lazy val locationName: String = {
|
lazy val locationName: String = try {
|
||||||
val locationName = LineNumbers(lambda) match {
|
val locationName = LineNumbers(lambda) match {
|
||||||
case LineNumbers.NoSourceInfo => "unknown"
|
case LineNumbers.NoSourceInfo => "unknown"
|
||||||
case LineNumbers.UnknownSourceFormat(_) => "unknown"
|
case LineNumbers.UnknownSourceFormat(_) => "unknown"
|
||||||
|
|
@ -317,6 +319,8 @@ object Attributes {
|
||||||
s"$filename:$from"
|
s"$filename:$from"
|
||||||
}
|
}
|
||||||
s"${lambda.getClass.getPackage.getName}-$locationName"
|
s"${lambda.getClass.getPackage.getName}-$locationName"
|
||||||
|
} catch {
|
||||||
|
case NonFatal(_) => "unknown" // location is not critical so give up without failing
|
||||||
}
|
}
|
||||||
|
|
||||||
override def toString: String = locationName
|
override def toString: String = locationName
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue