Add another test and fix a Java 7-related bug.

The code was sometimes adding a null key to a TreeMap which works in Java 6 but not any more in Java 7.