Unnecessary code in StrTokenizer
--------------------------------

                 Key: LANG-301
                 URL: http://issues.apache.org/jira/browse/LANG-301
             Project: Commons Lang
          Issue Type: Bug
    Affects Versions: 2.2
            Reporter: Henri Yandell
             Fix For: 2.3


In StrTokenizer, we have the following:

1086     public Object clone() {
1087         try {
1088             return cloneReset();
1089         } catch (CloneNotSupportedException ex) {
1090             return null;
1091         }
1092     }
...
1101     Object cloneReset() throws CloneNotSupportedException {
1102         StrTokenizer cloned = (StrTokenizer) super.clone();
1103         if (cloned.chars != null) {
1104             cloned.chars = (char[]) cloned.chars.clone();
1105         }
1106         cloned.reset();
1107         return cloned;
1108     }

FindBugs just reported it because the clone() method doesn't call 
super.clone(). While that's not a worry (because the method it calls does), I 
don't understand why we're not just doing:

    public Object clone() {
         StrTokenizer cloned = (StrTokenizer) super.clone();
         if (cloned.chars != null) {
             cloned.chars = (char[]) cloned.chars.clone();
         }
         cloned.reset();
         return cloned;
    }

and why we return null and not a runtime CloneNotSupportedException.

Also, is there any value in StrTokenizer being Cloneable? Or is it just done 
for the sake of the getXxxInstance methods?

-- 
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators: 
http://issues.apache.org/jira/secure/Administrators.jspa
-
For more information on JIRA, see: http://www.atlassian.com/software/jira

        

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to