Sonar-scanner java:S1176 fails on Java 17 record classes

Versions

sonarsource/sonar-scanner-cli:4.7.0 (Docker Image)
INFO: SonarScanner 4.7.0.2747
INFO: Java 11.0.15 Alpine (64-bit)
INFO: Linux 5.10.109+ amd64
INFO: Analyzing on SonarQube server 8.9.9

Description

Analysis shows errors when running on files containing Java 17 record classes, such as

public record SomeDto(int someValue) {
}

The full error reads:

ERROR: Unable to run check class org.sonar.java.checks.UndocumentedApiCheck - S1176 on file '<redacted>/SomeDto.java', To help improve the SonarSource Java Analyzer, please report this problem to SonarSource: see https://community.sonarsource.com/
java.util.NoSuchElementException: null
	at java.base/java.util.LinkedList.removeFirst(LinkedList.java:274)
	at java.base/java.util.LinkedList.pop(LinkedList.java:805)
	at org.sonar.java.checks.UndocumentedApiCheck.visitClass(UndocumentedApiCheck.java:110)
	at org.sonar.java.model.declaration.ClassTreeImpl.accept(ClassTreeImpl.java:220)
	at org.sonar.plugins.java.api.tree.BaseTreeVisitor.scan(BaseTreeVisitor.java:40)
	at org.sonar.plugins.java.api.tree.BaseTreeVisitor.scan(BaseTreeVisitor.java:34)
	at org.sonar.plugins.java.api.tree.BaseTreeVisitor.visitCompilationUnit(BaseTreeVisitor.java:52)
	at org.sonar.java.checks.UndocumentedApiCheck.visitCompilationUnit(UndocumentedApiCheck.java:97)
	at org.sonar.java.model.JavaTree$CompilationUnitTreeImpl.accept(JavaTree.java:185)
	at org.sonar.plugins.java.api.tree.BaseTreeVisitor.scan(BaseTreeVisitor.java:40)
	at org.sonar.java.checks.UndocumentedApiCheck.scanFile(UndocumentedApiCheck.java:91)
	at org.sonar.java.model.VisitorsBridge.lambda$runScanner$0(VisitorsBridge.java:154)
	at org.sonar.java.model.VisitorsBridge.runScanner(VisitorsBridge.java:159)
	at org.sonar.java.model.VisitorsBridge.runScanner(VisitorsBridge.java:154)
	at org.sonar.java.model.VisitorsBridge.visitFile(VisitorsBridge.java:128)
	at org.sonar.java.ast.JavaAstScanner.simpleScan(JavaAstScanner.java:127)
	at org.sonar.java.ast.JavaAstScanner.scan(JavaAstScanner.java:79)
	at org.sonar.java.JavaSquid.scanSources(JavaSquid.java:130)
	at org.sonar.java.JavaSquid.scan(JavaSquid.java:116)
	at org.sonar.plugins.java.JavaSquidSensor.execute(JavaSquidSensor.java:105)
	at org.sonar.scanner.sensor.AbstractSensorWrapper.analyse(AbstractSensorWrapper.java:48)
	at org.sonar.scanner.sensor.ModuleSensorsExecutor.execute(ModuleSensorsExecutor.java:85)
	at org.sonar.scanner.sensor.ModuleSensorsExecutor.lambda$execute$1(ModuleSensorsExecutor.java:59)
	at org.sonar.scanner.sensor.ModuleSensorsExecutor.withModuleStrategy(ModuleSensorsExecutor.java:77)
	at org.sonar.scanner.sensor.ModuleSensorsExecutor.execute(ModuleSensorsExecutor.java:59)
	at org.sonar.scanner.scan.ModuleScanContainer.doAfterStart(ModuleScanContainer.java:82)
	at org.sonar.core.platform.ComponentContainer.startComponents(ComponentContainer.java:137)
	at org.sonar.core.platform.ComponentContainer.execute(ComponentContainer.java:123)
	at org.sonar.scanner.scan.ProjectScanContainer.scan(ProjectScanContainer.java:392)
	at org.sonar.scanner.scan.ProjectScanContainer.scanRecursively(ProjectScanContainer.java:388)
	at org.sonar.scanner.scan.ProjectScanContainer.doAfterStart(ProjectScanContainer.java:357)
	at org.sonar.core.platform.ComponentContainer.startComponents(ComponentContainer.java:137)
	at org.sonar.core.platform.ComponentContainer.execute(ComponentContainer.java:123)
	at org.sonar.scanner.bootstrap.GlobalContainer.doAfterStart(GlobalContainer.java:150)
	at org.sonar.core.platform.ComponentContainer.startComponents(ComponentContainer.java:137)
	at org.sonar.core.platform.ComponentContainer.execute(ComponentContainer.java:123)
	at org.sonar.batch.bootstrapper.Batch.doExecute(Batch.java:72)
	at org.sonar.batch.bootstrapper.Batch.execute(Batch.java:66)
	at org.sonarsource.scanner.api.internal.batch.BatchIsolatedLauncher.execute(BatchIsolatedLauncher.java:46)
	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
	at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.base/java.lang.reflect.Method.invoke(Method.java:566)
	at org.sonarsource.scanner.api.internal.IsolatedLauncherProxy.invoke(IsolatedLauncherProxy.java:60)
	at com.sun.proxy.$Proxy0.execute(Unknown Source)
	at org.sonarsource.scanner.api.EmbeddedScanner.doExecute(EmbeddedScanner.java:189)
	at org.sonarsource.scanner.api.EmbeddedScanner.execute(EmbeddedScanner.java:138)
	at org.sonarsource.scanner.cli.Main.execute(Main.java:112)
	at org.sonarsource.scanner.cli.Main.execute(Main.java:75)
	at org.sonarsource.scanner.cli.Main.main(Main.java:61)

Yes, I’m using a SonarServer which is quite outdated, but I’d expect that the newest scanner does not fail.

Hey there.

Java 16/17 is not supported with SonarQube v8.9 LTS – only with the latest versions of SonarQube (today, that’s v9.6). In these versions, this bug has been addressed. The scanner version here is irrelevant (it just pulls the analysis engine from your SonarQube server).

You might find it useful to create a new Quality Profile for Java 17 that doesn’t include this rule, if you cannot upgrade. Or if this only affects one file, exclude the file from analysis.