{"record":{"id":"c72f04a868c62a12","repo":"JetBrains/intellij-community","slug":"slice-filter-parse-error-expression-must-evaluate","errorCode":"slice.filter.parse.error.expression.must.evaluate.to.constant","errorMessage":"Expression must evaluate to a constant: {0}","messagePattern":"Expression must evaluate to a constant: (.+?)","errorType":"validation","errorClass":"SliceFilterParseException","httpStatus":null,"severity":"error","filePath":"java/java-impl/src/com/intellij/slicer/JavaSliceProvider.java","lineNumber":170,"sourceCode":"        return new JavaValueFilter(DfTypes.referenceConstant(enumConstant, type));\n      } else {\n        throw new SliceFilterParseException(JavaBundle.message(\"slice.filter.parse.error.enum.constant.not.found\", filter));\n      }\n    }\n    PsiExpression constant;\n    try {\n      constant = JavaPsiFacade.getElementFactory(expression.getProject()).createExpressionFromText(filter, expression);\n    }\n    catch (IncorrectOperationException ignore) {\n      throw new SliceFilterParseException(JavaBundle.message(\"slice.filter.parse.error.incorrect.expression\", filter));\n    }\n    PsiType constantType = constant.getType();\n    if (constantType == null || !type.isAssignableFrom(constantType)) {\n      throw new SliceFilterParseException(JavaBundle.message(\"slice.filter.parse.error.incorrect.constant.type\", type.getPresentableText()));\n    }\n    Object o = ExpressionUtils.computeConstantExpression(constant);\n    if (o == null) {\n      throw new SliceFilterParseException(JavaBundle.message(\"slice.filter.parse.error.expression.must.evaluate.to.constant\", filter));\n    }\n    if (relationType != RelationType.EQ) {\n      if (!(o instanceof Number)) {\n        throw new SliceFilterParseException(JavaBundle.message(\"slice.filter.parse.error.incorrect.constant.expected.number\", filter));\n      }\n      if (PsiTypes.longType().equals(type)) {\n        LongRangeSet rangeSet = LongRangeSet.point(((Number)o).longValue()).fromRelation(relationType);\n        return new JavaValueFilter(DfTypes.longRange(rangeSet));\n      }\n      LongRangeSet rangeSet = LongRangeSet.point(((Number)o).intValue()).fromRelation(relationType);\n      return new JavaValueFilter(DfTypes.intRangeClamped(rangeSet));\n    }\n    return new JavaValueFilter(DfTypes.constant(o, type));\n  }\n\n  private static @Nullable PsiType getType(@NotNull PsiElement expression) {\n    if (expression instanceof PsiExpression) {\n      return ((PsiExpression)expression).getType();","sourceCodeStart":152,"sourceCodeEnd":188,"githubUrl":"https://github.com/JetBrains/intellij-community/blob/be881553f2a76ac8b4ea53950d93f0de78295c19/java/java-impl/src/com/intellij/slicer/JavaSliceProvider.java#L152-L188","documentation":"Thrown by JavaSliceProvider.parseFilter when the filter expression is syntactically valid and type-compatible but does not fold to a compile-time constant. ExpressionUtils.computeConstantExpression(constant) returning null (no constant value) triggers SliceFilterParseException; slice value filters only support dataflow-tractable constants.","triggerScenarios":"Entering a filter like 'Math.random()', 'System.currentTimeMillis()', 'new Date()', or a reference to a non-final/non-constant local variable — valid Java, right type, but no compile-time constant value.","commonSituations":"Users expecting runtime evaluation semantics from the filter; filtering on static final fields that are not compile-time constants (e.g. initialized with a method call); filtering on enum-adjacent static fields instead of enum constants.","solutions":["Use a literal or a compile-time constant expression (e.g. '42', '\"abc\"', 'true').","For enum-typed values use the bare enum constant name, which takes the dedicated enum branch and needs no evaluation.","Replace 'new X(...)' or method-call filters with the concrete value you care about.","Remember the filter describes a dataflow fact, not a predicate evaluated at runtime."],"exampleFix":"// before:\nfilter = \"System.currentTimeMillis()\"\n\n// after:\nfilter = \"1000L\"","handlingStrategy":"validation","validationCode":"Object v = ExpressionUtils.computeConstantExpression(candidate);\nif (v == null) {\n  // filter expression does not fold to a constant — reject with guidance\n}","typeGuard":null,"tryCatchPattern":"try { provider.parseFilter(expression, filter); } catch (SliceFilterParseException e) { /* ask user for a constant expression */ }","preventionTips":["Restrict filter suggestions to literals and compile-time constants.","Do not expect runtime evaluation in slice filters."],"tags":["java","intellij","dataflow","slice","constant-evaluation","user-input"],"backgroundTag":null,"analyzedSha":"be881553f2a76ac8b4ea53950d93f0de78295c19","analyzedAt":"2026-08-14T14:13:06.425Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}