<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;
}
Hi, Thank you so much for answering. I have tried to exclude class from instrumentationin "instrument" goal.
<execution>
<id>default-instrument</id><goals><goal>instrument</goal></goals>
<configuration><excludes><exclude>*.jar</exclude><exclude>**/BlockBuilderStatus
</exclude></excludes></configuration></execution>
I want use BlockBuilderStatus.class without instrumentation
An Ant BuildException has occured: Error while creating report: Error while analyzing xxx.class. Class xxx is already instrumented. "
Please change your code to ignore synthetic members.
where can I find a sample?