Class not found in resource cache

Must-share information:

  • Versions: SonarQube : 10.5.1, maven : 3.8.8, Java: jdk21, maven sonar scanner: 4.0.0.4121, jacoco: 0.8.12, surefire: 3.3.1, junit5: 5.5.1
  • how is SonarQube deployed: SonarQube runs in a Kubernetes cluster using Helm and a Docker image: sonarqube:10.5.1-community
  • what are you trying to achieve: Coverage test analysis

The problem is that all the unit tests have coverage analysis except for one file: InferenceServiceImplTest.java:

In a Jenkins Job, I run Maven Sonar analysis with the following command:

mvn sonar:sonar -X -Dsonar.projectName={project name} -Dsonar.host.url={my url} -Dsonar.login={my token}

From the logs, I found the following warnings for this file:

[INFO] 14:31:22.466 Starting batch processing.
[INFO] 14:31:28.045 100% analyzed
[INFO] 14:31:28.046 Batch processing: Done.
[INFO] 14:31:28.081 Did not optimize analysis for any files, performed a full analysis for all 22 files.
[INFO] 14:31:28.082 No "Generated" source files to scan.
[INFO] 14:31:28.082 Sensor JavaSensor [java] (done) | time=20391ms
[INFO] 14:31:28.083 Sensor SurefireSensor [java]
[INFO] 14:31:28.096 parsing [/home/jenkins/agent/workspace/eshop-project/target/surefire-reports]
[DEBUG] 14:31:28.613 Class not found in resource cache : bla.bla.bla.bla.projectname.test.service.InferenceServiceImplTest
[DEBUG] 14:31:28.614 Class not found in resource cache : bla.bla.bla.bla.projectname.test.service.InferenceServiceImplTest
[DEBUG] 14:31:28.614 Class not found in resource cache : bla.bla.bla.bla.projectname.test.service.InferenceServiceImplTest
[DEBUG] 14:31:28.615 Class not found in resource cache : bla.bla.bla.bla.projectname.test.service.InferenceServiceImplTest
[DEBUG] 14:31:28.615 Class not found in resource cache : bla.bla.bla.bla.projectname.test.service.InferenceServiceImplTest
[DEBUG] 14:31:28.615 Class not found in resource cache : bla.bla.bla.bla.projectname.test.service.InferenceServiceImplTest
[DEBUG] 14:31:28.615 Class not found in resource cache : bla.bla.bla.bla.projectname.test.service.InferenceServiceImplTest
[DEBUG] 14:31:28.615 Class not found in resource cache : bla.bla.bla.bla.projectname.test.service.InferenceServiceImplTest
[DEBUG] 14:31:28.615 Class not found in resource cache : bla.bla.bla.bla.projectname.test.service.InferenceServiceImplTest
[DEBUG] 14:31:28.615 Class not found in resource cache : bla.bla.bla.bla.projectname.test.service.InferenceServiceImplTest
[DEBUG] 14:31:28.615 Class not found in resource cache : bla.bla.bla.bla.projectname.test.service.InferenceServiceImplTest
[DEBUG] 14:31:28.615 Class not found in resource cache : bla.bla.bla.bla.projectname.test.service.InferenceServiceImplTest
[DEBUG] 14:31:28.615 Class not found in resource cache : bla.bla.bla.bla.projectname.test.service.InferenceServiceImplTest
[DEBUG] 14:31:28.616 Class not found in resource cache : bla.bla.bla.bla.projectname.test.service.InferenceServiceImplTest
[DEBUG] 14:31:28.616 Class not found in resource cache : bla.bla.bla.bla.projectname.test.service.InferenceServiceImplTest
[DEBUG] 14:31:28.616 Class not found in resource cache : bla.bla.bla.bla.projectname.test.service.InferenceServiceImplTest
[DEBUG] 14:31:28.616 Class not found in resource cache : bla.bla.bla.bla.projectname.test.service.InferenceServiceImplTest
[DEBUG] 14:31:28.616 Resource not found: bla.bla.bla.bla.projectname.test.service.InferenceServiceImplTest
[INFO] 14:31:28.658 Sensor SurefireSensor [java] (done) | time=576ms
[INFO] 14:31:28.658 Sensor XML Sensor [xml]
[DEBUG] 14:31:28.673 'pom.xml' generated metadata with charset 'UTF-8'
[INFO] 14:31:28.702 1 source file to be analyzed

