HDFS-14547 saves the NameNode heap space occupied by EnumCounters by essentially implementing a copy-on-write strategy.
At beginning, all EnumCounters refers to the same ConstEnumCounters to save heap space. When it is modified, an exception is thrown and the exception handler converts ConstEnumCounters to EnumCounters object and updates it.
Using exception handler to perform anything more than occasional is bad for performance.
Propose: use instanceof keyword to detect the type of object and do COW accordingly.