f can be null.