#210 Multiple identical string literals

Check (274)
Tim Tyler

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

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.


  • Dale King

    Dale King - 2003-06-13

    Logged In: YES

    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

    I've written this check:

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


    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

    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.


Log in to post a comment.

Get latest updates about Open Source Projects, Conferences and News.

Sign up for the SourceForge newsletter:

No, thanks