private static @NotNull DfaMemoryState createMemoryState(DfaValueFactory factory) {
    DfaMemoryState state = new JvmDfaMemoryStateImpl(factory);
    List<DfaVariableValue> vars = StreamEx.of(factory.getValues())
      .select(DfaVariableValue.class)
      .filter(var -> {
        if (!(var.getInherentType() instanceof DfReferenceType) ||
            ((DfReferenceType)var.getInherentType()).getNullability() == DfaNullability.UNKNOWN) {
          return false;
        }
        PsiVariable psi = ObjectUtils.tryCast(var.getPsiVariable(), PsiVariable.class);
        if (psi instanceof PsiPatternVariable) return true;
        if (psi instanceof PsiLocalVariable || psi instanceof PsiParameter) {
          PsiElement block = PsiUtil.getVariableCodeBlock(psi, null);
          return block == null || !HighlightControlFlowUtil.isEffectivelyFinal(psi, block, null);
        }
        return true;
      })
      .toList();
    for (DfaVariableValue var : vars) {
      state.setVarValue(var, factory.fromDfType(((DfReferenceType)var.getInherentType()).dropNullability()));
    }
    return state;
  }
private static @NotNull DfaMemoryState createMemoryState(DfaValueFactory factory)