In classic squid tradition: 20% code, and 80% test logic.
Closes#962. Alas, whoever reported this has deleted their account, so
they can't even be happy about it :(.
See comments in c8c128d335385d5afd6857dc25cc090672cc8563 for further
details. This requires /relatively/ few changes - mostly cases we were
missing @Nullable annotations.