Skip to content

Commit

Permalink
[javasrc2cpg] support flows for field accesses with a TYPE_REF base n…
Browse files Browse the repository at this point in the history
…ode (#5076)

* [javasrc2cpg] support flows for field accesses with a TYPE_REF base node

* scalafmt

* simplify `.where(_.or...)` with `.or(...)` cf. review suggestion

Co-authored-by: maltek <1694194+maltek@users.noreply.github.com>

---------

Co-authored-by: maltek <1694194+maltek@users.noreply.github.com>
  • Loading branch information
xavierpinho and maltek authored Nov 7, 2024
1 parent 6470dd7 commit 6465bfe
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,10 @@ class SourceToStartingPointsInMethod(
private def usageInOtherClasses(m: Method, usageInputs: List[UsageInput]): List[StartingPointWithSource] = {
usageInputs.flatMap { case UsageInput(src, typeDecl, astNode) =>
m.fieldAccess
.where(_.argument(1).isIdentifier.typeFullNameExact(typeDecl.fullName))
.or(
_.argument(1).isIdentifier.typeFullNameExact(typeDecl.fullName),
_.argument(1).isTypeRef.typeFullNameExact(typeDecl.fullName)
)
.where { x =>
astNode match {
case identifier: Identifier =>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,7 @@ import io.shiftleft.semanticcpg.language.*

class NewObjectTests extends JavaSrcCode2CpgFixture(withOssDataflow = true) {

// FIXME: stopped working after https://github.com/joernio/joern/pull/5036
"static field passed as an argument inside a same-class static method whilst being referenced by its simple name" ignore {
"static field passed as an argument inside a same-class static method whilst being referenced by its simple name" in {
val cpg = code("""
|class Bar {
| static String CONST = "<const>";
Expand All @@ -18,7 +17,7 @@ class NewObjectTests extends JavaSrcCode2CpgFixture(withOssDataflow = true) {
val sink = cpg.call("println").argument(1)
val source = cpg.literal
sink.reachableByFlows(source).map(flowToResultPairs).l shouldBe List(
List(("String Bar.CONST = \"<const>\"", Some(3)), ("System.out.println(Bar.CONST)", Some(5)))
List(("String Bar.CONST = \"<const>\"", Some(3)), ("System.out.println(CONST)", Some(5)))
)
}

Expand Down

0 comments on commit 6465bfe

Please sign in to comment.