forcedotcom / forcedotcom/code-analyzer
[BUG][code-analyzer] SFGE engine fails on for loops with ?? operator
- Lingua principale
- TypeScript
- Stelle
- 240
- Fork
- 52
- Merge medio
- 1g 23h
- PR unite (30g)
- 5
Descrizione
### 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
Guida per i contributori
Apri la guida per i contributori
Direzione di ricerca
Reproduce the failure with the Apex for-loop example, then start at MethodPathBuilderVisitor.java, especially visitForEachStatement, and follow the GremlinUtil.getChildren call shown in the stack trace. Confirm that SFGE loads the source and builds its graph without throwing UnexpectedException when the ?? operator appears in the loop.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Valutazione
- Stack tecnologico
- java
- Ambito
- devtools
- Tipo di issue
- Bug
- Difficoltà
- 3/5
- Tempo stimato
- 1-2 giorni
- Stato di attività
- Attiva
- Chiarezza
- Abbastanza chiara
- Idoneità per principianti
- 65/100