Uploaded image for project: 'SonarJava'
  1. SonarJava
  2. SONARJAVA-3438

S5122: ClassCastException when annotation is defined with an identifier

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Major
    • Resolution: Fixed
    • Affects Version/s: 6.4
    • Fix Version/s: 6.5
    • Component/s: Rules
    • Labels:

      Description

      Annotations can be initialized with constant from identifier or member select, if it is the case, the rule will throw a ClassCastException.

      final static String STAR = "*";
      @CrossOrigin(MyClass.STAR)
      @CrossOrigin(STAR)
      

      It will result in:

      [ERROR] Unable to run check class org.sonar.java.checks.CORSCheck - S5122 on file XXXXX, To help improve the SonarSource Java Analyzer, please report this problem to SonarSource: see https://community.sonarsource.com/
      java.lang.ClassCastException: class org.sonar.java.model.expression.MemberSelectExpressionTreeImpl cannot be cast to class org.sonar.plugins.java.api.tree.LiteralTree (org.sonar.java.model.expression.MemberSelectExpressionTreeImpl and org.sonar.plugins.java.api.tree.LiteralTree are in unnamed module of loader org.sonar.classloader.ClassRealm @385d819)
              at org.sonar.java.checks.CORSCheck.setSpecificOrigins(CORSCheck.java:120)
              at java.base/java.util.stream.MatchOps$1MatchSink.accept(MatchOps.java:90)
              at java.base/java.util.Spliterators$IteratorSpliterator.tryAdvance(Spliterators.java:1812)
              at java.base/java.util.stream.ReferencePipeline.forEachWithCancel(ReferencePipeline.java:127)
              at java.base/java.util.stream.AbstractPipeline.copyIntoWithCancel(AbstractPipeline.java:502)
              at java.base/java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:488)
              at java.base/java.util.stream.AbstractPipeline.wrapAndCopyInto(AbstractPipeline.java:474)
              at java.base/java.util.stream.MatchOps$MatchOp.evaluateSequential(MatchOps.java:230)
              at java.base/java.util.stream.MatchOps$MatchOp.evaluateSequential(MatchOps.java:196)
              at java.base/java.util.stream.AbstractPipeline.evaluate(AbstractPipeline.java:234)
              at java.base/java.util.stream.ReferencePipeline.noneMatch(ReferencePipeline.java:538)
              at org.sonar.java.checks.CORSCheck.checkAnnotation(CORSCheck.java:107)
              at org.sonar.java.checks.CORSCheck.visitNode(CORSCheck.java:86)
              at org.sonar.java.model.VisitorsBridge$IssuableSubsciptionVisitorsRunner.lambda$visit$6(VisitorsBridge.java:311)
              at org.sonar.java.model.VisitorsBridge$IssuableSubsciptionVisitorsRunner.lambda$forEach$9(VisitorsBridge.java:326)
              at org.sonar.java.model.VisitorsBridge.runScanner(VisitorsBridge.java:189)
              at org.sonar.java.model.VisitorsBridge.access$100(VisitorsBridge.java:66)
              at org.sonar.java.model.VisitorsBridge$IssuableSubsciptionVisitorsRunner.forEach(VisitorsBridge.java:326)
              at org.sonar.java.model.VisitorsBridge$IssuableSubsciptionVisitorsRunner.visit(VisitorsBridge.java:313)
              at org.sonar.java.model.VisitorsBridge$IssuableSubsciptionVisitorsRunner.visitChildren(VisitorsBridge.java:297)
              at org.sonar.java.model.VisitorsBridge$IssuableSubsciptionVisitorsRunner.visit(VisitorsBridge.java:317)
              at org.sonar.java.model.VisitorsBridge$IssuableSubsciptionVisitorsRunner.visitChildren(VisitorsBridge.java:297)
              at org.sonar.java.model.VisitorsBridge$IssuableSubsciptionVisitorsRunner.visit(VisitorsBridge.java:317)
              at org.sonar.java.model.VisitorsBridge$IssuableSubsciptionVisitorsRunner.visitChildren(VisitorsBridge.java:297)
              at org.sonar.java.model.VisitorsBridge$IssuableSubsciptionVisitorsRunner.visit(VisitorsBridge.java:317)
              at org.sonar.java.model.VisitorsBridge$IssuableSubsciptionVisitorsRunner.run(VisitorsBridge.java:288)
              at org.sonar.java.model.VisitorsBridge.visitFile(VisitorsBridge.java:171)
              at org.sonar.java.ast.JavaAstScanner.simpleScan(JavaAstScanner.java:98)
              at org.sonar.java.ast.JavaAstScanner.scan(JavaAstScanner.java:64)
              at org.sonar.java.JavaSquid.scanSources(JavaSquid.java:120)
              at org.sonar.java.JavaSquid.scan(JavaSquid.java:113)
              at org.sonar.plugins.java.JavaSquidSensor.execute(JavaSquidSensor.java:103)
              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:386)
              at org.sonar.scanner.scan.ProjectScanContainer.scanRecursively(ProjectScanContainer.java:382)
              at org.sonar.scanner.scan.ProjectScanContainer.doAfterStart(ProjectScanContainer.java:351)
              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:141)
              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.$Proxy25.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:137)
              at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:210)
              at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:156)
              at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:148)
              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:56)
              at org.apache.maven.lifecycle.internal.LifecycleStarter.execute(LifecycleStarter.java:128)
              at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:305)
              at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:192)
              at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:105)
              at org.apache.maven.cli.MavenCli.execute(MavenCli.java:957)
              at org.apache.maven.cli.MavenCli.doMain(MavenCli.java:289)
              at org.apache.maven.cli.MavenCli.main(MavenCli.java:193)
              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.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced(Launcher.java:282)
              at org.codehaus.plexus.classworlds.launcher.Launcher.launch(Launcher.java:225)
              at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode(Launcher.java:406)
      

        Attachments

          Issue Links

            Activity

              People

              • Assignee:
                quentin.jaquier Quentin Jaquier
                Reporter:
                quentin.jaquier Quentin Jaquier
              • Votes:
                0 Vote for this issue
                Watchers:
                1 Start watching this issue

                Dates

                • Due:
                  Created:
                  Updated:
                  Resolved: