Skip to content

[Bug]Keyword "final" not resolved in Javasrc2cpg #5654

@jjzdxmd

Description

@jjzdxmd

Keyword "final" not resolved in Javasrc2cpg
When i import a java source code in joern , i try to find cpg members modified by final. But all of keywords "final" is missed so i can not find the certain member I need.
To Reproduce
Steps to reproduce the behavior:

  1. import a Java source code in Joern
  2. In joern shell ,query "cpg.member.modifier.modifierType("FINAL")"
  3. find joern output "val res2: Iterator[io.shiftleft.codepropertygraph.generated.nodes.Modifier] = empty iterator"

Expected behavior
Query "cpg.member.modifier.modifierType("FINAL")" should list all members modified by 'final'

Screenshots

Image

Desktop (please complete the following information):

  • MacOS
  • Joern Version 4.0.421
  • Java version 21.06

Additional context
How to fix:
In /joern-cli/frontends/javasrc2cpg/src/main/scala/io/joern/javasrc2cpg/astcreation/declarations/AstForTypeDeclsCreator.scala#L705 modifiersForFieldDeclaration,modify as follow:

    val staticModifier =
      Option.when(decl.isStatic)(modifierNode(decl, ModifierTypes.STATIC))
    val finalModifier =
      Option.when(decl.isFinal)(modifierNode(decl, ModifierTypes.FINAL))
    val accessModifierType =
      if (decl.isPublic)
        Some(ModifierTypes.PUBLIC)
      else if (decl.isPrivate)
        Some(ModifierTypes.PRIVATE)
      else if (decl.isProtected)
        Some(ModifierTypes.PROTECTED)
      else
        None

    val accessModifier = accessModifierType.map(modifierNode(decl, _))

    List(staticModifier, finalModifier, accessModifier).flatten.map(Ast(_))
  }

Metadata

Metadata

Labels

bugSomething isn't working

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions