A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://github.com/pmd/pmd/issues/2625 below:

[java] NPathComplexity can't handle switch expressions · Issue #2625 · pmd/pmd · GitHub

Affects PMD Version:
6.25

Rule
NPathComplexity

Description:
When replacing java switch statements with the new switch expressions, NPathComplexity calculation goes through the roof. The following (obfuscated) code sample gives us an NPath complexity of 2147483645. Before the change to switch expressions, it was well below our threshold of 200.

Code Sample demonstrating the issue:

public class NPathTest {
    Product buildProduct(String title, Language language) {
        if (title.length() > 100 || title.length() == 0) {
            throw new IllegalArgumentException("Invalid title length (1-100 chars): " + title);
        }
        val product = new Product();
        val description = new MultiLangString();
        switch (language) {
            case FR -> description.setFr(title);
            case IT -> description.setIt(title);
            case EN -> description.setEn(title);
            default -> description.setDe(title);
        }
        product.setDescription(description);
        product.setMagicNumber(3);
        return product;
    }
}

Running PMD through: [CLI]
JDK: OpenJDK 14


RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4