jborgers / PMD-jPinpoint-rules

PMD rule set for responsible Java and Kotlin coding: performance, sustainability, multi-threading, data mixup and more.
Apache License 2.0
43 stars 10 forks source link

Fix Request: pmd7 AvoidConcatInLoop false positive #383

Closed jborgers closed 3 days ago

jborgers commented 3 days ago

false positives in:

 private static List<String> addTagToDescriptionAndDoc(List<String> mergedFileLines, String taggedDescriptionEndTag) {

        List<String> fileLinesWithReplaced = new ArrayList<>(mergedFileLines.size());
        for(String line : mergedFileLines) {
            Matcher matcher = TAGGED_DESCRIPTION_END_TAG_PATTERN.matcher(line);
            if (!matcher.find()) {
                // not yet tag so add our tag
                line = line.replace(DESCRIPTION_END_TAG, taggedDescriptionEndTag); // <-----false positive
            }

            line = line.replace("${doc_root}", COMPANY_DOC_ROOT); // <-----false positive
            fileLinesWithReplaced.add(line);
        }
        return fileLinesWithReplaced;
    }

//minimal test version:

   public void goodX() {
        String logStatement = "ticAtacBtoe";
        List<String> values = Arrays.asList("tic", "tac", "toe");
        for (String val : values) {
            logStatement = logStatement.replace(val, "-"); // <-----false positive
        }
    }
jborgers commented 3 days ago

also, ForStatement is not supported, missed case:

  public void badX() {
       String logStatement = "";
        for (int i = 0; i < 3; i++) {
            logStatement += i + ", "; // bad
        }
    }