JetBrains/intellij-community · error · SliceFilterParseException
slice.filter.parse.error.incorrect.constant.expected.number
slice.filter.parse.error.incorrect.constant.expected.number
Error message
Incorrect constant (expected number): {0} What it means
Thrown by JavaSliceProvider.parseFilter when the filter starts with a relational operator (relationType != EQ, i.e. '>', '<', '>=', '<=', '==', '!=' prefixes supported for byte/char/short/int/long types) but the remaining expression evaluates to a non-Number constant. The relational branch builds LongRangeSet constraints and requires the constant to be numeric.
Source
Thrown at java/java-impl/src/com/intellij/slicer/JavaSliceProvider.java:174
}
PsiExpression constant;
try {
constant = JavaPsiFacade.getElementFactory(expression.getProject()).createExpressionFromText(filter, expression);
}
catch (IncorrectOperationException ignore) {
throw new SliceFilterParseException(JavaBundle.message("slice.filter.parse.error.incorrect.expression", filter));
}
PsiType constantType = constant.getType();
if (constantType == null || !type.isAssignableFrom(constantType)) {
throw new SliceFilterParseException(JavaBundle.message("slice.filter.parse.error.incorrect.constant.type", type.getPresentableText()));
}
Object o = ExpressionUtils.computeConstantExpression(constant);
if (o == null) {
throw new SliceFilterParseException(JavaBundle.message("slice.filter.parse.error.expression.must.evaluate.to.constant", filter));
}
if (relationType != RelationType.EQ) {
if (!(o instanceof Number)) {
throw new SliceFilterParseException(JavaBundle.message("slice.filter.parse.error.incorrect.constant.expected.number", filter));
}
if (PsiTypes.longType().equals(type)) {
LongRangeSet rangeSet = LongRangeSet.point(((Number)o).longValue()).fromRelation(relationType);
return new JavaValueFilter(DfTypes.longRange(rangeSet));
}
LongRangeSet rangeSet = LongRangeSet.point(((Number)o).intValue()).fromRelation(relationType);
return new JavaValueFilter(DfTypes.intRangeClamped(rangeSet));
}
return new JavaValueFilter(DfTypes.constant(o, type));
}
private static @Nullable PsiType getType(@NotNull PsiElement expression) {
if (expression instanceof PsiExpression) {
return ((PsiExpression)expression).getType();
}
else if (expression instanceof PsiVariable) {
return ((PsiVariable)expression).getType();
}View on GitHub (pinned to be881553f2)
Solutions
- Use an unquoted numeric literal with relational filters, e.g. '>=5' not '>="5"'.
- Remove the relational prefix if you intend an equality/enum/null filter.
- Verify the sliced variable is one of byte/char/short/int/long — relational prefixes are only honored for those types anyway.
Example fix
// before: filter = ">= \"10\"" // after: filter = ">=10"
Defensive patterns
Strategy: validation
Validate before calling
if (relationType != RelationType.EQ && !(computed instanceof Number)) {
// relational filter requires a numeric constant — reject
} Try / catch
try { provider.parseFilter(expression, filter); } catch (SliceFilterParseException e) { /* relational filters need numbers: re-prompt */ } Prevention
- With relational filters (>=, <, ...) always use bare numeric literals, not strings or booleans.
- Offer numeric-only input assistance when a relational prefix is detected.
When it happens
Trigger: Slicing an int variable and entering '>= "abc"' or '>= true' — the type check passes for some inputs but computeConstantExpression yields a String/Boolean/Character that is not a java.lang.Number.
Common situations: Users adding comparison operators to non-numeric-looking filters; filtering char values where the evaluated constant resolves to something non-numeric; typos like '>="5"' (a quoted string) instead of '>=5'.
Related errors
- slice.filter.parse.error.not.null.filter.not.applicable.for.primitive.type
- slice.filter.parse.error.enum.constant.not.found
- slice.filter.parse.error.incorrect.expression
- slice.filter.parse.error.incorrect.constant.type
- slice.filter.parse.error.expression.must.evaluate.to.constant
AI-assisted analysis of JetBrains/intellij-community@be881553f2 (2026-08-14).
Data as JSON: /api/errors/08888086feecb38f.
Report an issue: GitHub.