[BUG][code-analyzer] sfge: JSON.deserialize with a Type variable throws ClassCastException and aborts the entry point
Nobody has claimed this yet.
Assessment
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Newbie friendliness
- 78/100
Research direction
Start in JSONDeserializeFactory.java around lines 45-52 and inspect how the second JSON.deserialize parameter is converted to a ClassRefExpressionVertex. Use the supplied Type.forName reproduction to verify the dynamic argument no longer aborts analysis. Done means the entry point completes without an InternalExecutionError and treats the non-class-literal type as indeterminate.
Written by the indexing model from the issue text.
Description
Have you tried to resolve this issue yourself first?
- I confirm I have gone through the above steps and still have an issue to report.
Bug Description
Engine: sfge (Salesforce Graph Engine) · Rule: ApexFlsViolation (DevPreview) · Selector: --rule-selector sfge
JSONDeserializeFactory assumes the second argument to JSON.deserialize is always a class literal, and casts without checking:
// JSONDeserializeFactory.java:45-52
// This results in a CastExpression that wraps a MethodCallExpression. The
// second parameter is always
// a ClassRefExpressionVertex that denotes the Type
// (MyObject__c)JSON.deserialize(asJson, MyObject__c.class);
ApexValue.validateParameterSize(vertex, 2);
final ClassRefExpressionVertex classRefExpression =
(ClassRefExpressionVertex) vertex.getParameters().get(1);
The comment says "always", but JSON.deserialize(String, System.Type) accepts any Type expression, and dynamic deserialization via Type.forName(...) is a normal pattern. When the argument is a variable, the cast fails.
Type targetType = Type.forName('Account');
Object o = JSON.deserialize(body, targetType);
Output / Logs
ClassCastException: class com.salesforce.graph.vertex.VariableExpressionVertex$Single cannot be cast to
class com.salesforce.graph.vertex.ClassRefExpressionVertex (...are in unnamed module of loader 'app'):
com.salesforce.graph.symbols.JSONDeserializeFactory.lambda$static$0(JSONDeserializeFactory.java:52);
com.salesforce.graph.ops.ApexStandardLibraryUtil.getStandardType(ApexStandardLibraryUtil.java:155);
com.salesforce.graph.symbols.PathScopeVisitor.afterVisit(PathScopeVisitor.java:1244); ...
Steps To Reproduce
- Create an empty SFDX project (
sfdx-project.jsonwith a singleforce-apppackage directory). - Add
force-app/main/default/classes/JsonDeserializeVarType.clswith the class shown below, plus a standardJsonDeserializeVarType.cls-meta.xml(apiVersion 62.0). - Add
code-analyzer.yml:engines: sfge: java_thread_timeout: 900000 java_thread_count: 4 - Run:
sf code-analyzer run --rule-selector sfge --workspace . --config-file code-analyzer.yml - The run reports an
InternalExecutionErrorfor the entry point instead of analysing it. That entry point yields noApexFlsViolationfindings at all, and nothing in the summary indicates coverage was lost.
public with sharing class JsonDeserializeVarType {
@AuraEnabled
public static void run(String body) {
Type targetType = Type.forName('Account');
Object o = JSON.deserialize(body, targetType);
Account a = (Account) o;
insert a;
}
}
Expected Behavior
When the type argument is not a ClassRefExpressionVertex, return an indeterminate value rather than throwing. The type genuinely is not statically known, which is a normal analysis outcome, not an engine error. An instanceof guard before the cast is sufficient.
Operating System
macOS 26.5.2
Salesforce CLI Version
@salesforce/cli/2.147.7 darwin-arm64 node-v24.5.0
Code Analyzer Plugin (code-analyzer) Version
code-analyzer 5.15.0
Node Version
v24.5.0
Java Version
openjdk version "11.0.32" 2026-07-21
Python Version
N/A
Additional Context (Screenshots, Files, etc)
Worth prioritising beyond its frequency (1 signature / 1 entry point for us): JSON.deserialize into a runtime-chosen type is precisely the shape a taint-tracking engine most wants to reason about, and today it is the shape that reliably kills the analysis instead.
Workaround
Use a class literal where the type is statically known (JSON.deserialize(body, Account.class)). No workaround exists when the target type is genuinely dynamic.
Urgency
Moderate
- Dominant language
- TypeScript
- Stars
- 240
- Forks
- 52
- Avg merge
- 1d 23h
- Merged PRs (30d)
- 5
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from forcedotcom/code-analyzer
-
Difficulty 1/5 Under an hour Newbie friendliness 88/100
forcedotcom/code-analyzer#2093 ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 82/100
forcedotcom/code-analyzer#2091 ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 76/100
forcedotcom/code-analyzer#2090 ·
-
Difficulty 4/5 3-5 days Newbie friendliness 52/100
forcedotcom/code-analyzer#2098 ·
-
Difficulty 3/5 1-2 days Newbie friendliness 72/100
forcedotcom/code-analyzer#2097 ·
All issues in forcedotcom/code-analyzer
Similar issues
-
Difficulty 2/5 1-3 hours Newbie friendliness 84/100
copse-dev/agent-pane#2953 ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 84/100
Eynzof/Hermes-CN-Desktop#610 ·
-
bug clawsweeper:linked-pr-open clawsweeper:needs-live-repro clawsweeper:no-new-fix-pr impact:message-loss issue-rating: 🐚 platinum hermit P2 regression
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
-
enhancement
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
-
calcite-components needs triage refactor
Difficulty 2/5 1-3 hours Newbie friendliness 75/100
Esri/calcite-design-system#15203 ·