{"record":{"id":"077df12e6199cd5b","repo":"oracle/graal","slug":"switch-case-probability-could-not-be-injected-bec","errorCode":null,"errorMessage":"Switch case probability could not be injected, because the probability value did not reduce to a constant value.","messagePattern":"Switch case probability could not be injected, because the probability value did not reduce to a constant value\\.","errorType":"exception","errorClass":"GraalError","httpStatus":null,"severity":"error","filePath":"compiler/src/jdk.graal.compiler/src/jdk/graal/compiler/nodes/extended/SwitchCaseProbabilityNode.java","lineNumber":73,"sourceCode":"    @Input ValueNode probability;\n\n    public SwitchCaseProbabilityNode(ValueNode probability) {\n        super(TYPE, StampFactory.forKind(JavaKind.Void));\n        this.probability = probability;\n    }\n\n    public ValueNode getProbability() {\n        return probability;\n    }\n\n    public void setProbability(ValueNode probability) {\n        updateUsages(this.probability, probability);\n        this.probability = probability;\n    }\n\n    @Override\n    public void lower(LoweringTool tool) {\n        throw new GraalError(\"Switch case probability could not be injected, because the probability value did not reduce to a constant value.\");\n    }\n}\n","sourceCodeStart":55,"sourceCodeEnd":76,"githubUrl":"https://github.com/oracle/graal/blob/a66e9ccd1d7bf2552883939aa0788dfd0e294aab/compiler/src/jdk.graal.compiler/src/jdk/graal/compiler/nodes/extended/SwitchCaseProbabilityNode.java#L55-L76","documentation":"SwitchCaseProbabilityNode is the switch-case analogue of BranchProbabilityNode: during simplification its probability array should constant-fold and be consumed into the switch's key probabilities. If the node survives to the lowering phase, the probability value did not reduce to a constant, and lower() throws — mirroring the branch-probability rule that these hints must be compile-time constants.","triggerScenarios":"Constructing a SwitchCaseProbabilityNode (via the switch-case probability intrinsic/annotation support) with a non-constant probability input: runtime-computed doubles, non-final fields, or values blocked from constant folding, so the node is still present during lowering.","commonSituations":"Passing profile-derived or computed probabilities to switch probability hints; refactoring constants into non-static-final fields; snippet parameters not marked constant.","solutions":["Supply a compile-time constant for the case probability (literal or static final)","If probabilities vary at run time, remove the hint node and rely on regular profile-based switch probabilities","In snippet/substitution code, mark probability inputs as constant parameters so they fold before lowering"],"exampleFix":"// before\nSwitchCaseProbabilityNode.probability(dynamicProbs[i], key)\n\n// after\nprivate static final double[] CASE_PROBS = {0.7, 0.2, 0.1};\nSwitchCaseProbabilityNode.probability(CASE_PROBS[i], key)","handlingStrategy":"validation","validationCode":"private static final double[] CASE_PROBS = {0.7, 0.2, 0.1};\n// ensure any probability fed to the switch-case hint is a compile-time constant:\nif (!probabilityInput.isConstant()) throw new IllegalStateException(\"switch case probability must be constant\");","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Use static final constants for switch-case probabilities","Mark probability parameters as constant in snippet definitions","For runtime-varying profiles, omit the hint and let profiling supply switch probabilities"],"tags":["graalvm","switch-probability","intrinsic-misuse","lowering"],"backgroundTag":null,"analyzedSha":"a66e9ccd1d7bf2552883939aa0788dfd0e294aab","analyzedAt":"2026-08-14T13:58:47.161Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}