Trivadis / plsql-cop-sonar

db* CODECOP for SonarQube
13 stars 3 forks source link

Support Projects running with Java 17 #5

Closed stadler closed 2 years ago

stadler commented 2 years ago

It seems that PLSQL Cop has issues when running with Java 17. Our SonarQube-Build produces the following Error when switching to Java 17:


$ java --version
openjdk 17.0.1 2021-10-19
OpenJDK Runtime Environment Temurin-17.0.1+12 (build 17.0.1+12)
OpenJDK 64-Bit Server VM Temurin-17.0.1+12 (build 17.0.1+12, mixed mode, sharing)
$ mvn --version
Apache Maven 3.8.4 (9b656c72d54e5bacbed989b64718c159fe39b537)
Maven home: /opt/apache-maven-3.8.4
Java version: 17.0.1, vendor: Eclipse Adoptium, runtime: /usr/lib/jvm/jdk-17.0.1+12
Default locale: en_US, platform encoding: UTF-8
OS name: "linux", version: "4.12.14-122.20-default", arch: "amd64", family: "unix"
$ mvn sonar:sonar
...
1483 [INFO] Sensor com.github.mc1arke.sonarqube.plugin.scanner.ScannerPullRequestPropertySensor
71490 [INFO] Sensor com.github.mc1arke.sonarqube.plugin.scanner.ScannerPullRequestPropertySensor (done) | time=7ms
71490 [INFO] Sensor PlSQL COP Sensor [plsqlcop]
72058 [INFO] ------------------------------------------------------------------------
72058 [INFO] Reactor Summary for myproject 1.2-SNAPSHOT:
72058 [INFO] 
72058 [INFO] myproject ............................................... FAILURE [ 27.002 s]
72058 [INFO] ------------------------------------------------------------------------
72058 [INFO] BUILD FAILURE
72058 [INFO] ------------------------------------------------------------------------
72058 [INFO] Total time:  01:10 min (Wall Clock)
72059 [INFO] Finished at: 2021-12-08T15:49:35+01:00
72059 [INFO] ------------------------------------------------------------------------
72059 [ERROR] Failed to execute goal org.sonarsource.scanner.maven:sonar-maven-plugin:3.9.1.2184:sonar (default-cli) on project myproject: Execution default-cli of goal org.sonarsource.scanner.maven:sonar-maven-plugin:3.9.1.2184:sonar failed: An API incompatibility was encountered while executing org.sonarsource.scanner.maven:sonar-maven-plugin:3.9.1.2184:sonar: java.lang.ExceptionInInitializerError: null
72059 [ERROR] -----------------------------------------------------
72059 [ERROR] realm =    plugin>org.sonarsource.scanner.maven:sonar-maven-plugin:3.9.1.2184
72059 [ERROR] strategy = org.codehaus.plexus.classworlds.strategy.SelfFirstStrategy
72059 [ERROR] urls[0] = file:/builds/myproject/.m2/repository/org/sonarsource/scanner/maven/sonar-maven-plugin/3.9.1.2184/sonar-maven-plugin-3.9.1.2184.jar
72059 [ERROR] urls[1] = file:/builds/myproject/.m2/repository/org/sonatype/plexus/plexus-sec-dispatcher/1.4/plexus-sec-dispatcher-1.4.jar
72060 [ERROR] urls[2] = file:/builds/myproject/.m2/repository/org/sonatype/plexus/plexus-cipher/1.4/plexus-cipher-1.4.jar
72060 [ERROR] urls[3] = file:/builds/myproject/.m2/repository/org/codehaus/plexus/plexus-utils/3.2.1/plexus-utils-3.2.1.jar
72060 [ERROR] urls[4] = file:/builds/myproject/.m2/repository/org/sonarsource/scanner/api/sonar-scanner-api/2.16.2.588/sonar-scanner-api-2.16.2.588.jar
72060 [ERROR] urls[5] = file:/builds/myproject/.m2/repository/commons-lang/commons-lang/2.6/commons-lang-2.6.jar
72060 [ERROR] Number of foreign imports: 1
72060 [ERROR] import: Entry[import  from realm ClassRealm[maven.api, parent: null]]
72060 [ERROR] 
72060 [ERROR] -----------------------------------------------------: com.google.inject.internal.util.$ComputationException: java.lang.ExceptionInInitializerError: Unable to make protected final java.lang.Class java.lang.ClassLoader.defineClass(java.lang.String,byte[],int,int,java.security.ProtectionDomain) throws java.lang.ClassFormatError accessible: module java.base does not "opens java.lang" to unnamed module @6e93232
72060 [ERROR] -> [Help 1]
`
``

When looking at the logs, it looks like PLSQL COP Sensor is responsible for the problem.
Have you already tested it on Java 17?
What are the plans to support Java 17?
PhilippSalvisberg commented 2 years ago

I tried to reproduce the issue as follows.

First, I configured $HOME/.m2/settings.xml according https://docs.sonarqube.org/latest/analysis/scan/sonarscanner-for-maven/ .

Then I created a new project with the following pom.xml:

<?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/maven-v4_0_0.xsd">
  <modelVersion>4.0.0</modelVersion>

  <groupId>com.trivadis.com</groupId>
  <artifactId>plsql-test</artifactId>
  <version>1.0-SNAPSHOT</version>

</project>

Then I copied guideline_4230_37.sql into the src/main/java folder.

And then I printed the Java version and run Maven. Here's the console output:

phs@macphs21 20211209_sonar % java -version
java version "17.0.1" 2021-10-19 LTS
Java(TM) SE Runtime Environment (build 17.0.1+12-LTS-39)
Java HotSpot(TM) 64-Bit Server VM (build 17.0.1+12-LTS-39, mixed mode, sharing)
phs@macphs21 20211209_sonar % mvn sonar:sonar
[INFO] Scanning for projects...
[INFO] 
[INFO] --------------------< com.trivadis.com:plsql-test >---------------------
[INFO] Building plsql-test 1.0-SNAPSHOT
[INFO] --------------------------------[ jar ]---------------------------------
[INFO] 
[INFO] --- sonar-maven-plugin:3.6.0.1398:sonar (default-cli) @ plsql-test ---
[INFO] User cache: /Users/phs/.sonar/cache
[INFO] SonarQube version: 8.9.0
[INFO] Default locale: "en_CH", source code encoding: "UTF-8" (analysis is platform dependent)
[INFO] Load global settings
[INFO] Load global settings (done) | time=179ms
[INFO] Server id: BF41A1F2-AXVRgA-nQTVPn48yw8x6
[INFO] User cache: /Users/phs/.sonar/cache
[INFO] Load/download plugins
[INFO] Load plugins index
[INFO] Load plugins index (done) | time=36ms
[INFO] Load/download plugins (done) | time=133ms
[INFO] Loaded core extensions: developer-scanner
[INFO] JavaScript/TypeScript frontend is enabled
[INFO] Define db* CODECOP PlugIn (Standalone)
[INFO] Process project properties
[INFO] Process project properties (done) | time=4ms
[INFO] Execute project builders
[INFO] Execute project builders (done) | time=1ms
[INFO] Project key: com.trivadis.com:plsql-test
[INFO] Base dir: /Users/phs/ownCloud/Business/Tests/2021/20211209_sonar
[INFO] Working dir: /Users/phs/ownCloud/Business/Tests/2021/20211209_sonar/target/sonar
[INFO] Load project settings for component key: 'com.trivadis.com:plsql-test'
[INFO] Load project settings for component key: 'com.trivadis.com:plsql-test' (done) | time=33ms
[INFO] Load project branches
[INFO] Load project branches (done) | time=25ms
[INFO] Load project pull requests
[INFO] Load project pull requests (done) | time=15ms
[INFO] Load branch configuration
[INFO] Load branch configuration (done) | time=1ms
[INFO] Load quality profiles
[INFO] Load quality profiles (done) | time=265ms
[INFO] Load active rules
[INFO] Load active rules (done) | time=4936ms
[WARNING] SCM provider autodetection failed. Please use "sonar.scm.provider" to define SCM of your project, or disable the SCM Sensor in the project settings.
[INFO] Indexing files...
[INFO] Project configuration:
[INFO] 2 files indexed
[INFO] Quality profile for plsqlcop: db* CODECOP
[INFO] Quality profile for xml: Sonar way
[INFO] ------------- Run sensors on module plsql-test
[INFO] JavaScript/TypeScript frontend is enabled
[INFO] Define db* CODECOP PlugIn (Standalone)
[INFO] Load metrics repository
[INFO] Load metrics repository (done) | time=20ms
[INFO] PlSQL COP Sensor initializing
[INFO] Instantiate class: com.trivadis.sonar.plugin.TrivadisGuidelines3PlusValidatorConfig
[INFO] Sensor CSS Rules [cssfamily]
[INFO] No CSS, PHP, HTML or VueJS files are found in the project. CSS analysis is skipped.
[INFO] Sensor CSS Rules [cssfamily] (done) | time=1ms
[INFO] Sensor C# Project Type Information [csharp]
[INFO] Sensor C# Project Type Information [csharp] (done) | time=0ms
[INFO] Sensor C# Properties [csharp]
[INFO] Sensor C# Properties [csharp] (done) | time=1ms
[INFO] Sensor JavaXmlSensor [java]
[INFO] 1 source file to be analyzed
[INFO] Load project repositories
[INFO] Load project repositories (done) | time=35ms
[INFO] 1/1 source file has been analyzed
[INFO] Sensor JavaXmlSensor [java] (done) | time=115ms
[INFO] Sensor HTML [web]
[INFO] Sensor HTML [web] (done) | time=1ms
[INFO] Sensor XML Sensor [xml]
[INFO] 1 source file to be analyzed
[INFO] 1/1 source file has been analyzed
[INFO] Sensor XML Sensor [xml] (done) | time=64ms
[INFO] Sensor VB.NET Project Type Information [vbnet]
[INFO] Sensor VB.NET Project Type Information [vbnet] (done) | time=1ms
[INFO] Sensor VB.NET Properties [vbnet]
[INFO] Sensor VB.NET Properties [vbnet] (done) | time=0ms
[INFO] Sensor JaCoCo XML Report Importer [jacoco]
[INFO] 'sonar.coverage.jacoco.xmlReportPaths' is not defined. Using default locations: target/site/jacoco/jacoco.xml,target/site/jacoco-it/jacoco.xml,build/reports/jacoco/test/jacocoTestReport.xml
[INFO] No report imported, no coverage information will be imported by JaCoCo XML Report Importer
[INFO] Sensor JaCoCo XML Report Importer [jacoco] (done) | time=3ms
[INFO] Sensor ThymeLeaf template sensor [securityjavafrontend]
[INFO] Sensor ThymeLeaf template sensor [securityjavafrontend] (done) | time=1ms
[INFO] Sensor PlSQL COP Sensor [plsqlcop]
[INFO] Process resource guideline_4230_37.sql
[WARNING] Metric 'lines' is an internal metric computed by SonarQube/SonarCloud. Provided value is ignored.
[INFO] Sensor PlSQL COP Sensor [plsqlcop] (done) | time=1470ms
[INFO] Sensor JavaSecuritySensor [security]
[INFO] Reading type hierarchy from: /Users/phs/ownCloud/Business/Tests/2021/20211209_sonar/target/sonar/ucfg2/java
[INFO] Read 0 type definitions
[INFO] Reading UCFGs from: /Users/phs/ownCloud/Business/Tests/2021/20211209_sonar/target/sonar/ucfg2/java
[INFO] No UCFGs have been included for analysis.
[INFO] Sensor JavaSecuritySensor [security] (done) | time=2ms
[INFO] Sensor CSharpSecuritySensor [security]
[INFO] Reading type hierarchy from: /Users/phs/ownCloud/Business/Tests/2021/20211209_sonar/target/ucfg_cs2
[INFO] Read 0 type definitions
[INFO] Reading UCFGs from: /Users/phs/ownCloud/Business/Tests/2021/20211209_sonar/target/ucfg_cs2
[INFO] No UCFGs have been included for analysis.
[INFO] Sensor CSharpSecuritySensor [security] (done) | time=0ms
[INFO] Sensor PhpSecuritySensor [security]
[INFO] Reading type hierarchy from: /Users/phs/ownCloud/Business/Tests/2021/20211209_sonar/target/sonar/ucfg2/php
[INFO] Read 0 type definitions
[INFO] Reading UCFGs from: /Users/phs/ownCloud/Business/Tests/2021/20211209_sonar/target/sonar/ucfg2/php
[INFO] No UCFGs have been included for analysis.
[INFO] Sensor PhpSecuritySensor [security] (done) | time=0ms
[INFO] Sensor PythonSecuritySensor [security]
[INFO] Reading type hierarchy from: /Users/phs/ownCloud/Business/Tests/2021/20211209_sonar/target/sonar/ucfg2/python
[INFO] Read 0 type definitions
[INFO] Reading UCFGs from: /Users/phs/ownCloud/Business/Tests/2021/20211209_sonar/target/sonar/ucfg2/python
[INFO] No UCFGs have been included for analysis.
[INFO] Sensor PythonSecuritySensor [security] (done) | time=0ms
[INFO] Sensor JsSecuritySensor [security]
[INFO] Reading type hierarchy from: /Users/phs/ownCloud/Business/Tests/2021/20211209_sonar/target/sonar/ucfg2/js
[INFO] Read 0 type definitions
[INFO] Reading UCFGs from: /Users/phs/ownCloud/Business/Tests/2021/20211209_sonar/target/sonar/ucfg2/js
[INFO] No UCFGs have been included for analysis.
[INFO] Sensor JsSecuritySensor [security] (done) | time=1ms
[INFO] ------------- Run sensors on project
[INFO] Sensor Zero Coverage Sensor
[INFO] Sensor Zero Coverage Sensor (done) | time=1ms
[INFO] SCM Publisher No SCM system was detected. You can use the 'sonar.scm.provider' property to explicitly specify it.
[INFO] CPD Executor Calculating CPD for 0 files
[INFO] CPD Executor CPD calculation finished (done) | time=0ms
[INFO] Load New Code definition
[INFO] Load New Code definition (done) | time=13ms
[INFO] Analysis report generated in 46ms, dir size=177 KB
[INFO] Analysis report compressed in 25ms, zip size=25 KB
[INFO] Analysis report uploaded in 53ms
[INFO] ANALYSIS SUCCESSFUL, you can browse http://fillmore:9000/dashboard?id=com.trivadis.com%3Aplsql-test
[INFO] Note that you will be able to access the updated dashboard once the server has processed the submitted analysis report
[INFO] More about the report processing at http://fillmore:9000/api/ce/task?id=AX2eF5mfPL6dFkf1eZ-C
[INFO] Analysis total time: 8.165 s
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time:  9.110 s
[INFO] Finished at: 2021-12-09T08:28:06+01:00
[INFO] ------------------------------------------------------------------------
phs@macphs21 20211209_sonar %       

I installed the following plugins in SonarQube Version 8.9:

image

So it should work with Java 17.

Could you please tell me about more about your SonarQube version and installed plugins? Could you please provide the full console log?

stadler commented 2 years ago

Hi Thanks a lot for your answer! We discovered that we were still using an old version of the plugin. We'll analyse if it works with the current version. Thank you!