The only pattern I can find is that is in some cases the class where the issue is raised has been actually modified during new code period. I understand that could make to detect some issues as new code for some rules, like java:S120 (package naming) or when adding a new line in an “if” that already had a Cognitive Complexity issue.
But I have an example of a constants class, just a list of them, where a new one has been added, and then Sonarqube raises as new issue an already existing constant declaration 200 lines before the new one.
This makes me wonder if an existing issue is defined as new every time the file is modified, no matter the rule.
Another explanation for this is that analysis doesn’t have the SCM metadata it needs to correctly understand what’s new and what’s not.
We would need your analysis log to understand.
The analysis / scanner log is what’s output from the analysis command. Hopefully, the log you provide - redacted as necessary - will include that command as well.
This isn’t in the guide I pointed you to, but it’s a classic example of how you get new issues in old code. When that like was originally written new Integer(int) wasn’t deprecated. In the meantime, I suppose you’ve upgraded your Java version, and now it is.
We haven’t upgraded the java version (we will soon, and it is very interesting that you pointed it). Here you may find the analysis of the issue of my first post (“Remove this expression which always evaluate to true”) with the new version of Sonarqube and sonar.java.source still set to 8.
[INFO]
[INFO] --- sonar-maven-plugin:4.0.0.4121:sonar (default-cli) @ reg-integration ---
[INFO] 09:24:51.714 Java 21.0.5 Azul Systems, Inc. (64-bit)
[INFO] 09:24:51.714 Linux 6.13.11-200.fc41.x86_64 (amd64)
[INFO] 09:24:51.714 MAVEN_OPTS= -Djava.awt.headless=true
[INFO] 09:24:51.871 User cache: /*********/.sonar/cache
[INFO] 09:24:52.200 Communicating with SonarQube Server 25.2.0.102705
[INFO] 09:24:52.289 Default locale: "en_US", source code encoding: "UTF-8"
[INFO] 09:24:53.182 Load global settings
[INFO] 09:24:53.451 Load global settings (done) | time=270ms
[INFO] 09:24:53.483 Server id: *********
[INFO] 09:24:53.496 Loading required plugins
[INFO] 09:24:53.496 Load plugins index
[INFO] 09:24:53.563 Load plugins index (done) | time=67ms
[INFO] 09:24:53.564 Load/download plugins
[INFO] 09:24:53.638 Load/download plugins (done) | time=75ms
[INFO] 09:24:54.144 Process project properties
[INFO] 09:24:54.159 Process project properties (done) | time=15ms
[INFO] 09:24:54.170 Project key: /*********/.
[INFO] 09:24:54.171 Base dir: //*********/.
[INFO] 09:24:54.171 Working dir: //*********/.
[INFO] 09:24:54.179 Load project settings for component key: /*********/.'
[INFO] 09:24:54.293 Load project settings for component key: '/*********/.' (done) | time=114ms
[INFO] 09:24:54.318 Load project branches
[INFO] 09:24:54.386 Load project branches (done) | time=68ms
[INFO] 09:24:54.387 Load branch configuration
[INFO] 09:24:54.390 Auto detected BRANCH configuration with source develop using com.github.mc1arke.sonarqube.plugin.scanner.autoconfiguration.GitlabCiAutoConfigurer
[INFO] 09:24:54.390 Load branch configuration (done) | time=3ms
[INFO] 09:24:54.410 Load quality profiles
[INFO] 09:24:54.493 Load quality profiles (done) | time=83ms
[INFO] 09:24:54.500 Auto-configuring with CI 'Gitlab CI'
[INFO] 09:24:54.537 Load active rules
[INFO] 09:24:54.945 Load active rules (done) | time=408ms
[INFO] 09:24:54.952 Load analysis cache
[INFO] 09:24:54.997 Load analysis cache | time=45ms
[INFO] 09:24:55.069 Branch name: develop
[INFO] 09:24:55.091 Preprocessing files...
[INFO] 09:24:55.815 2 languages detected in 708 preprocessed files
[INFO] 09:24:55.815 334 files ignored because of inclusion/exclusion patterns
[INFO] 09:24:55.816 0 files ignored because of scm ignore settings
[INFO] 09:24:55.819 Loading plugins for detected languages
[INFO] 09:24:55.820 Load/download plugins
[INFO] 09:24:55.904 Load/download plugins (done) | time=84ms
[INFO] 09:24:56.126 Load project repositories
[INFO] 09:24:56.301 Load project repositories (done) | time=175ms
[INFO] 09:24:56.321 Indexing files...
[INFO] 09:24:56.321 Project configuration:
[INFO] 09:24:56.321 Excluded sources: **//*********/./inputs/**
[INFO] 09:24:56.322 Excluded tests: **/test/**, **/unitTest/**
[INFO] 09:24:56.351 708 files indexed
[INFO] 09:24:56.352 Quality profile for java: R9K Java Quality profile
[INFO] 09:24:56.352 Quality profile for xml: Sonar way
[INFO] 09:24:56.352 ------------- Run sensors on module /*********/.: A.0.0-SNAPSHOT
[INFO] 09:24:56.615 Load metrics repository
[INFO] 09:24:56.654 Load metrics repository (done) | time=39ms
[INFO] 09:24:56.686 Delphi Project Helper creation!!!
[INFO] 09:24:56.687 No exclude directories found in project configuration.
[INFO] 09:24:56.688 Delphi sensor DelphiSensor...
[INFO] 09:24:56.693 Delphi Project Helper creation!!!
[INFO] 09:24:56.693 No exclude directories found in project configuration.
[INFO] 09:24:57.361 Delphi sensor describe...
[INFO] 09:24:57.363 SurefireSensor sensor describe...
[INFO] 09:24:57.364 PMD sensor.describe
[INFO] 09:24:57.376 Delphi sensor describe...
[INFO] 09:24:57.376 SurefireSensor sensor describe...
[INFO] 09:24:57.376 PMD sensor.describe
[INFO] 09:24:57.377 Sensor JavaSensor [java]
[INFO] 09:24:57.385 Configured Java source version (sonar.java.source): 8, preview features enabled (sonar.java.enablePreview): false
[INFO] 09:24:57.426 Server-side caching is enabled. The Java analyzer will not try to leverage data from a previous analysis.
[INFO] 09:24:57.428 Using ECJ batch to parse 707 Main java source files with batch size 500 KB.
[INFO] 09:24:57.848 Starting batch processing.
[INFO] 09:24:58.578 The Java analyzer cannot skip unchanged files in this context. A full analysis is performed for all files.
[INFO] 09:25:09.408 100% analyzed
[INFO] 09:25:09.408 Batch processing: Done.
[INFO] 09:25:09.409 Did not optimize analysis for any files, performed a full analysis for all 707 files.
[INFO] 09:25:09.411 No "Test" source files to scan.
[INFO] 09:25:09.411 No "Generated" source files to scan.
[INFO] 09:25:09.411 Sensor JavaSensor [java] (done) | time=12034ms
[INFO] 09:25:09.411 Sensor JaCoCo XML Report Importer [jacoco]
[INFO] 09:25:09.417 Importing 1 report(s). Turn your logs in debug mode in order to see the exhaustive list.
[INFO] 09:25:09.584 Sensor JaCoCo XML Report Importer [jacoco] (done) | time=173ms
[INFO] 09:25:09.585 Sensor Java Config Sensor [iac]
[INFO] 09:25:09.615 0 source files to be analyzed
[INFO] 09:25:09.617 0/0 source files have been analyzed
[INFO] 09:25:09.617 Sensor Java Config Sensor [iac] (done) | time=32ms
[INFO] 09:25:09.618 Sensor SurefireSensor [java]
[INFO] 09:25:09.619 parsing [//*********/./target/surefire-reports/tests-report]
[INFO] 09:25:09.761 Sensor SurefireSensor [java] (done) | time=143ms
[INFO] 09:25:09.762 Sensor XML Sensor [xml]
[INFO] 09:25:09.763 1 source file to be analyzed
[INFO] 09:25:09.941 1/1 source file has been analyzed
[INFO] 09:25:09.941 Sensor XML Sensor [xml] (done) | time=180ms
[INFO] 09:25:09.941 Sensor com.github.mc1arke.sonarqube.plugin.scanner.ScannerPullRequestPropertySensor
[INFO] 09:25:09.942 Sensor com.github.mc1arke.sonarqube.plugin.scanner.ScannerPullRequestPropertySensor (done) | time=1ms
[INFO] 09:25:09.943 Sensor IaC Docker Sensor [iac]
[INFO] 09:25:10.025 0 source files to be analyzed
[INFO] 09:25:10.025 0/0 source files have been analyzed
[INFO] 09:25:10.026 Sensor IaC Docker Sensor [iac] (done) | time=83ms
[INFO] 09:25:10.026 Sensor TextAndSecretsSensor [text]
[INFO] 09:25:10.026 Available processors: 16
[INFO] 09:25:10.026 Using 16 threads for analysis.
[INFO] 09:25:10.411 Using git CLI to retrieve untracked files
[INFO] 09:25:10.804 Analyzing language associated files and files included via "sonar.text.inclusions" that are tracked by git
[INFO] 09:25:10.897 708 source files to be analyzed
[INFO] 09:25:11.123 708/708 source files have been analyzed
[INFO] 09:25:11.125 Sensor TextAndSecretsSensor [text] (done) | time=1099ms
[INFO] 09:25:11.129 ------------- Run sensors on project
[INFO] 09:25:11.324 Sensor Zero Coverage Sensor
[INFO] 09:25:11.326 Sensor Zero Coverage Sensor (done) | time=2ms
[INFO] 09:25:11.326 Sensor Java CPD Block Indexer
[INFO] 09:25:11.545 Sensor Java CPD Block Indexer (done) | time=219ms
[INFO] 09:25:11.582 SCM Publisher SCM provider for this project is: git
[INFO] 09:25:11.584 SCM Publisher 1 source file to be analyzed
[INFO] 09:25:12.504 SCM Publisher 1/1 source file have been analyzed (done) | time=919ms
[INFO] 09:25:12.527 CPD Executor 202 files had no CPD blocks
[INFO] 09:25:12.527 CPD Executor Calculating CPD for 505 files
[INFO] 09:25:12.601 CPD Executor CPD calculation finished (done) | time=74ms
[INFO] 09:25:12.609 SCM revision ID '************'
[INFO] 09:25:12.809 Load New Code definition
[INFO] 09:25:12.865 Load New Code definition (done) | time=56ms
[INFO] 09:25:12.921 Analysis report generated in 263ms, dir size=3.2 MB
[INFO] 09:25:13.559 Analysis report compressed in 637ms, zip size=1.9 MB
[INFO] 09:25:13.864 Analysis report uploaded in 305ms
[INFO] 09:25:13.867 ------------- Check Quality Gate status
[INFO] 09:25:13.867 Waiting for the analysis report to be processed (max 4000s)
[INFO] 09:33:43.093 QUALITY GATE STATUS: PASSED - View details on https://sonarqube./*********/.
I am missing something for sure, but I just would like to understand.