#210 Multiple identical string literals

release_3.5
closed
Rick Giles
Check (274)
5
2012-10-10
2003-06-12
Tim Tyler
No

A check for multiple identical string literals is a
special case of the check for duplicated code.

It's main advantages are that it identifies a fairly
common problem - and can be implemented relatively
easily - and executed quickly (compared to other
checks for replicated code).

There should be a configurable length limit - below
which the problem is not reported - defaulting to
two characters.

The implementation should ideally report the problem
on /every/ line involved (including the first one) -
though I'm not sure how easy this is to do in
Checkstyle.

Similar checks for other multiple identical literals
could also be done relatively inexpensively -
int, long, float, double - but they might be a
bit less useful.

Discussion

  • Dale King
    Dale King
    2003-06-13

    Logged In: YES
    user_id=130378

    Might be nice to have an option to exclude strings in array
    initialization. I could see how you might not care about
    duplicated strings there.

     
  • Tim Tyler
    Tim Tyler
    2003-06-13

    Logged In: YES
    user_id=796025

    I've written this check:

        <module name="MultipleStringLiterals">
            <property name="shortestAllowedLength"
    

    value="1"/>
    </module>

    Dale's suggestion is on the ToDo list - I'm not sure how
    to implement it at the moment.

     
  • Rick Giles
    Rick Giles
    2004-05-31

    Logged In: YES
    user_id=539926

    An implementation of this without property
    shortestAllowedLength is now committed to the 3.5 CVS (from
    patch 929882). Closing this for now. If you need
    shortestAllowedLength property, or a property to control the
    check for array initialization, please submit a new RFE or,
    even better, a patch.