Well, its really a nice question..
The reason for this behaviour is the implementation of TreeMap. while trying to remove an object out of Treemap, you are calling map.remove(key) method. Please see the implementation of remove method for Treemap,
So, if you dont have any object in your map, then its size will be 0, and obviously it will return null only with out allowing further processing.