However, I read the Surefire XML file, and it shows that all 16 tests ran successfully.

<testsuite xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="https://maven.apache.org/surefire/maven-surefire-plugin/xsd/surefire-test-report.xsd" version="3.0.2" name="bla.bla.bla.bla.projectname.test.service.InferenceServiceImplTest" time="13.523" tests="16" errors="0" skipped="0" failures="0">

Where could the problem be?

Hi,

Is the XML listing for this file similar to those for the other test files?

Are your tests all built and executed just before analysis?

 
Thx,
Ann

Hi,

First, I run the build command:

mvn clean install -Dmaven.test.failure.ignore=true

I get an error for this test file, but I’m not sure if it’s related because all tests are executing.

[INFO] Running bla.bla.bla.projectname.test.service.InferenceServiceImplTest
09:05:55.131 [main] ERROR org.apache.jena.riot -- [line: 1, col: 1 ] Content is not allowed in prolog.
09:05:56.615 [main] WARN bla.bla.bla.projectname.service.InferenceServiceImpl -- No inference SPARQL queries could be retrieved from the application.yml file, triples will be missing after the inference
09:05:57.960 [main] WARN bla.bla.bla.projectname.service.InferenceServiceImpl -- No inference SPARQL queries could be retrieved from the application.yml file, triples will be missing after the inference
09:06:03.501 [main] WARN bla.bla.bla.projectname.service.InferenceServiceImpl -- No inference SPARQL queries could be retrieved from the application.yml file, triples will be missing after the inference
09:06:04.412 [main] WARN bla.bla.bla.projectname.service.InferenceServiceImpl -- Extended model not defined, empty model will be used.
09:06:04.613 [main] WARN bla.bla.bla.projectname.service.InferenceServiceImpl -- No inference SPARQL queries could be retrieved from the application.yml file, triples will be missing after the inference
09:06:07.824 [main] WARN bla.bla.bla.projectname.utils.ModelUtils -- Couldn't find a lang name for name ''
[INFO] Tests run: 16, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 25.66 s -- in bla.bla.bla.projectname.test.service.InferenceServiceImplTest

In the second stage, I run the SonarQube command.

