Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[java] InvalidLogMessageFormat may examine the value of a different but identically named String variable #3284

Closed
krallus opened this issue May 19, 2021 · 0 comments · Fixed by #3285
Assignees
Labels
a:false-positive PMD flags a piece of code that is not problematic
Milestone

Comments

@krallus
Copy link

krallus commented May 19, 2021

Affects PMD Version: 6.33.0 (via Eclipse PMD For Eclipse 4.22.0)

Rule: InvalidLogMessageFormat

Description:

InvalidLogMessageFormat does not respect the scope in which a String format variable is declared and may use the value of an identically named variable that has been declared in a different scope.

Code Sample demonstrating the issue:

	public void aTest() {
		if (true) {
			final String logMessage = "A message formatted with three parameters: {}, {}, {}";
		}

		if (true) {
			final String logMessage = "A message formatted with only one parameter: {}";
			final Object param = null;
			logger.trace(logMessage, param);
		}
	}

Expected outcome:

PMD reports a violation at line 8, but that's wrong. That's a false positive.

Specifically, the error is reported as:
InvalidLogMessageFormat: Missing arguments, expected 3 arguments but have 1

Running PMD through: Eclipse

@krallus krallus added the a:false-positive PMD flags a piece of code that is not problematic label May 19, 2021
@adangel adangel self-assigned this May 20, 2021
@adangel adangel added this to the 6.36.0 milestone May 20, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
a:false-positive PMD flags a piece of code that is not problematic
Projects
None yet
2 participants