Hi, First of all quoting JaCoCo FAQ item "My code uses reflection. Why does it fail when I execute it with JaCoCo?" ( see http://www.jacoco.org/jacoco/trunk/doc/faq.html ) : To collect execution data JaCoCo instruments the classes under test which adds two members to the classes: A private static field $jacocoData and a private static method $jacocoInit(). Both members are marked as synthetic. *Please change your code to ignore synthetic members.* This is a good practice anyways as also the Java compiler creates synthetic members in certain situation.
And answering your question about exclusions: there is known inconsistency between exclusion patterns for instrumentation and report generation ( see https://github.com/jacoco/jacoco/issues/34 ): first one accepts Java or VM class name, while second one accepts file name. So if you want to exclude class from instrumentation - specify it as " **/BlockBuilderStatus" for "instrument" goal. Or as a workaround - you can specify "**/BlockBuilderStatus*", which will also work for "report" goal. On Tuesday, January 3, 2017 at 3:34:02 AM UTC+1, [email protected] wrote: > > hi, > > I want to skip instrument a class named BlockBuilderStatus.class ,but > it didn't work , here is my configuration ,is there anything wrong? > > <plugin> > <groupId>org.jacoco</groupId> > <artifactId>jacoco-maven-plugin</artifactId> > <version>0.7.7.201606060606</version> > <executions> > <execution> > <id>jacoco-initialize</id> > <goals> > <goal>prepare-agent</goal> > </goals> > </execution> > <execution> > <id>jacoco-site</id> > <phase>package</phase> > <goals> > <goal>report</goal> > </goals> > </execution> > </executions> > <configuration> > <excludes> > <exclude> > *.jar > </exclude> > <exclude> > **/BlockBuilderStatus.class > </exclude> > </excludes> > </configuration> > </plugin> > > Method deepInstanceSize in BlockBuilderStatus.java will be invoked when > the class is loaded , and it throws an Exception when use jacoco , it will > go into 'if (clazz.isArray())' this branch. so I want to skip > instrument the class . > > private static int deepInstanceSize(Class<?> clazz) > { > if (clazz.isArray()) { > throw new IllegalArgumentException(String.format("Cannot > determine size of %s because it contains an array", clazz.getSimpleName())); > } > if (clazz.isInterface()) { > throw new IllegalArgumentException(String.format("%s is an > interface", clazz.getSimpleName())); > } > if (Modifier.isAbstract(clazz.getModifiers())) { > throw new IllegalArgumentException(String.format("%s is > abstract", clazz.getSimpleName())); > } > if (!clazz.getSuperclass().equals(Object.class)) { > throw new IllegalArgumentException(String.format("Cannot > determine size of a subclass. %s extends from %s", clazz.getSimpleName(), > clazz.getSuperclass().getSimpleName())); > } > > int size = ClassLayout.parseClass(clazz).instanceSize(); > for (Field field : clazz.getDeclaredFields()) { > if (!field.getType().isPrimitive()) { > size += deepInstanceSize(field.getType()); > } > } > return size; > } > > -- 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/3be2158b-7815-48d6-a912-8353d72b2133%40googlegroups.com. For more options, visit https://groups.google.com/d/optout.