I can’t find anything in the pom.xml for excluding the file.

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
	<modelVersion>4.0.0</modelVersion>
	<groupId>bla.bla.bla.projectname.test.service</groupId>
	<artifactId>metadata-validation-service</artifactId>
	<version>2.3.0</version>
	<packaging>jar</packaging>
	<name>metadata-validation</name>
	<description>test</description>
	<parent>
		<groupId>org.springframework.boot</groupId>
		<artifactId>spring-boot-starter-parent</artifactId>
		<version>3.2.7</version>
		<relativePath />
	</parent>
	<properties>
		<aws-java-sdk.version>1.12.381</aws-java-sdk.version>
		<clover-extension-maven-plugin.version>1.0.0</clover-extension-maven-plugin.version>
		<clover-maven-plugin.version>4.2.1</clover-maven-plugin.version>
		<gson.version>2.10.1</gson.version>
		<guava.version>33.2.1-jre</guava.version>
		<java.version>21</java.version>
		<jena.version>4.10.0</jena.version>
        <jib.version>3.3.2</jib.version>
		<junit5.version>5.5.1</junit5.version>
		<junit5-platform.version>1.5.1</junit5-platform.version>
		<maven-surefire-plugin.version>3.3.1</maven-surefire-plugin.version>
		<mapstruct.version>1.2.0.Final</mapstruct.version>
		<version.dependency-check-maven>10.0.3</version.dependency-check-maven>
		<sonar.dependencyCheck.reportPath>${project.build.directory}/dependency-check-report.xml</sonar.dependencyCheck.reportPath>
		<sonar.dependencyCheck.htmlReportPath>${project.build.directory}/dependency-check-report.html</sonar.dependencyCheck.htmlReportPath>
		<pitest.version>1.4.9</pitest.version>
		<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
		<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
		<project.scm.id>arhs-ci-server</project.scm.id>
		<shacl.version>1.4.3</shacl.version>
		<springdoc-openapi-ui.version>2.5.0</springdoc-openapi-ui.version>
		<spring-retry.version>1.3.3</spring-retry.version>
		<spring-aspects.version>6.1.10</spring-aspects.version>
		<version.sonar>4.0.0.4121</version.sonar>
		<version.jacoco>0.8.12</version.jacoco>
		<tests.excluded>integration</tests.excluded>
		<tests.included></tests.included>
        <vault.version>4.1.3</vault.version>
	</properties>
	<dependencies>
		<dependency>
			<groupId>org.springframework.boot</groupId>
			<artifactId>spring-boot-starter-actuator</artifactId>
		</dependency>
		<dependency>
			<groupId>org.springframework.boot</groupId>
			<artifactId>spring-boot-starter-web</artifactId>
		</dependency>
		<dependency>
			<groupId>org.springframework.boot</groupId>
			<artifactId>spring-boot-configuration-processor</artifactId>
		</dependency>
		<dependency>
			<groupId>org.topbraid</groupId>
			<artifactId>shacl</artifactId>
			<version>${shacl.version}</version>
			<exclusions>
				<exclusion>
					<artifactId>log4j</artifactId>
					<groupId>log4j</groupId>
				</exclusion>
				<exclusion>
					<artifactId>slf4j-log4j12</artifactId>
					<groupId>org.slf4j</groupId>
				</exclusion>
			</exclusions>
		</dependency>
		<dependency>
			<groupId>org.apache.jena</groupId>
			<artifactId>jena-core</artifactId>
			<version>${jena.version}</version>
		</dependency>
		<dependency>
			<groupId>org.apache.jena</groupId>
			<artifactId>jena-arq</artifactId>
			<version>${jena.version}</version>
			<exclusions>
				<exclusion>
					<groupId>com.google.protobuf</groupId>
					<artifactId>protobuf-java</artifactId>
				</exclusion>
			</exclusions>
		</dependency>
		<dependency>
			<groupId>org.apache.jena</groupId>
			<artifactId>jena-querybuilder</artifactId>
			<version>${jena.version}</version>
		</dependency>
		<dependency>
			<groupId>org.springdoc</groupId>
			<artifactId>springdoc-openapi-starter-webmvc-ui</artifactId>
			<version>${springdoc-openapi-ui.version}</version>
		</dependency>
		<dependency>
			<groupId>com.amazonaws</groupId>
			<artifactId>aws-java-sdk-s3</artifactId>
			<version>${aws-java-sdk.version}</version>
		</dependency>
		<dependency>
			<groupId>com.google.guava</groupId>
			<artifactId>guava</artifactId>
			<version>${guava.version}</version>
		</dependency>
		<dependency>
			<groupId>com.google.code.gson</groupId>
			<artifactId>gson</artifactId>
		</dependency>
		<dependency>
			<groupId>jakarta.xml.bind</groupId>
			<artifactId>jakarta.xml.bind-api</artifactId>
		</dependency>
		<dependency>
			<groupId>org.springframework.boot</groupId>
			<artifactId>spring-boot-starter-test</artifactId>
			<scope>test</scope>
		</dependency>
		<dependency>
			<groupId>org.junit.platform</groupId>
			<artifactId>junit-platform-engine</artifactId>
			<scope>test</scope>
		</dependency>
		<dependency>
			<groupId>org.mockito</groupId>
			<artifactId>mockito-junit-jupiter</artifactId>
			<scope>test</scope>
		</dependency>
		<dependency>
			<groupId>org.junit.platform</groupId>
			<artifactId>junit-platform-commons</artifactId>
			<scope>test</scope>
		</dependency>
		<dependency>
			<groupId>org.junit.jupiter</groupId>
			<artifactId>junit-jupiter-api</artifactId>
			<scope>test</scope>
		</dependency>
		<dependency>
			<groupId>org.junit.jupiter</groupId>
			<artifactId>junit-jupiter-engine</artifactId>
			<scope>test</scope>
		</dependency>
		<dependency>
			<groupId>bla.bla.bla.projectname</groupId>
			<artifactId>clover-extension-maven-plugin</artifactId>
			<version>1.0.0</version>
			<optional>true</optional>
		</dependency>
		<dependency>
			<groupId>org.mapstruct</groupId>
			<artifactId>mapstruct</artifactId>
			<version>${mapstruct.version}</version>
			<scope>provided</scope>
		</dependency>
		<dependency>
			<groupId>io.micrometer</groupId>
			<artifactId>micrometer-registry-jmx</artifactId>
		</dependency>
		<dependency>
			<groupId>org.springframework.retry</groupId>
			<artifactId>spring-retry</artifactId>
		</dependency>
		<dependency>
			<groupId>org.springframework</groupId>
			<artifactId>spring-aspects</artifactId>
		</dependency>
		<dependency>
			<groupId>org.yaml</groupId>
			<artifactId>snakeyaml</artifactId>
		</dependency>

        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-vault-config</artifactId>
            <version>${vault.version}</version>
        </dependency>
    </dependencies>
    <dependencyManagement>
        <dependencies>
            <dependency>
                <groupId>org.springframework.cloud</groupId>
                <artifactId>spring-cloud-dependencies</artifactId>
                <version>2023.0.3</version>
                <type>pom</type>
                <scope>import</scope>
            </dependency>
        </dependencies>
    </dependencyManagement>

	<build>
        <!-- Required for Vault - expecting the keystore on the classpath keystore directory.-->
        <resources>
            <!-- Define as classpath resource with filtering enabled
             everything included in /resources directory -->
            <resource>
                <directory>src/main/resources</directory>
                <filtering>true</filtering>
                <excludes>
                    <exclude>/keystore/*</exclude>
                </excludes>
            </resource>
            <!-- Define as classpath resource with filtering disabled the keystore folder -->
            <resource>
                <directory>src/main/resources/keystore/</directory>
                <filtering>false</filtering>
                <!-- By not defining <targetPath>keystore</targetPath> the contents of keystore are by default
                 placed in classpath: and not in classpath:keystore/ -->
            </resource>
        </resources>

		<pluginManagement>
			<plugins>
				<plugin>
					<groupId>org.sonarsource.scanner.maven</groupId>
					<artifactId>sonar-maven-plugin</artifactId>
					<version>${version.sonar}</version>
				</plugin>
				<plugin>
					<groupId>org.owasp</groupId>
					<artifactId>dependency-check-maven</artifactId>
					<version>${version.dependency-check-maven}</version>
					<configuration>
						<format>ALL</format>
						<failOnError>false</failOnError>
						<nvdApiKey>MyNVDkey</nvdApiKey>
						<suppressionFile>owasp-dependency-check-exclude.xml</suppressionFile>
					</configuration>
				</plugin>
			</plugins>
		</pluginManagement>
		<plugins>
			<plugin>
				<groupId>org.springframework.boot</groupId>
				<artifactId>spring-boot-maven-plugin</artifactId>
			</plugin>
			<plugin>
				<groupId>org.apache.maven.plugins</groupId>
				<artifactId>maven-release-plugin</artifactId>
				<version>2.5.3</version>
				<configuration>
					<releaseProfiles>release</releaseProfiles>
					<tagBase>https://gitlabUrl/tags
                    </tagBase>
					<tagNameFormat>@{project.version}</tagNameFormat>
				</configuration>
			</plugin>
			<plugin>
				<groupId>org.apache.maven.plugins</groupId>
				<artifactId>maven-surefire-plugin</artifactId>
				<version>${maven-surefire-plugin.version}</version>
				<configuration>
					<useSystemClassLoader>false</useSystemClassLoader>
					<groups>${tests.included}</groups>
					<excludedGroups>${tests.excluded}</excludedGroups>
				</configuration>
			</plugin>
			<plugin>
				<groupId>org.apache.maven.plugins</groupId>
				<artifactId>maven-failsafe-plugin</artifactId>
				<version>${maven-surefire-plugin.version}</version>
			</plugin>
			<plugin>
				<groupId>org.jacoco</groupId>
				<artifactId>jacoco-maven-plugin</artifactId>
				<version>${version.jacoco}</version>
				<executions>
					<execution>
						<id>prepare-unit-test-agent</id>
						<goals>
							<goal>prepare-agent</goal>
						</goals>
					</execution>
					<execution>
						<id>generate-unit-test-report</id>
						<goals>
							<goal>report</goal>
						</goals>
					</execution>
					<execution>
						<id>prepare-integration-test-agent</id>
						<goals>
							<goal>prepare-agent-integration</goal>
						</goals>
					</execution>
					<execution>
						<id>generate-integration-test-report</id>
						<goals>
							<goal>report-integration</goal>
						</goals>
					</execution>
				</executions>
			</plugin>
		</plugins>
	</build>
	<profiles>
		<profile>
			<id>allTests</id>
			<properties>
				<tests.excluded></tests.excluded>
			</properties>
		</profile>
		<profile>
			<id>integrationTests</id>
			<properties>
				<tests.included>integration</tests.included>
				<tests.excluded></tests.excluded>
			</properties>
		</profile>
		<profile>
			<id>digit</id>
			<repositories>
				<repository>
					<id>digit-releases</id>
					<url>url path</url>
					<releases>
						<enabled>true</enabled>
					</releases>
					<snapshots>
						<enabled>false</enabled>
					</snapshots>
				</repository>
				<repository>
					<id>digital-snapshots</id>
					<url>url path/op</url>
					<releases>
						<enabled>false</enabled>
					</releases>
					<snapshots>
						<enabled>true</enabled>
					</snapshots>
				</repository>
				<repository>
					<id>atlassian-public</id>
					<url>https://packages.atlassian.com/maven/repository/public</url>
					<releases>
						<enabled>true</enabled>
					</releases>
				</repository>
			</repositories>
		</profile>
		<profile>
			<id>sonar</id>
			<properties>
				<sonar.host.url>sonar url</sonar.host.url>
				<sonar.login>admin</sonar.login>
				<sonar.password>admin</sonar.password>
			</properties>
		</profile>
		<profile>
			<id>clover</id>
			<build>
				<plugins>
					<plugin>
						<groupId>bla.bla.bla.projectname</groupId>
						<artifactId>clover-extension-maven-plugin</artifactId>
						<version>${clover-extension-maven-plugin.version}</version>
						<executions>
							<execution>
								<phase>process-sources</phase>
								<goals>
									<goal>replace-annotation</goal>
								</goals>
							</execution>
						</executions>
					</plugin>
					<plugin>
						<groupId>org.openclover</groupId>
						<artifactId>clover-maven-plugin</artifactId>
						<version>${clover-maven-plugin.version}</version>
						<configuration>
							<singleCloverDatabase>true</singleCloverDatabase>
							<distributedCoverage>
								<numClients>1</numClients>
							</distributedCoverage>
							<targetPercentage>86.2%</targetPercentage>
							<generateHtml>true</generateHtml>
						</configuration>
						<executions>
							<execution>
								<phase>process-sources</phase>
								<goals>
									<goal>setup</goal>
								</goals>
							</execution>
							<execution>
								<id>log</id>
								<phase>test</phase>
								<goals>
									<goal>log</goal>
									<goal>clover</goal>
									<goal>check</goal>
								</goals>
							</execution>
						</executions>
					</plugin>
				</plugins>
			</build>
		</profile>
		<profile>
			<id>owasp</id>
			<build>
				<plugins>
					<plugin>
						<groupId>org.owasp</groupId>
						<artifactId>dependency-check-maven</artifactId>
						<version>${owasp-dependency-check.version}</version>
						<configuration>
							<failBuildOnCVSS>0</failBuildOnCVSS>
							<suppressionFile>owasp-dependency-check-exclude.xml</suppressionFile>
						</configuration>
						<executions>
							<execution>
								<goals>
									<goal>check</goal>
								</goals>
							</execution>
						</executions>
					</plugin>
				</plugins>
			</build>
		</profile>
	</profiles>
</project>

Thnx,
Apostolos

Hi Apostolos,

What I was asking was: when you open the Surefire XML file and look at the contents, do the listings for the other files look similar in format and content to the one for InferenceServiceImplTest.java?

 
Thx,
Ann

Hi Ann,

Yes, the format is the same in all XML files.

Thnx,
Apostolos

Hi Apostolos,

Thanks for that confirmation. I’m going to flag this for the language experts.

 
Ann

Hi @alazidis,

After reviewing the information and logs you provided, I see that InferenceServiceImplTest has some issues.
Can you please try to fix the test and successfully build the project with the command: mvn clean install ?

Thank you!

All the best,

Irina

Hi Irina,

The error and warning in the logs of InferenceServiceImplTest do not impact test results, as all tests ran successfully, which is confirmed by the Surefire xml for InferenceServiceImplTest. Also, I tried running Sonnar scanner with Java version 17 and 21, but without success.

Thank you,
Lazidis Apostolos

Hi @alazidis,

Can you please build your project with the command mvn clean install , analyze it, and send me the logs?
Thank you!

All the best,

Irina