JetBrains/intellij-community · error · SliceFilterParseException
slice.filter.parse.error.enum.constant.not.found
slice.filter.parse.error.enum.constant.not.found
Error message
Enum constant not found: {0} What it means
Thrown by JavaSliceProvider.parseFilter when the value being sliced has an enum class type and the filter text does not name an existing constant of that enum. The parser resolves the enum class with PsiUtil.resolveClassInClassTypeOnly, calls findFieldByName(filter, false), and if the field is not a PsiEnumConstant it throws SliceFilterParseException with the offending filter text.
Source
Thrown at java/java-impl/src/com/intellij/slicer/JavaSliceProvider.java:154
PsiTypes.charType().equals(type) ||
PsiTypes.shortType().equals(type) ||
PsiTypes.intType().equals(type) ||
PsiTypes.longType().equals(type)) {
for (RelationType relType : RelationType.values()) {
if (filter.startsWith(relType.toString())) {
relationType = relType;
filter = filter.substring(relType.toString().length()).trim();
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) {View on GitHub (pinned to be881553f2)
Solutions
- Type the exact simple name of an existing enum constant, matching case (e.g. 'MONDAY', not 'monday').
- Check the enum declaration (Ctrl+B on the variable's type) to confirm the constant list and spelling.
- Do not prefix the constant with the enum or package name — only the bare constant name is accepted.
- If the constant was recently renamed, re-enter the filter with the new name.
Example fix
// before (enum Day { MONDAY, ... }):
filter = "Day.MONDAY"
// after:
filter = "MONDAY" Defensive patterns
Strategy: validation
Validate before calling
PsiClass c = PsiUtil.resolveClassInClassTypeOnly(type);
if (c != null && c.isEnum() && !(c.findFieldByName(filter, false) instanceof PsiEnumConstant)) {
// filter does not name a constant: offer completion from c.getFields() of type PsiEnumConstant
} Try / catch
try { provider.parseFilter(expression, filter); } catch (SliceFilterParseException e) { /* surface message, keep filter editor open */ } Prevention
- Offer enum-constant completion from the sliced variable's enum type instead of free-text entry.
- Use the exact constant name; no enum-name prefix, no qualification, case-sensitive.
When it happens
Trigger: Slicing a variable of enum type (e.g. Day day) and typing a filter that is not one of its constants (typo, casing mismatch, or a fully qualified name like 'java.time.Day.MONDAY' which findFieldByName does not match).
Common situations: Typos or wrong case in constant names ('monday' vs 'MONDAY'); renaming an enum constant so a previously saved/remembered filter no longer resolves; pasting a qualified constant name where only the simple constant name is expected; enum defined with the constant inherited or hidden by a field of the same name.
Related errors
- slice.filter.parse.error.not.null.filter.not.applicable.for.primitive.type
- slice.filter.parse.error.incorrect.expression
- 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/9b73c0824c7a19fc.
Report an issue: GitHub.