commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Henri Yandell (JIRA)" <j...@apache.org>
Subject [jira] Updated: (LANG-301) Unnecessary code in StrTokenizer
Date Tue, 26 Dec 2006 21:28:22 GMT
     [ http://issues.apache.org/jira/browse/LANG-301?page=all ]

Henri Yandell updated LANG-301:
-------------------------------

    Fix Version/s: 3.0
                       (was: 2.3)

Moving this back to 3.0. 

There are three things to do here, if reasons for the current code don't show up:

1) Refactor the cloneReset method away. It's possible that it's setup this way to be more
useful for subclasses. 
2) Switch from returning null to throwing CloneNotSupported.
3) Stop supporting clone() and Cloneable.

The latter 2 definitely need to wait for 3.0, the former is not very critical.

> 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: 3.0
>
>
> 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: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org


Mime
View raw message