FP: java:S7467 (replace e with an unnamed pattern)

  • ALM used: GitHub

  • CI system used: Jenkins

  • Scanner command used when applicable (private details masked)

    mvn -Duser.home=masked org.sonarsource.scanner.maven:sonar-maven-plugin:5.6.0.6792:sonar --batch-mode -pl masked --also-make --no-snapshot-updates -Psonar -Dsonar -Dsonar.projectName=masked -Dsonar.projectKey=masked -Dsonar.organization=masked -Dsonar.host.url=https://sonarcloud.io -Dsonar.token=masked -Dsonar.branch.name=masked -Dmaven.repo.local=masked/.m2/repository -f masked/Parent/pom.xml

  • Languages of the repository: Java,JS,TS

import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.TimeUnit;
import lombok.Getter;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;

public class SonarFP {
	private final Logger log = LogManager.getLogger();
	private final Config config;

	@Getter
	public static class Config {
		private final long intervalMs = 1000;
	}

	SonarFP(Config config) {
		this.config = config;
	}

	void start() {
		ScheduledExecutorService executor = Executors.newSingleThreadScheduledExecutor();
		executor.scheduleAtFixedRate(
			() -> {
				try {
					Integer.parseInt("1.2");
				} catch (Exception e) { // FP: java:S7467 (Replace "e" with an unnamed pattern.)
					log.error("SonarQube Cloud reports 'e' should be replaced by _ while it's used", e);
				}
			},
			0,
			config.getIntervalMs(),
			TimeUnit.MILLISECONDS
		);
	}
}

The code above reports that e should be replaced by an unnamed pattern while it’s used in the next line. JDK25 is in use.

Additional observations:

  1. SonarQube for Eclipse doesn’t show this issue (just SonarQube Cloud)

  2. If we remove Lombok @Getterand replaced it by plain getter Config.getIntervalMs the FP disappears

Thank you for the report! I’ve filed SONARJAVA-6455 to track resolution of this issue.