Search code examples
sonarqubeillegalargumentexceptionthreadgroup

Sonar ThreadGroup error on IllegalArgumentException


Sonar shows "ThreadGroup" error on the line where IllegalArgumentException is thrown. Why is the issue here? enter image description here

Here is the code snippet, where issue is found by Sonar:

public static ResolutionElection fromValue(String value) {
    for (ResolutionElection election : ResolutionElection.values()) {
        if (election.getValue().equals(value)) {
            return election;
        }
    }
    throw new java.lang.IllegalArgumentException();
}

Sonar error description:

Avoid Thread Group
Avoid using ThreadGroup; although it is intended to be used in a threaded environment it contains methods that are not thread safe.


Solution

  • This is a known issue relating to underlying analyzer PMD : http://jira.codehaus.org/browse/SONARPMD-5

    As per this bug report, this bug should be fix if you use latest version of sonar-pmd plugin (2.2 as of writing) which relies on PMD 5.1.1