listener may be NULL.  Fixes #515