Menu

#226 Check for SimpleDateFormat as singleton?

closed
nobody
None
5
2012-10-07
2004-09-01
No

Not sure how if this should be done. But since
SimpleDateFormat should not be reused by other
threads as it is not thread safe, we should check for

(public,private,protected) static final? AnyType foo =
new SimpleDateFormat(...)

I don't recommend spreading this to all formatters,
though it says that it does not guarantee thread safety
on formatters some are threadsafe such as
FastDateFormat from commons-lang.

Discussion

  • Tom Copeland

    Tom Copeland - 2004-09-02

    Logged In: YES
    user_id=5159

    Hm, something like this would probably work:

    //FieldDeclaration[@Static='true']//AllocationExpression/Name[@Image='SimpleDateFormat']

    The problem is that it's hard to tell what's going on in the
    code around it - I mean, if the accessors are synchronized,
    it may well be OK.

    Yours,

    Tom

     
  • Allan Caplan

    Allan Caplan - 2006-02-07

    Logged In: YES
    user_id=1127445

    Tom

    I had this as a rule on my wishlist, it's a common problem I
    see (unsynchronized static formatters)

    The rule I have for this is on the bug I just entered - but
    basically, it's checking every time you touch the formatter
    that it is in a synchronized manner.

    Sound good?

     
  • Allan Caplan

    Allan Caplan - 2006-10-16

    Logged In: YES
    user_id=1127445

    This has been implemented since PMD 3.6 - see rule
    UnsynchronizedStaticDateFormatter

     

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.