Menu

"Prefer StringBuffer over += for concatenating strings" - when using string reassignment with Ternary operator

Help
Atul
2015-04-20
2015-05-01
  • Atul

    Atul - 2015-04-20

    Hi All,

    could someone please explain me the below behavior of PMD plugin, when trying to perform String Reassignment using ternary operators.

    Please find the below sample code, which is throwing this exception.

    country = (country == null || "".equals(country))
        ? ((String) getCountry())
        : country;
    

    i am not sure, why PMD is treating the same as String Concatination instead of usual reassignment.

    Thanks,

     

    Last edit: Andreas Dangel 2015-04-20
  • Andreas Dangel

    Andreas Dangel - 2015-04-20

    This looks like a bug. I've created an issue [#1340] for this. Thanks!

     

    Related

    Issues: #1340

  • Andreas Dangel

    Andreas Dangel - 2015-05-01

    I can't reproduce this with PMD 5.3.1 - which version of PMD were you using?

     

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.