Cannot use lambda expressions when running in JDK inferior to 1.8 mode!

Hello

SonarQube 7.9.1

I am receiving the following error but I am unsure why. I have Java 11 running on the SonarQube server and Java 10 on the build server where the scan is running.
The INFO line below show Java version 1.6. Where is this info coming from? Is this the reason why the error is occuring?

**14:10:45** 14:10:46.429 INFO: Sensor JavaSquidSensor [java] (done) | time=6159ms 
**14:10:45** 14:10:46.429 INFO: Sensor PmdSensor [pmd] 
**14:10:45** 14:10:46.443 INFO: Execute PMD 6.10.0 
**14:10:46
** 14:10:46.764 INFO: Java version: 1.6
**14:10:46
** 14:10:47.185 INFO: PMD configuration: /home/****/jenkins/workspace/NMS.email-delivery-service.PR-OPENED.BUILD/.scannerwork/pmd.xml
**14:10:48
** 14:10:49.111 ERROR: Fail to execute PMD. Following file is ignored: dist/build/rpmbuild/BUILD/email-delivery-service-1.1.1/service/src/main/java/com/intralinks/eds/actors/DataStoreActor.java **14:10:48** net.sourceforge.pmd.PMDException: Error while parsing file:///home/****/jenkins/workspace/NMS.email-delivery-service.PR-OPENED.BUILD/dist/build/rpmbuild/BUILD/email-delivery-service-1.1.1/service/src/main/java/com/intralinks/eds/actors/DataStoreActor.java 
**14:10:48** at net.sourceforge.pmd.SourceCodeProcessor.processSourceCode(SourceCodeProcessor.java:99) **14:10:48** at net.sourceforge.pmd.SourceCodeProcessor.processSourceCode(SourceCodeProcessor.java:51) **14:10:48** at org.sonar.plugins.pmd.PmdTemplate.process(PmdTemplate.java:101) 
**14:10:48** at org.sonar.plugins.pmd.PmdExecutor.executeRules(PmdExecutor.java:131) 
**14:10:48** at org.sonar.plugins.pmd.PmdExecutor.executePmd(PmdExecutor.java:98) 
**14:10:48** at org.sonar.plugins.pmd.PmdExecutor.execute(PmdExecutor.java:80) 
**14:10:48** at org.sonar.plugins.pmd.PmdSensor.execute(PmdSensor.java:71) 
**14:10:48** at org.sonar.scanner.sensor.AbstractSensorWrapper.analyse(AbstractSensorWrapper.java:48) **14:10:48** at org.sonar.scanner.sensor.ModuleSensorsExecutor.execute(ModuleSensorsExecutor.java:85) **14:10:48** at org.sonar.scanner.sensor.ModuleSensorsExecutor.lambda$execute$1(ModuleSensorsExecutor.java:59) 
**14:10:48** at org.sonar.scanner.sensor.ModuleSensorsExecutor.withModuleStrategy(ModuleSensorsExecutor.java:77) 
**14:10:48** at org.sonar.scanner.sensor.ModuleSensorsExecutor.execute(ModuleSensorsExecutor.java:59) **14:10:48** at org.sonar.scanner.scan.ModuleScanContainer.doAfterStart(ModuleScanContainer.java:82) **14:10:48** at org.sonar.core.platform.ComponentContainer.startComponents(ComponentContainer.java:136) **14:10:48** at org.sonar.core.platform.ComponentContainer.execute(ComponentContainer.java:122) **14:10:48** at org.sonar.scanner.scan.ProjectScanContainer.scan(ProjectScanContainer.java:400) **14:10:48** at org.sonar.scanner.scan.ProjectScanContainer.scanRecursively(ProjectScanContainer.java:395) **14:10:48** at org.sonar.scanner.scan.ProjectScanContainer.doAfterStart(ProjectScanContainer.java:358) **14:10:48** at org.sonar.core.platform.ComponentContainer.startComponents(ComponentContainer.java:136) **14:10:48** at org.sonar.core.platform.ComponentContainer.execute(ComponentContainer.java:122) **14:10:48** at org.sonar.scanner.bootstrap.GlobalContainer.doAfterStart(GlobalContainer.java:141) **14:10:48** at org.sonar.core.platform.ComponentContainer.startComponents(ComponentContainer.java:136) **14:10:48** at org.sonar.core.platform.ComponentContainer.execute(ComponentContainer.java:122) **14:10:48** at org.sonar.batch.bootstrapper.Batch.doExecute(Batch.java:73) 
**14:10:48** at org.sonar.batch.bootstrapper.Batch.execute(Batch.java:67) *
*14:10:48** at org.sonarsource.scanner.api.internal.batch.BatchIsolatedLauncher.execute(BatchIsolatedLauncher.java:46) 
**14:10:48** at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method) **14:10:48** at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) **14:10:48** at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) 
**14:10:48** at java.base/java.lang.reflect.Method.invoke(Method.java:564) 
**14:10:48** at org.sonarsource.scanner.api.internal.IsolatedLauncherProxy.invoke(IsolatedLauncherProxy.java:60) **14:10:48** at com.sun.proxy.$Proxy0.execute(Unknown Source) 
**14:10:48** at org.sonarsource.scanner.api.EmbeddedScanner.doExecute(EmbeddedScanner.java:185) 
**14:10:48** at org.sonarsource.scanner.api.EmbeddedScanner.execute(EmbeddedScanner.java:137) **14:10:48** at org.sonarsource.scanner.cli.Main.execute(Main.java:112) 
**14:10:48** at org.sonarsource.scanner.cli.Main.execute(Main.java:75) 
**14:10:48** at org.sonarsource.scanner.cli.Main.main(Main.java:61) 
**14:10:48** Caused by: net.sourceforge.pmd.lang.java.ast.ParseException: Line 18, Column 55: Cannot use lambda expressions when running in JDK inferior to 1.8 mode!

