The specification for the copyOf
method states
Returns an unmodifiable Map containing the entries of the given Map.
(emphasis mine)
Which means only the entries get copied, nothing else. Hence, it is expected behavior, not a bug.
On the other hand, as suggested in the comments, the documentation for the constructor of the TreeMap
class says
Constructs a new tree map containing the same mappings and using the same ordering as the specified sorted map. This method runs in linear time.
Parameters:
m
- the sorted map whose mappings are to be placed in this map, and whose comparator is to be used to sort this map
(again, emphasis mine)