JetBrains/intellij-community · error · SliceFilterParseException
slice.filter.parse.error.incorrect.expression
slice.filter.parse.error.incorrect.expression
Error message
Incorrect expression: {0} What it means
Thrown by JavaSliceProvider.parseFilter when the filter text cannot be parsed into a Java expression. After the 'null'/enum branches fail to match, the parser calls JavaPsiFacade.getElementFactory().createExpressionFromText(filter, expression); if that raises IncorrectOperationException (the text is not syntactically valid Java), it is wrapped in SliceFilterParseException.
Source
Thrown at java/java-impl/src/com/intellij/slicer/JavaSliceProvider.java:162
break;
}
}
}
PsiClass psiClass = PsiUtil.resolveClassInClassTypeOnly(type);
if (psiClass != null && psiClass.isEnum()) {
PsiField enumConstant = psiClass.findFieldByName(filter, false);
if (enumConstant instanceof PsiEnumConstant) {
return new JavaValueFilter(DfTypes.referenceConstant(enumConstant, type));
} else {
throw new SliceFilterParseException(JavaBundle.message("slice.filter.parse.error.enum.constant.not.found", filter));
}
}
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);View on GitHub (pinned to be881553f2)
Solutions
- Correct the filter so it is a syntactically valid Java expression (literal, constant reference, or simple expression).
- For string comparison use a quoted literal, e.g. "\"foo\"" in the filter field.
- Verify balanced parentheses/quotes and remove stray characters.
- Remember the expression is parsed in the context of the sliced element, so only context-free constant expressions make sense.
Example fix
// before: filter = "foo'" // after: filter = "\"foo\""
Defensive patterns
Strategy: try-catch
Validate before calling
try {
JavaPsiFacade.getElementFactory(project).createExpressionFromText(filter, context);
} catch (IncorrectOperationException e) {
// filter is not a valid Java expression — reject before slicing
} Try / catch
try { provider.parseFilter(expression, filter); } catch (SliceFilterParseException e) { /* invalid Java expression: report and retry */ } Prevention
- Validate filter text as a Java expression before applying.
- Provide completion/templates for the supported filter forms (null, !null, constant, relational+constant, enum constant).
When it happens
Trigger: Entering a slice filter containing a Java syntax error — unbalanced parentheses, a stray operator, a keyword like 'new' without a body, or a plain word that is neither an enum constant nor a valid expression.
Common situations: Users pasting arbitrary text into the filter field; using string literals without proper quoting; expecting SQL-like or glob syntax where a Java expression is required; partial typing while the field is validated live.
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.constant.type
- slice.filter.parse.error.expression.must.evaluate.to.constant
- slice.filter.parse.error.incorrect.constant.expected.number
AI-assisted analysis of JetBrains/intellij-community@be881553f2 (2026-08-14).
Data as JSON: /api/errors/cefaff25cadb0247.
Report an issue: GitHub.