Hi,

According to the docs and Jira the latest version of SonarScanner for Maven is 3.6.0. If you’ve pinned a specific scanner version in your pom, you should remove it and try again.

Edit: The above is the answer to a different thread :woman_facepalming:

Try executing java -version on the command line. That will give you your default Java version. Another possible source is having a $JAVA_HOME set in the user session that’s running analysis

 
Ann

Hi Ann

Below is the output from java -version and JAVA_HOME setting. Both show version 10.

10:43:53 + java -version
10:43:53 java version “10.0.1” 2018-04-17
10:43:53 Java™ SE Runtime Environment 18.3 (build 10.0.1+10)
10:43:53 Java HotSpot™ 64-Bit Server VM 18.3 (build 10.0.1+10, mixed mode)
10:43:53 + env
10:43:53 + grep HOME
10:43:53 JAVA_HOME=/usr/java/latest

$ ll
total 12
lrwxrwxrwx. 1 root root 16 Jul 18 2017 default -> /usr/java/latest
drwxr-xr-x. 9 root root 4096 May 29 10:13 jdk-10.0.1
drwxr-xr-x. 8 root root 4096 Sep 26 2017 jdk1.7.0_80
drwxr-xr-x. 9 root root 4096 Jul 18 2017 jdk1.8.0_77
lrwxrwxrwx. 1 root root 20 May 29 10:13 latest -> /usr/java/jdk-10.0.1

Hi,

Your analysis log snipped doesn’t indicate your analysis mode (Maven? Gradle? …) but you should check those settings too.

I’m probably not going to be able to help you much further in pinning down the source of your misconfiguration, but I do wonder if you still really need Java 6. By deleting (or renaming) that version it might make it clearer where the reference to it is coming from.

 
Ann

I am using the SonarQube plugin for Jenkins for scans.

