"Method '...' is too complex to analyze by data flow algorithm" Follow
Hi,
I just noticed this warning, signaled by a wavy grey underscore on the name of the method in question. The extended description reads:
"This inspection reports those conditions in the specified inspection scope that are always true or false, as well as points out where a RuntimeException may be thrown, based on data flow analysis of the code."
The method in question is not particularly complex:
<![CDATA[ public void format(PrintStream stream, String format) { int nFmtChars = format.length(); boolean percent = false; boolean backslash = false; for (int iFmtChar = 0; iFmtChar < nFmtChars; iFmtChar++) { char fmtChar = format.charAt(iFmtChar); if (backslash) { stream.print(fmtChar); backslash = false; } else if (percent) { switch (fmtChar) { case '%': stream.print('%'); break; case 's': stream.print(fSeverity.leftName); break; case 'M': stream.print(fMajor != null ? fMajor : "?"); break; case 'm': stream.print(fMinor != null ? fMinor : "?"); break; case 'v': stream.print(fVariant != null ? fVariant : "?"); break; case 'f': printMessage(stream); break; case 't': printThrownMessage(stream); break; case 'S': printStackTrace(stream); break; case 'n': stream.println(); } percent = false; } else if (fmtChar == '\\') backslash = true; else if (fmtChar == '%') percent = true; else stream.print(fmtChar); } ]]>
So what's the deal with this? Which inspection is creating it? What's too complex about that code?
I'm running EA 7312 under 1.6.0_02 on Linux.
Randal Schulz
Please sign in to leave a comment.
Hello Randall,
As you can see from the description, the "Constant Conditions and Exceptions"
inspection is creating it. Note that the only thing new for this is the warning
itself: previously such methods were silently ignored, and you got no null
pointer highlighting etc. in such methods.
I don't know the exact rules for detecting too complex methods - Max Shafirov
will probably answer this part.
--
Dmitry Jemerov
Software Developer
JetBrains, Inc.
http://www.jetbrains.com/
"Develop with Pleasure!"
Yeah I noticed this as well for a few of my methods. Seems like a few nesting levels (sometimes unavoidable) may be triggering it.
Eh? How can I see that? That name is not present in the description.
OK. The code isn't too new, but the hilight is subtle enough that thought I might have missed it before. There is a regular yellow warning marker in the right gutter, though.
Randall Schulz
Is there any way to disable the "too complex" portion of the inspection but still keep the inspection enabled for not-too complex methods?
Hello k,
No, the highlighting of code which is too complex to analyze can't be separately
disabled.
--
Dmitry Jemerov
Software Developer
JetBrains, Inc.
http://www.jetbrains.com/
"Develop with Pleasure!"
i'm still trying to figure this out...
a) is the "too complex" supposed to be a warning that the code actually is too complex and should be refactored?
or
b) is the "too complex" just information that the analyzer is not up to task to analyze the particular method?
if the answer is (a) then there are some pretty simple methods it can't analyze. if the answer is (b) then why is this highlighting as yellow warning instead of just info
I try to keep my files "green" but this particular inspection has turned many of them yellow. I want to keep the inspection on but if a method is too complex for it I don't want my entire file marked yellow because of it.
Hello k,
The answer is (b), and the "too complex" highlighting is shown with INFO
severity.
--
Dmitry Jemerov
Software Developer
JetBrains, Inc.
http://www.jetbrains.com/
"Develop with Pleasure!"
If I'm looking at the correct inspection, "Constant conditions & exceptions" in the "Probable bugs" section, then this is a "warning" / yellow by default, but that can be changed to any defined severity level, including one of the user's own definition.
Randall Schulz