mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
[uast-inspections] IDEA-324304 "String template as argument to logging call" where the argument is an exception
GitOrigin-RevId: fdba04156f50430ce2b78bdc2dce82a8ccb09a53
This commit is contained in:
committed by
intellij-monorepo-bot
parent
ab14666e4e
commit
dea129dd78
+12
@@ -15,6 +15,7 @@ import com.intellij.openapi.project.Project
|
||||
import com.intellij.psi.CommonClassNames
|
||||
import com.intellij.psi.PsiElementVisitor
|
||||
import com.intellij.psi.PsiType
|
||||
import com.intellij.psi.util.InheritanceUtil
|
||||
import com.intellij.psi.util.TypeConversionUtil
|
||||
import com.intellij.uast.UastHintedVisitorAdapter
|
||||
import org.jetbrains.uast.*
|
||||
@@ -106,6 +107,17 @@ class LoggingStringTemplateAsArgumentInspection : AbstractBaseUastLocalInspectio
|
||||
return true
|
||||
}
|
||||
|
||||
//strange behavior for last parameter as exception. let's ignore this case
|
||||
val injected = parts.filter { it !is ULiteralExpression }
|
||||
val javaLangThrowable = CommonClassNames.JAVA_LANG_THROWABLE
|
||||
if ((injected.size == 1 &&
|
||||
InheritanceUtil.isInheritor(injected[0].getExpressionType(), javaLangThrowable)) ||
|
||||
((valueArguments.size - 1 - indexStringExpression) == 1 &&
|
||||
InheritanceUtil.isInheritor(valueArguments[valueArguments.size - 1].getExpressionType(), javaLangThrowable))
|
||||
) {
|
||||
return true
|
||||
}
|
||||
|
||||
if (mySkipPrimitives && allExpressionsInPatternArePrimitivesOrWrappers(parts)) {
|
||||
return true
|
||||
}
|
||||
|
||||
+9
-1
@@ -20,6 +20,14 @@ class StringTemplateAsArgument {
|
||||
loggerLog4J.atInfo().<warning descr="String template as argument to 'log()' logging call">log</warning>( "variable1: ${variable1}")
|
||||
}
|
||||
|
||||
|
||||
fun testException(){
|
||||
var exception = RuntimeException()
|
||||
loggerLog4J.info("exception: $exception")
|
||||
val variable1 = 1
|
||||
loggerLog4J.info("variable1: $variable1", exception)
|
||||
}
|
||||
|
||||
fun testLoggerSlf4J() {
|
||||
val variable1 = 1
|
||||
loggerSlf4J.info("variable1: {}", variable1)
|
||||
@@ -28,7 +36,7 @@ class StringTemplateAsArgument {
|
||||
loggerSlf4J.<warning descr="String template as argument to 'info()' logging call">info</warning>("${getInt()}")
|
||||
loggerSlf4J.<warning descr="String template as argument to 'info()' logging call">info</warning>("variable1: ${variable1}")
|
||||
loggerSlf4J.<warning descr="String template as argument to 'info()' logging call">info</warning>("variable1: $variable1")
|
||||
loggerSlf4J.<warning descr="String template as argument to 'info()' logging call">info</warning>("variable1: $variable1", RuntimeException())
|
||||
loggerSlf4J.info("variable1: $variable1", RuntimeException())
|
||||
loggerSlf4J.<warning descr="String template as argument to 'info()' logging call">info</warning>("{} variable1: $variable1", 1, RuntimeException())
|
||||
loggerSlf4J.<warning descr="String template as argument to 'info()' logging call">info</warning>("{} variable1: $variable1 {}", 1, 2, RuntimeException())
|
||||
loggerSlf4J.<warning descr="String template as argument to 'info()' logging call">info</warning>("{} variable1: $variable1 {} {}", 1, 2, RuntimeException())
|
||||
|
||||
+1
-1
@@ -13,7 +13,7 @@ class StringTemplateAsArgumentFix {
|
||||
loggerSlf4J.info("variable1: {}", variable1)
|
||||
loggerSlf4J.info("variable1: {}", variable1)
|
||||
loggerSlf4J.info("variable1: {}", variable1)
|
||||
loggerSlf4J.info("variable1: {}", variable1, RuntimeException())
|
||||
loggerSlf4J.info("variable1: $variable1", RuntimeException())
|
||||
loggerSlf4J.info("{} variable1: {}", 1, variable1)
|
||||
loggerSlf4J.info("{} variable1: {} {} variable1: {}", 1, variable1, 2, variable1)
|
||||
loggerSlf4J.info("{} variable1: {} {} variable1: {} {}", 1, variable1, 2, variable1, 3)
|
||||
|
||||
Reference in New Issue
Block a user