IDEA-72636 ("Log statement not guarded by log condition" inspection fails on custom logging methods with method signatures different from log.debug(String))

This commit is contained in:
Bas Leijdekkers
2013-03-08 12:49:40 +01:00
parent d75f9e6b25
commit 38226e6ab4
3 changed files with 25 additions and 4 deletions
@@ -1,5 +1,5 @@
/*
* Copyright 2008-2012 Bas Leijdekkers
* Copyright 2008-2013 Bas Leijdekkers
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -221,9 +221,17 @@ public class LogStatementGuardedByLogConditionInspection extends BaseInspection
if (arguments.length == 0) {
return;
}
final PsiExpression firstArgument = arguments[0];
if (!flagAllUnguarded && PsiUtil.isConstantExpression(firstArgument)) {
return;
if (!flagAllUnguarded) {
boolean constant = true;
for (PsiExpression argument : arguments) {
if (!PsiUtil.isConstantExpression(argument)) {
constant = false;
break;
}
}
if (constant) {
return;
}
}
registerMethodCallError(expression);
}
@@ -32,6 +32,10 @@ public class LogStatementGuardedByLogCondition {
}
}
void alternativeDebugMethodSignature(int i) {
LOG.debug(i, "asdfasdf");
}
static class Logger {
public Logger(String log) {
@@ -40,6 +44,8 @@ public class LogStatementGuardedByLogCondition {
public void debug(String s) {
}
public void debug(int i, String s) {}
public void trace(String s) {}
public boolean isDebug() {
@@ -14,4 +14,11 @@
<problem_class severity="WARNING" attribute_key="WARNING_ATTRIBUTES">Log statement not guarded by log condition</problem_class>
<description>&lt;code&gt;debug()&lt;/code&gt; log statement not guarded by log condition #loc</description>
</problem>
<problem>
<file>LogStatementGuardedByLogCondition.java</file>
<line>36</line>
<problem_class severity="WARNING" attribute_key="WARNING_ATTRIBUTES">Log statement not guarded by log condition</problem_class>
<description>&lt;code&gt;debug()&lt;/code&gt; log statement not guarded by log condition #loc</description>
</problem>
</problems>