10:43:53 [NMS.email-delivery-service.PR-OPENED.BUILD] $ /home//jenkins/tools/hudson.plugins.sonar.SonarRunnerInstallation/IL_Sonarqube/bin/sonar-scanner -Dsonar.host.url=http://sonarqube.intralinks.com -Dproject.settings=/home//jenkins/workspace/NMS.email-delivery-service.PR-OPENED.BUILD/sonar-project.properties -Dsonar.projectName=email-delivery-service -Dsonar.projectVersion=1.1.1 -Dsonar.projectKey=email-delivery-service -Dsonar..exclusions.disabled=true -Dsonar.projectBaseDir=/home//jenkins/workspace/NMS.email-delivery-service.PR-OPENED.BUILD
10:43:54 INFO: Scanner configuration file: /home//jenkins/tools/hudson.plugins.sonar.SonarRunnerInstallation/IL_Sonarqube/conf/sonar-scanner.properties 10:43:54 INFO: Project root configuration file: /home//jenkins/workspace/NMS.email-delivery-service.PR-OPENED.BUILD/sonar-project.properties
10:43:54 INFO: SonarQube Scanner 4.0.0.1744
10:43:54 INFO: Java 10.0.1 Oracle Corporation (64-bit)
10:43:54 INFO: Linux 3.10.0-693.2.1.el7.x86_64 amd64
10:43:54 INFO: User cache: /home//.sonar/cache
10:43:54 INFO: SonarQube server 7.9.1
10:43:54 INFO: Default locale: “en_US”, source code encoding: “UTF-8” (analysis is platform dependent) *
10:43:54* WARN: SonarScanner will require Java 11+ to run starting in SonarQube 8.x
10:43:54 INFO: Load global settings
10:43:55 INFO: Load global settings (done) | time=98ms
10:43:55 INFO: Server id: 86E1FA4D-AV2AE0BOUz4RUnWGt_6T
10:43:55 INFO: User cache: /home/
/.sonar/cache
10:43:55 INFO: Load/download plugins
10:43:55 INFO: Load plugins index
10:43:55 INFO: Load plugins index (done) | time=122ms
10:43:55 INFO: Load/download plugins (done) | time=359ms
10:43:55 INFO: Loaded core extensions: developer-scanner
10:43:56 INFO: Process project properties
10:43:56 INFO: Execute project builders
10:43:56 INFO: Execute project builders (done) | time=7ms
10:43:56 INFO: Project key: email-delivery-service
10:43:56 INFO: Base dir: /home//jenkins/workspace/NMS.email-delivery-service.PR-OPENED.BUILD
10:43:56 INFO: Working dir: /home/
/jenkins/workspace/NMS.email-delivery-service.PR-OPENED.BUILD/.scannerwork
10:43:56 INFO: Load project settings for component key: ‘email-delivery-service’
10:43:56 INFO: Load project settings for component key: ‘email-delivery-service’ (done) | time=38ms
10:43:56 INFO: Load project branches
10:43:56 INFO: Load project branches (done) | time=33ms
10:43:56 INFO: Load project pull requests
10:43:56 INFO: Load project pull requests (done) | time=19ms
10:43:56 INFO: Load branch configuration
10:43:56 INFO: Load branch configuration (done) | time=3ms
10:43:56 INFO: Load quality profiles
10:43:56 INFO: Load quality profiles (done) | time=81ms
10:43:56 INFO: Detected Jenkins
10:43:56 INFO: Load active rules
10:43:57 INFO: Load active rules (done) | time=1255ms
10:43:57 INFO: Exclusions based on SCM info is disabled by configuration
10:43:57 INFO: Branch name: feature/SCM-19414-cannot-use-lambda-expressions-when-running-in-jdk-inferior-to-1.8-mode, type: short living
10:43:57 INFO: SCM collecting changed files in the branch
10:43:58 INFO: SCM collecting changed files in the branch (done) | time=150ms
10:43:58 INFO: Indexing files…
10:43:58 INFO: Project configuration:
10:43:58 INFO: Included sources: dist/build/rpmbuild/BUILD/email-delivery-service-1.1.1/service/src/main/java/**/*
10:43:58 INFO: 12 files indexed
10:43:58 INFO: 0 files ignored because of inclusion/exclusion patterns
10:43:58 INFO: Quality profile for java: 2019 Security
10:43:58 INFO: ------------- Run sensors on module email-delivery-service
10:43:58 INFO: Load metrics repository
10:43:58 INFO: Load metrics repository (done) | time=25ms
10:43:59 WARNING: An illegal reflective access operation has occurred
10:43:59 WARNING: Illegal reflective access by net.sf.cglib.core.ReflectUtils$1 (file:/home//.sonar/cache/a89f1943fc75b65becd9fb4ecab8d913/sonar-tsql-plugin.jar) to method java.lang.ClassLoader.defineClass(java.lang.String,byte[],int,int,java.security.ProtectionDomain) 10:43:59 WARNING: Please consider reporting this to the maintainers of net.sf.cglib.core.ReflectUtils$1
10:43:59 WARNING: Use --illegal-access=warn to enable warnings of further illegal reflective access operations
10:43:59 WARNING: All illegal access operations will be denied in a future release
10:44:01 INFO: Sensor JavaSquidSensor [java]
10:44:01 INFO: Configured Java source version (sonar.java.source): none
10:44:01 INFO: JavaClasspath initialization
10:44:01 WARN: Bytecode of dependencies was not provided for analysis of source files, you might end up with less precise results. Bytecode can be provided using sonar.java.libraries property. 10:44:01 INFO: JavaClasspath initialization (done) | time=33ms
10:44:01 INFO: JavaTestClasspath initialization
10:44:01 INFO: JavaTestClasspath initialization (done) | time=0ms
10:44:01 INFO: Java Main Files AST scan
10:44:01 INFO: 12 source files to be analyzed
10:44:05 INFO: Java Main Files AST scan (done) | time=3112ms
10:44:05 INFO: Java Test Files AST scan
10:44:05 INFO: 0 source files to be analyzed
10:44:05 INFO: Java Test Files AST scan (done) | time=1ms
10:44:05 INFO: Sensor JavaSquidSensor [java] (done) | time=3764ms
10:44:05 INFO: Sensor PmdSensor [pmd]
10:44:05 INFO: 12/12 source files have been analyzed
10:44:05 INFO: 0/0 source files have been analyzed
10:44:05 INFO: Execute PMD 6.10.0
10:44:05 INFO: Java version: 1.6
10:44:05 INFO: PMD configuration: /home/
/jenkins/workspace/NMS.email-delivery-service.PR-OPENED.BUILD/.scannerwork/pmd.xml
10:44:06 ERROR: Fail to execute PMD. Following file is ignored: dist/build/rpmbuild/BUILD/email-delivery-service-1.1.1/service/src/main/java/com/intralinks/eds/actors/DataStoreActor.java
10:44:06 net.sourceforge.pmd.PMDException: Error while parsing file:///home/****/jenkins/workspace/NMS.email-delivery-service.PR-OPENED.BUILD/dist/build/rpmbuild/BUILD/email-delivery-service-1.1.1/service/src/main/java/com/intralinks/eds/actors/DataStoreActor.java
10:44:06 at net.sourceforge.pmd.SourceCodeProcessor.processSourceCode(SourceCodeProcessor.java:99) 10:44:06 at net.sourceforge.pmd.SourceCodeProcessor.processSourceCode(SourceCodeProcessor.java:51) 10:44:06 at org.sonar.plugins.pmd.PmdTemplate.process(PmdTemplate.java:101)
10:44:06 at org.sonar.plugins.pmd.PmdExecutor.executeRules(PmdExecutor.java:131)
10:44:06 at org.sonar.plugins.pmd.PmdExecutor.executePmd(PmdExecutor.java:98)
10:44:06 at org.sonar.plugins.pmd.PmdExecutor.execute(PmdExecutor.java:80)
10:44:06 at org.sonar.plugins.pmd.PmdSensor.execute(PmdSensor.java:71)
10:44:06 at org.sonar.scanner.sensor.AbstractSensorWrapper.analyse(AbstractSensorWrapper.java:48)
10:44:06 at org.sonar.scanner.sensor.ModuleSensorsExecutor.execute(ModuleSensorsExecutor.java:85)
10:44:06 at org.sonar.scanner.sensor.ModuleSensorsExecutor.lambda$execute$1(ModuleSensorsExecutor.java:59)
10:44:06 at org.sonar.scanner.sensor.ModuleSensorsExecutor.withModuleStrategy(ModuleSensorsExecutor.java:77)
10:44:06 at org.sonar.scanner.sensor.ModuleSensorsExecutor.execute(ModuleSensorsExecutor.java:59)
10:44:06 at org.sonar.scanner.scan.ModuleScanContainer.doAfterStart(ModuleScanContainer.java:82)
10:44:06 at org.sonar.core.platform.ComponentContainer.startComponents(ComponentContainer.java:136)
10:44:06 at org.sonar.core.platform.ComponentContainer.execute(ComponentContainer.java:122)
10:44:06 at org.sonar.scanner.scan.ProjectScanContainer.scan(ProjectScanContainer.java:400)
10:44:06 at org.sonar.scanner.scan.ProjectScanContainer.scanRecursively(ProjectScanContainer.java:395)
10:44:06 at org.sonar.scanner.scan.ProjectScanContainer.doAfterStart(ProjectScanContainer.java:358)
10:44:06 at org.sonar.core.platform.ComponentContainer.startComponents(ComponentContainer.java:136)
10:44:06 at org.sonar.core.platform.ComponentContainer.execute(ComponentContainer.java:122)
10:44:06 at org.sonar.scanner.bootstrap.GlobalContainer.doAfterStart(GlobalContainer.java:141)
10:44:06 at org.sonar.core.platform.ComponentContainer.startComponents(ComponentContainer.java:136)
10:44:06 at org.sonar.core.platform.ComponentContainer.execute(ComponentContainer.java:122)
10:44:06 at org.sonar.batch.bootstrapper.Batch.doExecute(Batch.java:73)
10:44:06 at org.sonar.batch.bootstrapper.Batch.execute(Batch.java:67)
10:44:06 at org.sonarsource.scanner.api.internal.batch.BatchIsolatedLauncher.execute(BatchIsolatedLauncher.java:46)
10:44:06 at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
10:44:06 at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
10:44:06 at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
10:44:06 at java.base/java.lang.reflect.Method.invoke(Method.java:564)
10:44:06 at org.sonarsource.scanner.api.internal.IsolatedLauncherProxy.invoke(IsolatedLauncherProxy.java:60)
10:44:06 at com.sun.proxy.$Proxy0.execute(Unknown Source)
10:44:06 at org.sonarsource.scanner.api.EmbeddedScanner.doExecute(EmbeddedScanner.java:185)
10:44:06 at org.sonarsource.scanner.api.EmbeddedScanner.execute(EmbeddedScanner.java:137) 10:44:06 at org.sonarsource.scanner.cli.Main.execute(Main.java:112)
10:44:06 at org.sonarsource.scanner.cli.Main.execute(Main.java:75)
10:44:06 at org.sonarsource.scanner.cli.Main.main(Main.java:61)
10:44:06 Caused by: net.sourceforge.pmd.lang.java.ast.ParseException: Line 18, Column 55: Cannot use lambda expressions when running in JDK inferior to 1.8 mode!

Hi,

It’s interesting that you appear to have set your Jenkins job to use vanilla SonarScanner analysis. If you’re using Maven or Gradle to build, you probably want to look at using them to analyze as well. And then you just have to figure out which Java Maven or Gradle is using.

As I said, I’m probably not going to be able to help you track down where/how you’re configured to use Java 6 for analysis. But I can point out that it appears that the PMD plugin is the one erroring out analysis, so failing all else, you could uninstall it.

 
Ann

I just ran into this as well. The answer is that PMD is incorrectly assuming you’re using JDK 6. The following lines are in your log file:

17:51:18 [exec] [sonar:sonar] Execute PMD 6.10.0
17:51:18 [exec] [sonar:sonar] Java version: 1.6

Apparently you can use the sonar.java.source value to get PMD to use the correct version:

I added this as a property:
sonar.java.source=1.8

At which point you should see the following logged:

19:29:42 [exec] [sonar:sonar] Execute PMD 6.10.0
19:29:42 [exec] [sonar:sonar] Java version: 1.8

1 Like

Thanks Sam, that cleared the error.