Unable to run check class org.sonar.java.se.SymbolicExecutionVisitor / java.lang.NumberFormatException

[INFO] --- sonar-maven-plugin:3.6.0.1398:sonar (default-cli) @ pst-exp ---
[INFO] User cache: /home/travis/.sonar/cache
[INFO] SonarQube version: 7.8.0

...

[ERROR] Unable to run check class org.sonar.java.se.SymbolicExecutionVisitor -  on file 'src/main/java/org/pipoware/pst/exp/HID.java', To help improve SonarJava, please report this problem to SonarSource : see https://www.sonarqube.org/community/
java.lang.NumberFormatException: For input string: "11111111111111110000000000000000"
	at java.lang.NumberFormatException.forInputString(NumberFormatException.java:65)
	at java.lang.Integer.parseInt(Integer.java:583)
	at java.lang.Integer.valueOf(Integer.java:740)
	at org.sonar.java.model.LiteralUtils.intLiteralValue(LiteralUtils.java:54)
	at org.sonar.java.model.LiteralUtils.intLiteralValue(LiteralUtils.java:40)
	at org.sonar.java.se.checks.MinMaxRangeCheck.checkPostStatement(MinMaxRangeCheck.java:145)

Seems to be a problem to parse this statement

  hidBlockIndex = (hid & 0b11111111111111110000000000000000) >>> 16;

Full stack:
https://travis-ci.org/farnulfo/pst-exp/builds/538060524#L3399

