Skip to content

Commit

Permalink
[x2cpg] Safe Handling of null node for `AstNodeBuilder.unknownNod…
Browse files Browse the repository at this point in the history
…e` (#3796)

Currently, when forming an `Unknown` node there is a chance that we are unable to get the `className` effectively. This PR aims to add handling for such cases.
  • Loading branch information
khemrajrathore authored Nov 6, 2023
1 parent 17a3c7a commit 3d67ca3
Showing 1 changed file with 2 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import io.shiftleft.codepropertygraph.generated.nodes.{
}
import org.apache.commons.lang.StringUtils

import scala.util.Try
trait AstNodeBuilder[Node, NodeProcessor] { this: NodeProcessor =>
protected def line(node: Node): Option[Integer]
protected def column(node: Node): Option[Integer]
Expand All @@ -46,7 +47,7 @@ trait AstNodeBuilder[Node, NodeProcessor] { this: NodeProcessor =>

protected def unknownNode(node: Node, code: String): NewUnknown = {
NewUnknown()
.parserTypeName(node.getClass.getSimpleName)
.parserTypeName(Try(node.getClass.getSimpleName).toOption.getOrElse(Defines.Unknown))
.code(code)
.lineNumber(line(node))
.columnNumber(column(node))
Expand Down

0 comments on commit 3d67ca3

Please sign in to comment.