carbon-config icon indicating copy to clipboard operation
carbon-config copied to clipboard

Resolve jacoco maven plugin - class already instrumented exception when building the project

Open vidurananayakkara opened this issue 7 years ago • 5 comments

Jacoco plugin throws class already instrumented exception when building the project. These exceptions should not be thrown and should be resolved

More information:

A sample exception will be as shown below:

Caused by: java.lang.IllegalStateException: Class org/wso2/carbon/config/configuration/ConfigurationUtils is already instrumented.
	at org.jacoco.agent.rt.internal_b0d6a23.core.internal.instr.InstrSupport.assertNotInstrumented(InstrSupport.java:89)
	at org.jacoco.agent.rt.internal_b0d6a23.core.internal.instr.ClassInstrumenter.visitField(ClassInstrumenter.java:55)
	at org.jacoco.agent.rt.internal_b0d6a23.asm.ClassVisitor.visitField(ClassVisitor.java:272)
	at org.jacoco.agent.rt.internal_b0d6a23.asm.ClassReader.readField(ClassReader.java:768)
	at org.jacoco.agent.rt.internal_b0d6a23.asm.ClassReader.accept(ClassReader.java:689)
	at org.jacoco.agent.rt.internal_b0d6a23.asm.ClassReader.accept(ClassReader.java:506)
	at org.jacoco.agent.rt.internal_b0d6a23.core.instr.Instrumenter.instrument(Instrumenter.java:83)
	at org.jacoco.agent.rt.internal_b0d6a23.core.instr.Instrumenter.instrument(Instrumenter.java:101)
	... 47 more

This exception, however, does not impact the build or jacoco reports in any way. The plugin is configured to proceed ignore this warning and produce jacoco reports using the following config

<execution> <id>default-restore-instrumented-classes</id> <goals> <goal>restore-instrumented-classes</goal> </goals> </execution>

vidurananayakkara avatar Mar 15 '17 04:03 vidurananayakkara

Vidura, thanks for reporting this! I cannot see this issue in the master branch: build.txt Would you mind sharing the steps to recreate this?

imesh avatar Mar 22 '17 04:03 imesh

@imesh This error occurs after the carbon config was moved to a separate repo only. I haven't identified the root cause for this issue yet. This issue is not present in the master branch

vidurananayakkara avatar Mar 22 '17 06:03 vidurananayakkara

As per my insight into this research: It is possible to also use offline-instrumented classes with the JaCoCo Java agent. In this case, the configuration is taken from the agent options. The agent must be configured in a way that pre-instrumented classes are excluded, e.g. with " excludes=* ". Otherwise it will result in error messages on the console if the agent instruments such classes again likewise in your case. Jacoco plugin entry:-

<configuration> 
     <excludes> 
          <exclude>*</exclude> 
     </excludes> 
</configuration>

The agent jacocoagent.jar is part of the JaCoCo distribution and includes all required dependencies. A Java agent can be activated with the following JVM option(in command line):

-javaagent:[yourpath/]jacocoagent.jar=[option1]=[value1],[option2]=[value2]

For JaCoCo agent options, consider the following link: http://www.jacoco.org/jacoco/trunk/doc/agent.html

As the agent jacocoagent.jar is part of the JaCoCo distribution, it gets automatically included in argLine parameter and need not be set explicitly, but we should to verify if jacocoagent.jar is shown as set in argLine while doing mvn clean install command.

vermastuti avatar Aug 11 '17 18:08 vermastuti

Hi Guys, i am using below plugins , still getting the error java.lang.IllegalStateException: Cannot process instrumented class com/daa/kafka/connect/AzureProviderConfig. Please supply original non-instrumented classes.

