Cobertura Java7 try with a resource

I am using cobertura 2.6 with maven on java 1.7

            <plugin>
                <groupId>org.codehaus.mojo</groupId>
                <artifactId>cobertura-maven-plugin</artifactId>
                <version>2.6</version>
                <configuration>
                    <formats>
                        <format>html</format>
                        <format>xml</format>
                    </formats>
                </configuration>
            </plugin>

but if I use the new try-with-resource function for java7, it tells me that the tests do not have a "nonexistent catch" block ... it marks the closing bracket of the try-block block

any ideas what's wrong? or how can i test them?

+4
source share
1 answer

The problem is that you probably are not testing all cases for your attempt using the resource block. Every time you write something like:

try(Autocloseable ac = new Autocloseable()) {
   //do something
} catch(Exception e) {
   //Do something with e
}

The compiler interprets something like:

Autocloseable ac = null;
Exception e = null;
try {
   ac = new Autocloseable();
   //Do something
} catch (Exception e1) {
   e = e1
   //Do something with exception
} finally {
  if(ac != null) {
     try {
       ac.close();
     } catch (Exception e2) {
        throw e == null? e2 : e;
     }
     if(e != null ) throw e; 
  }
}

, , , , . , , .

+2

Source: https://habr.com/ru/post/1526531/


All Articles