-
Notifications
You must be signed in to change notification settings - Fork 361
Closed
Labels
bugSomething isn't workingSomething isn't working
Description
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:
- import a Java source code in Joern
- In joern shell ,query "cpg.member.modifier.modifierType("FINAL")"
- 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

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
Assignees
Labels
bugSomething isn't workingSomething isn't working