Menu

#48 Curly bracket counted as line with no coverage

open
nobody
None
5
2014-10-05
2006-04-21
Anonymous
No

From paul{XdotX}field{YatY}db{ZdotZ}com

Using Cobertura v1.8. Here's my method:

public <K,V> NullCache<K,V> getCache(String cacheName) {
assert cacheName != null;

synchronized (caches) {
NullCache<K, V> result = caches.get(cacheName);
if (result == null) {
result = new NullCache<K, V>(cacheName);
caches.put(cacheName, result);
}
return result;
} // THIS LINE GETS A COUNT OF '0'
}

I call this method in my unit tests and all the lines
get a non-zero cound except for the closing brace of
the 'synchronized' (see the comment above).

Discussion

  • Nobody/Anonymous

    This also happens for me as well. Here is my method (note that a mock security manager is used to generate the security exception):

    try {
    System.exit(0);
    } catch (final SecurityException exception) {
    exception.printStackTrace();
    } // This curly brace shows as never being covered, although the next line shows as covered.
    System.err.println("The program never exited!");

     
  • MunchGut

    MunchGut - 2008-12-09

    Also a problem for us as well. This is happening when instrumenting jars, merging ser files and then generating reports using the shell scripts.

     
  • Anonymous

    Anonymous - 2011-08-11

    Another case is a synchronized block - the closing brace is marked as untested. Example:

    public boolean foo(int number) {
    synchronized (this.monitor) {
    if(number>0) return true;
    return false;
    }
    }

     

Log in to post a comment.