Structural search question

Hi all,

I'm trying to find instances of bad usages of logging in our code, for example: log.error(exception). This seems like a good application for structural search, but for the life of me I can't figure it out. I need to do something like:

.error(]]>)

Is this possible? For bonus points, can the same search find calls to debug, info, warn and fatal at the same time? Obviously that's just laziness though :)

As an aside, this seems like a good candidate for an inspection (log parameter calls default toString of exception type?)

Cheers,
Colin

4 comments
Comment actions Permalink

Hi,
$instance$.error($parameter$);

instance variable has expression type constraint of 'org.log4j.Category'
within hierarchy
parameter has expression type constraint of 'java.lang.Exception' within
hierarchy

Colin Fleming wrote:

Hi all,

I'm trying to find instances of bad usages of logging in our code, for example: log.error(exception). This seems like a good application for structural search, but for the life of me I can't figure it out. I need to do something like:

<variable of type extending org.log4j.Category>.error(<variable extending java.lang.Exception>)

Is this possible? For bonus points, can the same search find calls to debug, info, warn and fatal at the same time? Obviously that's just laziness though :)

As an aside, this seems like a good candidate for an inspection (log parameter calls default toString of exception type?)

Cheers,
Colin



--
Best regards,
Maxim Mossienko
IntelliJ Labs / JetBrains Inc.
http://www.intellij.com
"Develop with pleasure!"

0
Comment actions Permalink

That's great, thanks very much, Maxim.

I seem to recall seeing a plan a while ago to allow user-defined inspections using the structural search - did anything ever come of that?

Cheers,
Colin

0
Comment actions Permalink

Take a look at the "Structural Search Inspection"

0
Comment actions Permalink

I love being amazed from time to time :)

Cheers,
Colin

0

Please sign in to leave a comment.