method is too complex to analyze by data flow algorithm

Hi all,

Could a JetBrainer explain what sort of code constructs triggers this warning? I have a method which is about a screenful of code, with a few nested for loops, if blocks and try/catch blocks. The nesting never goes more than 4 levels deep. It doesn't look like a particularly complicated method to me.

Thanks,
Gordon

7 comments
Comment actions Permalink

To partially answer my own question, it appears it doesn't like the try/catch block encompassing most of the code in the method. If I move all the code in the try/catch block out, remove the now empty try/catch block and add the exceptions to the method declaration, it no longer gives this warning. Why?

0
Comment actions Permalink

Can you, perhaps, post the source code? In any case, the fact that you are getting such warning is a good indication that your method needs re-factoring.

0
Comment actions Permalink

Gordon Tyler wrote:

To partially answer my own question, it appears it doesn't like the try/catch block encompassing most of the code in the method. If I move all the code in the try/catch block out, remove the now empty try/catch block and add the exceptions to the method declaration, it no longer gives this warning. Why?

I find that this message appears specifically when I have a try-catch
within a loop.  I can often get rid of the message by "introduce method"
around the content said the loop.

It does beg the question though, what benefit are we missing out on by
circumventing the "data flow algorithm"?

0
Comment actions Permalink

That's not circumventing it. You're refactoring the code into a form that that algorithm can analyze.

I'd still like to know why the original form can't be analyzed.

0
Comment actions Permalink

Here's a different method which is even simpler in my opinion but triggers the same warning:



protected synchronized void postLoadAllPlugins(Map loadFailures) {
    Iterator it = mLoadedPlugins.iterator();
    while (it.hasNext()) {
        Plugin plugin = (Plugin)it.next();
        try {
            postLoadPlugin(plugin);
        }
        catch (Throwable e) {
            // Remove the plugin from the list of loaded plugins
            it.remove();


            String name = plugin.getClass().getName();
            CAT.log("exceptionPostLoadingPlugin", name, e);
            loadFailures.put(name, e);


            // Try unloading the plugin, since it is already loaded
            try {
                unloadPlugin(plugin);
            }
            catch (Throwable e2) {
                CAT.log("exceptionWhileUnloadingPlugin", name, e2);
            }
        }
    }
}

0
Comment actions Permalink

Or even simpler:

public synchronized final void unloadPlugins() throws LoadFailedException {
    Map loadFailures = new HashMap();
    for (int i = 0; i < mLoadedPlugins.size(); ++i) {
        Plugin plugin = (Plugin)mLoadedPlugins.get(i);
        try {
            unloadPlugin(plugin);
        }
        catch (Exception e) {
            String className = plugin.getClass().getName();
            CAT.log("exceptionWhileUnloadingPlugin", className, e);
            loadFailures.put(className, e);
        }
    }


    mLoadedPlugins.clear();


    if (!loadFailures.isEmpty()) {
        throw new LoadFailedException(loadFailures);
    }
}

0
Comment actions Permalink

Guest wrote:

... this message appears specifically when I have a try-catch
within a loop.

...

I have the same issue. It is annoying.

0

Please sign in to leave a comment.