{"record":{"id":"a80704c1396ef821","repo":"oracle/graal","slug":"negative-compilationfinal-dimensions","errorCode":null,"errorMessage":"Negative @CompilationFinal dimensions","messagePattern":"Negative @CompilationFinal dimensions","errorType":"validation","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"compiler/src/jdk.graal.compiler/src/jdk/graal/compiler/truffle/PartialEvaluator.java","lineNumber":164,"sourceCode":"        lastTierDecodingPlugins.maybePrintIntrinsics(options);\n    }\n\n    private static int getArrayDimensions(JavaType type) {\n        int dimensions = 0;\n        for (JavaType componentType = type; componentType.isArray(); componentType = componentType.getComponentType()) {\n            dimensions++;\n        }\n        return dimensions;\n    }\n\n    private static int actualStableDimensions(ResolvedJavaField field, int dimensions) {\n        if (dimensions == 0) {\n            return 0;\n        }\n        int arrayDim = getArrayDimensions(field.getType());\n        if (dimensions < 0) {\n            if (dimensions != -1) {\n                throw new IllegalArgumentException(\"Negative @CompilationFinal dimensions\");\n            }\n            return arrayDim;\n        }\n        if (dimensions > arrayDim) {\n            throw new IllegalArgumentException(String.format(\"@CompilationFinal(dimensions=%d) exceeds declared array dimensions (%d) of field %s\", dimensions, arrayDim, field));\n        }\n        return dimensions;\n    }\n\n    /**\n     * Gets an object describing how a read of {@code field} can be constant folded based on Truffle\n     * annotations.\n     *\n     * @param field the field for which to compute {@link ConstantFieldInfo}\n     * @param declaredAnnotationValues a map of method annotations keyed by their declaring\n     *            {@link ResolvedJavaType}\n     * @param types cached types known to the Truffle compiler\n     * @param unwrapType a function that unwraps a {@link ResolvedJavaType} obtained from","sourceCodeStart":146,"sourceCodeEnd":182,"githubUrl":"https://github.com/oracle/graal/blob/a66e9ccd1d7bf2552883939aa0788dfd0e294aab/compiler/src/jdk.graal.compiler/src/jdk/graal/compiler/truffle/PartialEvaluator.java#L146-L182","documentation":"PartialEvaluator.actualStableDimensions validates the dimensions attribute of Truffle's @CompilationFinal annotation. The value -1 is the sentinel meaning 'all array dimensions of the field'; any other negative value (dimensions < 0 && != -1) throws IllegalArgumentException('Negative @CompilationFinal dimensions').","triggerScenarios":"Declaring a field with @CompilationFinal(dimensions = -2) or any negative value other than the -1 sentinel.","commonSituations":"Hand-writing the annotation with an arithmetic expression that evaluates below -1; porting code where -1 was computed dynamically and the computation went below -1; misunderstanding that only -1 has special meaning.","solutions":["Use dimensions = -1 for 'all dimensions', or a non-negative count.","If dimensions is computed, clamp/validate it to the range [-1, arrayDim] before applying the annotation."],"exampleFix":"// before\n@CompilationFinal(dimensions = -2)\nObject[] cache;\n\n// after\n@CompilationFinal(dimensions = -1) // all dimensions treated as compilation-final\nObject[] cache;","handlingStrategy":"validation","validationCode":"// Validate an annotation dimension value before it reaches the partial evaluator\nstatic boolean validDimensions(int d) {\n    return d == -1 || d >= 0;\n}\nif (!validDimensions(dimensions)) {\n    throw new IllegalArgumentException(\"@CompilationFinal dimensions must be -1 or >= 0, got \" + dimensions);\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Remember -1 is the only negative sentinel ('all dimensions'); every other negative value is invalid.","If dimensions is computed from configuration, validate it to [-1, arrayDepth] at config load time."],"tags":["graal","truffle","compilation-final","annotation","validation"],"backgroundTag":null,"analyzedSha":"a66e9ccd1d7bf2552883939aa0788dfd0e294aab","analyzedAt":"2026-08-14T13:58:47.161Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}