JetBrains/intellij-community · error · SliceFilterParseException

slice.filter.parse.error.not.null.filter.not.applicable.for.primitive.type

slice.filter.parse.error.not.null.filter.not.applicable.for.primitive.type

Error message

'!null' filter is not applicable to primitive type {0}

What it means

Thrown by JavaSliceProvider.parseFilter when the user types a '!null' filter in the Java Slice (dataflow) tool window for a value whose static type is a primitive (int, boolean, etc.). Primitives can never be null in Java, so a NOT_NULL dataflow value filter is meaningless and the parser rejects it with SliceFilterParseException. The message interpolates the presentable text of the primitive type.

Source

Thrown at java/java-impl/src/com/intellij/slicer/JavaSliceProvider.java:129

    return type != null && !PsiTypes.voidType().equals(type) && !PsiTypes.nullType().equals(type);
  }

  @Override
  public @NotNull SliceValueFilter parseFilter(@NotNull PsiElement expression, @NotNull String filter) throws SliceFilterParseException {
    PsiType type = getType(expression);
    if (type == null) {
      return SliceLanguageSupportProvider.super.parseFilter(expression, filter);
    }
    if (filter.equals("null")) {
      if (type instanceof PsiPrimitiveType) {
        throw new SliceFilterParseException(
          JavaBundle.message("slice.filter.parse.error.null.filter.not.applicable.for.primitive.type", type.getPresentableText()));
      }
      return new JavaValueFilter(DfTypes.NULL);
    }
    if (filter.equals("!null")) {
      if (type instanceof PsiPrimitiveType) {
        throw new SliceFilterParseException(
          JavaBundle.message("slice.filter.parse.error.not.null.filter.not.applicable.for.primitive.type", type.getPresentableText()));
      }
      return new JavaValueFilter(DfTypes.NOT_NULL_OBJECT);
    }
    RelationType relationType = RelationType.EQ;
    if (PsiTypes.byteType().equals(type) ||
        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;
        }
      }
    }

View on GitHub (pinned to be881553f2)

Solutions

  1. Remove the '!null' filter when slicing a value of primitive type — primitives are never null by language rules.
  2. If you expected a reference type, check that you are slicing the right expression (e.g. the boxed Integer, not the unboxed int).
  3. Use a value filter appropriate to primitives, such as a relational filter (e.g. '>=5') or a plain constant like '5'.
  4. If you are a plugin author calling this API programmatically, guard with 'type instanceof PsiPrimitiveType' before requesting '!null'.

Example fix

// before (Slice filter on int x):
filter = "!null"

// after:
filter = ">=0"   // relational constant filter valid for int
Defensive patterns

Strategy: validation

Validate before calling

PsiType type = JavaSliceProvider.getType(expression); // or resolve the sliced value's type yourself
boolean primitive = type instanceof PsiPrimitiveType;
// only offer '!null' filter when !primitive

Try / catch

try { provider.parseFilter(expression, filter); } catch (SliceFilterParseException e) { /* show e.getMessage() in the filter UI */ }

Prevention

When it happens

Trigger: Opening the Slice tool window on a variable/parameter of primitive type (e.g. int x) and entering '!null' in the filter field; parseFilter resolves the type via getType(), sees type instanceof PsiPrimitiveType for the '!null' branch, and throws.

Common situations: Users exploring data flow for an int/long/boolean value and reflexively applying the same '!null' filter they use for reference types; plugin code calling SliceLanguageSupportProvider.parseFilter or JavaSliceProvider directly with a hardcoded '!null' filter; analyzing auto-unboxed values where the declared type is still primitive.

Related errors


AI-assisted analysis of JetBrains/intellij-community@be881553f2 (2026-08-14). Data as JSON: /api/errors/ca9ff12885ba234d. Report an issue: GitHub.