Fix NPE with null context

We should not try to register @EventHandler methods if the passed-in
context is null. This usually does not come up, but is a problem for
Objects reconstructed externally via ObjectInputStream, as done in e.g.
TestBinaryMaskOverlay.

In the future we will likely need to be more careful about persistence
of such objects; Java serialization is always a dangerous approach,
especially with the need for the context to be non-null and consistent.