`[ERROR] Unable to run check class org.sonar.java.se.SymbolicExecutionVisitor -  on file 'src/main/java/org/pipoware/pst/exp/HID.java', To help improve SonarJava, please report this problem to SonarSource : see https://www.sonarqube.org/community/
java.lang.NumberFormatException: For input string: "11111111111111110000000000000000"
	at java.lang.NumberFormatException.forInputString(NumberFormatException.java:65)
	at java.lang.Integer.parseInt(Integer.java:583)
	at java.lang.Integer.valueOf(Integer.java:740)
	at org.sonar.java.model.LiteralUtils.intLiteralValue(LiteralUtils.java:54)
	at org.sonar.java.model.LiteralUtils.intLiteralValue(LiteralUtils.java:40)
	at org.sonar.java.se.checks.MinMaxRangeCheck.checkPostStatement(MinMaxRangeCheck.java:145)
	at org.sonar.java.se.CheckerDispatcher.executePost(CheckerDispatcher.java:106)
	at org.sonar.java.se.CheckerDispatcher.addTransition(CheckerDispatcher.java:97)
	at org.sonar.java.se.CheckerDispatcher.executePost(CheckerDispatcher.java:118)
	at org.sonar.java.se.CheckerDispatcher.addTransition(CheckerDispatcher.java:97)
	at org.sonar.java.se.CheckerDispatcher.executePost(CheckerDispatcher.java:118)
	at org.sonar.java.se.CheckerDispatcher.addTransition(CheckerDispatcher.java:97)
	at org.sonar.java.se.CheckerDispatcher.executePost(CheckerDispatcher.java:118)
	at org.sonar.java.se.CheckerDispatcher.addTransition(CheckerDispatcher.java:97)
	at org.sonar.java.se.CheckerDispatcher.executePost(CheckerDispatcher.java:118)
	at org.sonar.java.se.CheckerDispatcher.addTransition(CheckerDispatcher.java:97)
	at org.sonar.java.se.CheckerDispatcher.executePost(CheckerDispatcher.java:118)
	at org.sonar.java.se.CheckerDispatcher.addTransition(CheckerDispatcher.java:97)
	at org.sonar.java.se.CheckerDispatcher.executePost(CheckerDispatcher.java:118)
	at org.sonar.java.se.CheckerDispatcher.addTransition(CheckerDispatcher.java:97)
	at org.sonar.java.se.CheckerDispatcher.executePost(CheckerDispatcher.java:118)
	at org.sonar.java.se.CheckerDispatcher.addTransition(CheckerDispatcher.java:97)
	at org.sonar.java.se.CheckerDispatcher.executePost(CheckerDispatcher.java:118)
	at org.sonar.java.se.CheckerDispatcher.addTransition(CheckerDispatcher.java:97)
	at org.sonar.java.se.CheckerDispatcher.executePost(CheckerDispatcher.java:118)
	at org.sonar.java.se.CheckerDispatcher.addTransition(CheckerDispatcher.java:97)
	at org.sonar.java.se.CheckerDispatcher.executePost(CheckerDispatcher.java:118)
	at org.sonar.java.se.CheckerDispatcher.addTransition(CheckerDispatcher.java:97)
	at org.sonar.java.se.CheckerDispatcher.executePost(CheckerDispatcher.java:118)
	at org.sonar.java.se.CheckerDispatcher.addTransition(CheckerDispatcher.java:97)
	at org.sonar.java.se.checks.NullDereferenceCheck.checkPostStatement(NullDereferenceCheck.java:210)
	at org.sonar.java.se.CheckerDispatcher.executePost(CheckerDispatcher.java:106)
	at org.sonar.java.se.CheckerDispatcher.addTransition(CheckerDispatcher.java:97)
	at org.sonar.java.se.CheckerDispatcher.executeCheckPostStatement(CheckerDispatcher.java:69)
	at org.sonar.java.se.ExplodedGraphWalker.visit(ExplodedGraphWalker.java:642)
	at org.sonar.java.se.ExplodedGraphWalker.execute(ExplodedGraphWalker.java:249)
	at org.sonar.java.se.ExplodedGraphWalker.visitMethod(ExplodedGraphWalker.java:209)
	at org.sonar.java.se.ExplodedGraphWalker.visitMethod(ExplodedGraphWalker.java:201)
	at org.sonar.java.se.SymbolicExecutionVisitor.execute(SymbolicExecutionVisitor.java:78)
	at org.sonar.java.se.SymbolicExecutionVisitor.visitNode(SymbolicExecutionVisitor.java:64)
	at org.sonar.java.ast.visitors.SubscriptionVisitor.visit(SubscriptionVisitor.java:103)
	at org.sonar.java.ast.visitors.SubscriptionVisitor.visitChildren(SubscriptionVisitor.java:128)
	at org.sonar.java.ast.visitors.SubscriptionVisitor.visit(SubscriptionVisitor.java:105)
	at org.sonar.java.ast.visitors.SubscriptionVisitor.visitChildren(SubscriptionVisitor.java:128)
	at org.sonar.java.ast.visitors.SubscriptionVisitor.visit(SubscriptionVisitor.java:105)
	at org.sonar.java.ast.visitors.SubscriptionVisitor.scanTree(SubscriptionVisitor.java:86)
	at org.sonar.java.ast.visitors.SubscriptionVisitor.scanFile(SubscriptionVisitor.java:72)
	at org.sonar.java.se.SymbolicExecutionVisitor.scanFile(SymbolicExecutionVisitor.java:54)
	at org.sonar.java.model.VisitorsBridge.runScanner(VisitorsBridge.java:149)
	at org.sonar.java.model.VisitorsBridge.visitFile(VisitorsBridge.java:137)
	at org.sonar.java.ast.JavaAstScanner.simpleScan(JavaAstScanner.java:90)
	at org.sonar.java.ast.JavaAstScanner.scan(JavaAstScanner.java:67)
	at org.sonar.java.JavaSquid.scanSources(JavaSquid.java:114)
	at org.sonar.java.JavaSquid.scan(JavaSquid.java:108)
	at org.sonar.plugins.java.JavaSquidSensor.execute(JavaSquidSensor.java:88)
	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:136)
	at org.sonar.core.platform.ComponentContainer.execute(ComponentContainer.java:122)
	at org.sonar.scanner.scan.ProjectScanContainer.scan(ProjectScanContainer.java:360)
	at org.sonar.scanner.scan.ProjectScanContainer.scanRecursively(ProjectScanContainer.java:355)
	at org.sonar.scanner.scan.ProjectScanContainer.doAfterStart(ProjectScanContainer.java:318)
	at org.sonar.core.platform.ComponentContainer.startComponents(ComponentContainer.java:136)
	at org.sonar.core.platform.ComponentContainer.execute(ComponentContainer.java:122)
	at org.sonar.scanner.bootstrap.GlobalContainer.doAfterStart(GlobalContainer.java:142)
	at org.sonar.core.platform.ComponentContainer.startComponents(ComponentContainer.java:136)
	at org.sonar.core.platform.ComponentContainer.execute(ComponentContainer.java:122)
	at org.sonar.batch.bootstrapper.Batch.doExecute(Batch.java:73)
	at org.sonar.batch.bootstrapper.Batch.execute(Batch.java:67)
	at org.sonarsource.scanner.api.internal.batch.BatchIsolatedLauncher.execute(BatchIsolatedLauncher.java:46)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.lang.reflect.Method.invoke(Method.java:498)
	at org.sonarsource.scanner.api.internal.IsolatedLauncherProxy.invoke(IsolatedLauncherProxy.java:60)
	at com.sun.proxy.$Proxy23.execute(Unknown Source)
	at org.sonarsource.scanner.api.EmbeddedScanner.doExecute(EmbeddedScanner.java:185)
	at org.sonarsource.scanner.api.EmbeddedScanner.execute(EmbeddedScanner.java:137)
	at org.sonarsource.scanner.maven.bootstrap.ScannerBootstrapper.execute(ScannerBootstrapper.java:65)
	at org.sonarsource.scanner.maven.SonarQubeMojo.execute(SonarQubeMojo.java:104)
	at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo(DefaultBuildPluginManager.java:134)
	at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:208)
	at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:154)
	at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:146)
	at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:117)
	at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:81)
	at org.apache.maven.lifecycle.internal.builder.singlethreaded.SingleThreadedBuilder.build(SingleThreadedBuilder.java:51)
	at org.apache.maven.lifecycle.internal.LifecycleStarter.execute(LifecycleStarter.java:128)
	at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:309)
	at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:194)
	at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:107)
	at org.apache.maven.cli.MavenCli.execute(MavenCli.java:955)
	at org.apache.maven.cli.MavenCli.doMain(MavenCli.java:290)
	at org.apache.maven.cli.MavenCli.main(MavenCli.java:194)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.lang.reflect.Method.invoke(Method.java:498)
	at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced(Launcher.java:289)
	at org.codehaus.plexus.classworlds.launcher.Launcher.launch(Launcher.java:229)
	at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode(Launcher.java:415)
	at org.codehaus.plexus.classworlds.launcher.Launcher.main(Launcher.java:356)
1 Like

After some digging in sonar-java source, may be there is a simple patch:

sonar-java-master\java-frontend\src\main\java\org\sonar\java\model\LiteralUtils.java
Before

      @CheckForNull
      private static Integer intLiteralValue(LiteralTree literal) {
        String literalValue = literal.value().replaceAll("_", "");
        if (literalValue.startsWith("0b") || literalValue.startsWith("0B")) {
          return Integer.valueOf(literalValue.substring(2), 2);
        }
        return Long.decode(literalValue).intValue();
      }

After:

      @CheckForNull
      private static Integer intLiteralValue(LiteralTree literal) {
        String literalValue = literal.value().replaceAll("_", "");
        if (literalValue.startsWith("0b") || literalValue.startsWith("0B")) {
          return Long.valueOf(literalValue.substring(2), 2).intValue();
        }
        return Long.decode(literalValue).intValue();
      }

0b11111111111111110000000000000000 will still be parsed as a INTEGER_LITERAL and we’re loosing precision but no more exception.
Parsing as LONG_LITERAL is harder than it looks…

Need some testing but it’s late :slight_smile:

2 Likes

hello @farnulfo,

thanks for reporting this, I created ticket to track the problem https://jira.sonarsource.com/browse/SONARJAVA-3113

Indeed your solution seems to be quite straightforward.