forcedotcom / forcedotcom/code-analyzer

[BUG][code-analyzer] SFGE engine fails on for loops with ?? operator

Open
#1,813 3 comments 0 reactions 0 assignees View on GitHub
SFGE
Dominant language
TypeScript
Stars
240
Forks
52
Avg merge
1d 23h
Merged PRs (30d)
5

Description

### Have you tried to resolve this issue yourself first?

- [x] I confirm I have gone through the above steps and still have an issue to report

### Bug Description

When running SFGE engine, we see that when ?? is used in a for loop, there is an error
Example snippet

``
for (Account a : aList ?? new List()) {
system.debug('do something');
}
``

I assume this is a bug/issue with underlying AST parser or similar as the ?? operator is relatively new in Apex

### Output / Logs

2025-05-20 00:23:01 ERROR Sfge:159 - Unexpected exception while loading graph
com.salesforce.exception.UnexpectedException: vp[FirstChild->true], vp[BeginLine->29], vp[DefiningType_CaseSafe->EXAMPLECLASS...], vp[LastChild->true], vp[DefiningType->EXAMPLECLASS...], vp[EndLine->29], vp[childIdx->0], vp[BeginColumn->4]
at com.salesforce.graph.build.GremlinUtil.getChildren(GremlinUtil.java:60) ~[sfge-1.0.0.jar:?]
at com.salesforce.graph.build.MethodPathBuilderVisitor.visitForEachStatement(MethodPathBuilderVisitor.java:235) ~[sfge-1.0.0.jar:?]
at com.salesforce.graph.build.MethodPathBuilderVisitor._visit(MethodPathBuilderVisitor.java:130) ~[sfge-1.0.0.jar:?]
at com.salesforce.graph.build.MethodPathBuilderVisitor._visit(MethodPathBuilderVisitor.java:159) ~[sfge-1.0.0.jar:?]
at com.salesforce.graph.build.MethodPathBuilderVisitor._visit(MethodPathBuilderVisitor.java:159) ~[sfge-1.0.0.jar:?]
at com.salesforce.graph.build.MethodPathBuilderVisitor._visit(MethodPathBuilderVisitor.java:159) ~[sfge-1.0.0.jar:?]
at com.salesforce.graph.build.MethodPathBuilderVisitor.apply(MethodPathBuilderVisitor.java:97) ~[sfge-1.0.0.jar:?]
at com.salesforce.graph.build.AbstractApexVertexBuilder.afterInsert(AbstractApexVertexBuilder.java:169) ~[sfge-1.0.0.jar:?]
at com.salesforce.graph.build.AbstractApexVertexBuilder.buildVertices(AbstractApexVertexBuilder.java:153) ~[sfge-1.0.0.jar:?]
at com.salesforce.graph.build.AbstractApexVertexBuilder.buildVertices(AbstractApexVertexBuilder.java:125) ~[sfge-1.0.0.jar:?]
at com.salesforce.graph.build.AbstractApexVertexBuilder.buildVertices(AbstractApexVertexBuilder.java:35) ~[sfge-1.0.0.jar:?]
at com.salesforce.graph.build.CustomerApexVertexBuilder.build(CustomerApexVertexBuilder.java:21) ~[sfge-1.0.0.jar:?]
at com.salesforce.graph.build.Util.buildGraph(Util.java:39) ~[sfge-1.0.0.jar:?]
at com.salesforce.graph.ops.GraphUtil.loadSourceFilesAndFolders(GraphUtil.java:170) ~[sfge-1.0.0.jar:?]
at com.salesforce.Sfge$Dependencies.loadSourceFilesAndFoldersToGraph(Sfge.java:249) ~[sfge-1.0.0.jar:?]
at com.salesforce.Sfge.execute(Sfge.java:153) [sfge-1.0.0.jar:?]
at com.salesforce.Sfge.process(Sfge.java:103) [sfge-1.0.0.jar:?]
at com.salesforce.Sfge.main(Sfge.java:71) [sfge-1.0.0.jar:?]

### Steps To Reproduce

1. Write apex class containing ?? in for loop.
2. run SFGE engine covering aforementioned code
3. refer to logs

### Expected Behavior

?? should be accepted as is valid json.

### Operating System

Windows 11

### Salesforce CLI Version

@salesforce/cli/2.88.6 win32-x64 node-v22.14.0

### Code Analyzer Plugin (code-analyzer) Version

code-analyzer 5.0.0 (>=5.0.0 <6.0.0-0)

### Node Version

v22.14.0

### Java Version

openjdk version "17.0.11" 2024-04-16 LTS OpenJDK Runtime Environment Zulu17.50+19-CA (build 17.0.11+9-LTS) OpenJDK 64-Bit Server VM Zulu17.50+19-CA (build 17.0.11+9-LTS, mixed mode, sharing)

### Python Version

_No response_

### Additional Context (Screenshots, Files, etc)

_No response_

### Workaround

bring ?? outside of for loop, assign variable, then use in for loop.

### Urgency

Low

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.