On Thursday, August 29, 2019 at 4:22:24 AM UTC+2, [email protected] wrote: > > Thanks Marc for the explanation. That's bad news for me, though. > For the constructor, actually I didn't define such a constructor; Jacoco > 'identifies' or 'defines' it... >
Hi, Please see chapter Default Constructor in Java Language Specification (https://docs.oracle.com/javase/specs/jls/se8/html/jls-8.html#jls-8.8.9), which states: "If a class contains no constructor declarations, then a default constructor with no formal parameters and no throws clause is implicitly declared." in other words constructor exists in bytecode after compilation of both following examples public class Example { } public class Example { public Example() { } } > For the static one, it's not even a method. It's only an initializer of a > private member... > Same here - initialization of static fields happens in a static initializer, in other words static initialization method exists in bytecode after compilation of both following examples class Example { static Object o = new Object(); } class Example { static Object o; static { o = new Object(); } } So in both cases JaCoCo does not invent out of thin air something that does not exist - they exist and this is how Java works. On Thursday, August 29, 2019 at 4:22:24 AM UTC+2, [email protected] wrote: > > Thanks Marc for the explanation. That's bad news for me, though. > On Wednesday, August 28, 2019 at 10:55:35 AM UTC+2, [email protected] wrote: > > Such behavior affects the coverage number in the report... > Static initializers are executed when class is loaded. Constructors are executed when class is instantiated. Aren't you load class and instantiate it? So could you please elaborate more why this is such a big problem for you? While for the above reasons not at all a problem for many other people, and also for many others is important to not exclude static fields, because they can contain branches: class Example { static Object o = System.getProperty("flag") == null ? null : new Object(); } Regards, Evgeny > So, is there an approach to prevent jacoco from thinking them as methods, > so that they won't be included in the execution report? > Thanks. > --huafeng > > On Wednesday, August 28, 2019 at 8:02:30 PM UTC+8, Marc R. Hoffmann wrote: >> >> Hi Huafeng, >> >> both are executable code that at least for the static initializer also >> exist in your source code and therefore shown by JaCoCo. >> >> There is no option to exclude specific methods from JaCoCo. >> >> Regards, >> -marc >> >> >> On 28. Aug 2019, at 10:55, [email protected] wrote: >> >> Hi, >> My class looks like >> >> 1 public class XXXController { >> 2 >> 3 private static Logger logger = getLogger(XXX.class); >> ... >> >> I the report jacoco generated, it identifies two methods that don't >> actually exist. >> The first is "XXXController()", located at line 1. This is obviously the >> constructor method, which I didn't define, but Jacoco just treat the class >> as the constructor method. >> The second is "static {...}", located at line 3. >> >> Such behavior affects the coverage number in the report... how can I >> prevent Jacoco to identify such non-existent methods? >> Thanks. >> --huafeng >> >> -- >> You received this message because you are subscribed to the Google Groups >> "JaCoCo and EclEmma Users" group. >> To unsubscribe from this group and stop receiving emails from it, send an >> email to [email protected]. >> To view this discussion on the web visit >> https://groups.google.com/d/msgid/jacoco/09478e63-411a-40a8-84a4-91197e679131%40googlegroups.com >> >> <https://groups.google.com/d/msgid/jacoco/09478e63-411a-40a8-84a4-91197e679131%40googlegroups.com?utm_medium=email&utm_source=footer> >> . >> >> >> -- You received this message because you are subscribed to the Google Groups "JaCoCo and EclEmma Users" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To view this discussion on the web visit https://groups.google.com/d/msgid/jacoco/3373ad68-84ed-4fe9-9fed-202673b1c4e5%40googlegroups.com.
