SonarOpenCommunity / sonar-cxx

SonarQube C++ Community plugin (cxx plugin): This plugin adds C++ support to SonarQube with the focus on integration of existing C++ tools.
GNU Lesser General Public License v3.0
996 stars 364 forks source link

NoClassDefError with the SonarScanner #2686

Open shangchenlin opened 5 months ago

shangchenlin commented 5 months ago

Before you create a new issue

Describe the bug When I run the command line which the SonarQube gave me, it kept jump the NoClassDefError

Screenshots cmd_UXwMMFP2JE cmd_qwtaAaOmGF

Desktop (please complete the following information):

guwirth commented 5 months ago

Hi @shangchenlin,

the NoClassDefError comes from CxxUnitTestResultsAggregator in https://github.com/SonarOpenCommunity/sonar-cxx/blob/1be6f9d3ff826cd7f52cb6bbf512358e69f2f6b4/sonar-cxx-plugin/src/main/java/org/sonar/plugins/cxx/CxxPlugin.java#L80 https://github.com/SonarOpenCommunity/sonar-cxx/blob/1be6f9d3ff826cd7f52cb6bbf512358e69f2f6b4/sonar-cxx-plugin/src/main/java/org/sonar/plugins/cxx/CxxPlugin.java#L110

That‘s one of the first steps during setup of the plugin, long before any analysis is executed. Wondering how that could be because CI tests are running? https://github.com/SonarOpenCommunity/sonar-cxx/actions/runs/9267875389

Regards,

guwirth commented 5 months ago

Duplicate #2634, #2475

2475 has been solved with:

The issue has been solved. The resolution was to clear the /var/lib/jenkins/.sonar tmp files and the /var/lib/jenkins/.sonar/cache as well as ensure the /var/lib/jenkins/.sonar/cache/_tmp folder had the correct ownership:group

shangchenlin commented 5 months ago

I am running on local PC with Oracle Java 17, I didn't run any testing, I just want to analyze the .xml which cpp check gave, I have another question is that is this plugin really need cpp check? Also, this is my current SonarQube showed image image ![Uploading image.png…]()

guwirth commented 5 months ago

is this plugin really need cpp check?

SonarQube C++ Community plugin (cxx plugin): This plugin adds C++ support to SonarQube with the focus on integration of existing C++ tools. …the main purpose of the cxx plugin is to forward reports from 3rd party tools to SonarQube. The plugin is not doing any static code analysis by its own. If you want that you have to use the SQ developer edition with the cpp plugin.

qathy commented 4 months ago

Duplicate #2634, #2475

2475 has been solved with:

The issue has been solved. The resolution was to clear the /var/lib/jenkins/.sonar tmp files and the /var/lib/jenkins/.sonar/cache as well as ensure the /var/lib/jenkins/.sonar/cache/_tmp folder had the correct ownership:group

We don't use Jenkins to run our CI jobs, but GitLab CI which launches jobs on docker containers (hence, clean) using the official image sonarsource/sonar-scanner-cli:latest and despite this hopefully clean environment, we do experience the same java.lang.ClassNotFoundException: org.sonar.cxx.sensors.tests.dotnet.CxxUnitTestResultsAggregator issue.

NB: aggregator is used to collect compilation warnings from both Linux and Windows platforms, ccpcheck analysis, gcov results as well as valgrind output.

@guwirth do you have any hint, like using a better docker image, for instance? Or do we have to inject the pluggin, or an updated version, in the container?

Aga303 commented 3 months ago

We don't use Jenkins to run our CI jobs, but GitLab CI which launches jobs on docker containers (hence, clean) using the official image sonarsource/sonar-scanner-cli:latest and despite this hopefully clean environment, we do experience the same java.lang.ClassNotFoundException: org.sonar.cxx.sensors.tests.dotnet.CxxUnitTestResultsAggregator issue.

We have the same setup and the same problem. And ours does not even have C++ code. Removing the sonar-caches did not help. In production we run sonar-scanner-cli:5 and that's working without problems.

guwirth commented 3 months ago

The NoClassDefFoundError is a runtime error in Java that occurs if the Java Virtual Machine (JVM) or a ClassLoader instance attempts to load the definition of a class but cannot find it at runtime. The class definition exists at compile-time but is not available at runtime.

What I still don’t understand is, that everything is working fine in our test environments. Why is only sometimes the dependency to the class CxxUnitTestResultsAggregator not available at runtime? Someone an idea?

Found this: https://rollbar.com/blog/java-no-class-def-found-error/