Please someone help

        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-compiler-plugin</artifactId>
            <version>3.8.0</version>
              <configuration>
                <source>8</source>
                <target>8</target>
            </configuration>
        </plugin>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-assembly-plugin</artifactId>
            <executions>
                <execution>
                    <goals>
                        <goal>attached</goal>
                    </goals>
                    <phase>package</phase>
                    <configuration>
                        <descriptorRefs>
                            <descriptorRef>jar-with-dependencies</descriptorRef>
                        </descriptorRefs>
                        <archive>
                        </archive>
                    </configuration>
                </execution>
            </executions>
        </plugin>
         <plugin>
			<groupId>org.apache.maven.plugins</groupId>
			<artifactId>maven-release-plugin</artifactId>
			<version>3.0.0-M6</version>
		</plugin>
		
		<plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-surefire-plugin</artifactId>
            <version>2.20</version>
            <configuration>
                <skipTests>false</skipTests>
                <argLine>-Xmx1024m -XX:MaxPermSize=256m ${argLine}</argLine>
            </configuration>
        </plugin>
        <plugin>
            <groupId>org.jacoco</groupId>
            <artifactId>jacoco-maven-plugin</artifactId>
            <version>0.7.6.201602180812</version>
            <executions>
            
            <execution>
                <id>default-instrument</id>
                <goals>
                    <goal>instrument</goal>
                </goals>
            </execution>
            <execution>
                <id>default-restore-instrumented-classes</id>
                <goals>
                    <goal>restore-instrumented-classes</goal>
                </goals>
            </execution>
			 <execution>
                    <id>prepare-agent</id>
                    <goals>
                        <goal>prepare-agent</goal>
                    </goals>
					 <configuration> 
            <excludes> 
            <exclude>*</exclude> 
            </excludes> 
            </configuration>  
            </execution> 
                <execution>
                    <id>default-report</id>
                    <phase>prepare-package</phase>
                    <goals>
                        <goal>report</goal>
                    </goals>
                </execution>
            </executions>
        </plugin>
		
		 </plugins>
</build>

DevarajKR avatar Aug 25 '22 11:08 DevarajKR

Hi Guys, i am using below plugins , still getting the error java.lang.IllegalStateException: Cannot process instrumented class com/daa/kafka/connect/AzureProviderConfig. Please supply original non-instrumented classes.

Please someone help

        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-compiler-plugin</artifactId>
            <version>3.8.0</version>
              <configuration>
                <source>8</source>
                <target>8</target>
            </configuration>
        </plugin>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-assembly-plugin</artifactId>
            <executions>
                <execution>
                    <goals>
                        <goal>attached</goal>
                    </goals>
                    <phase>package</phase>
                    <configuration>
                        <descriptorRefs>
                            <descriptorRef>jar-with-dependencies</descriptorRef>
                        </descriptorRefs>
                        <archive>
                        </archive>
                    </configuration>
                </execution>
            </executions>
        </plugin>
         <plugin>
			<groupId>org.apache.maven.plugins</groupId>
			<artifactId>maven-release-plugin</artifactId>
			<version>3.0.0-M6</version>
		</plugin>
		
		<plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-surefire-plugin</artifactId>
            <version>2.20</version>
            <configuration>
                <skipTests>false</skipTests>
                <argLine>-Xmx1024m -XX:MaxPermSize=256m ${argLine}</argLine>
            </configuration>
        </plugin>
        <plugin>
            <groupId>org.jacoco</groupId>
            <artifactId>jacoco-maven-plugin</artifactId>
            <version>0.7.6.201602180812</version>
            <executions>
            
            <execution>
                <id>default-instrument</id>
                <goals>
                    <goal>instrument</goal>
                </goals>
            </execution>
            <execution>
                <id>default-restore-instrumented-classes</id>
                <goals>
                    <goal>restore-instrumented-classes</goal>
                </goals>
            </execution>
			 <execution>
                    <id>prepare-agent</id>
                    <goals>
                        <goal>prepare-agent</goal>
                    </goals>
					 <configuration> 
            <excludes> 
            <exclude>*</exclude> 
            </excludes> 
            </configuration>  
            </execution> 
                <execution>
                    <id>default-report</id>
                    <phase>prepare-package</phase>
                    <goals>
                        <goal>report</goal>
                    </goals>
                </execution>
            </executions>
        </plugin>
		
		 </plugins>
</build>

Hi @DevarajKR , is it solved?

wycmiko avatar Aug 28 '23 09:08 wycmiko