Custon Java Rule: enum symbol unknown when used in swich statement (works in if statement)

152 views
Skip to first unread message

wolfgang....@gmail.com

unread,
May 22, 2018, 12:30:34 PM5/22/18
to SonarQube
Hello!

We're trying to write a custom Rule for Java that checks references to certain constants. This works very well, except on code referencing enum values inside a Switch Statement. Here, the identifier referencing the enum value resolves to an unknown Symbol, when the same enum value referenced in an if Statement resolves properly to a Symbol.

Am I doing something wrong?

I've written a small custom rule to test this. It checks for identifiers with unknown symbols inside if and switch statements.

Let me know in case any information is missing.

Thanks & Kind regards,
Wolfgang

Version of Sonarqube: 6.7.3
Java Analyzer Version: SonarJava 5.3.0.13828
Analyzer called via sonar-maven-plugin:3.4.0.905

pom.xml:

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">


  <modelVersion>4.0.0</modelVersion>


  <groupId>wh.ee.sonar.testcode</groupId>


  <artifactId>wh.ee.sonar.testcode</artifactId>


  <version>0.0.1-SNAPSHOT</version>


  <properties>


    <sonar.sources>src\main\java\wh\ee\sonar\testcode</sonar.sources>


  </properties>


  </project>


test source files:

package wh.ee.sonar.testcode;



public enum TestEnum {


        TEST1, TEST2;


}


package wh.ee.sonar.testcode;



public class TestCode {


        public static void testEnum(TestEnum t) {


                switch (t) {


                case TEST1:


                        break;


                case TEST2:


                        break;


                default:


                        break;


                }


        }



        public static void testEnum2(TestEnum t) {


                if (TestEnum.TEST1.equals(t)) {


                       


                }


                else if (TestEnum.TEST2.equals(t)) {


                       


                }


                else {


                       


                }


        }


}

In this file, the test rule will flag lines 6 and 8, but not lines 16 and 19.



Custom Rule class:

package wh.test.sonar.plugin.checks;



import org.sonar.api.utils.log.Logger;


import org.sonar.api.utils.log.Loggers;


import org.sonar.check.Rule;


import org.sonar.plugins.java.api.JavaFileScanner;


import org.sonar.plugins.java.api.JavaFileScannerContext;


import org.sonar.plugins.java.api.tree.BaseTreeVisitor;


import org.sonar.plugins.java.api.tree.IdentifierTree;


import org.sonar.plugins.java.api.tree.IfStatementTree;


import org.sonar.plugins.java.api.tree.SwitchStatementTree;



@Rule(key = "TestSymbol", name = "Test for unknown symbols", description = "TBD")


public class TestSymbolRule extends BaseTreeVisitor implements JavaFileScanner {


        private static final Logger LOGGER = Loggers.get(TestSymbolRule.class);



        private JavaFileScannerContext context;



        @Override


        public void scanFile(JavaFileScannerContext ctx) {


                this.context = ctx;


                LOGGER.info("Scanning: " + context.getFile().getName());


                scan(context.getTree());


        }



        private boolean doCheck = false;


       


        @Override


        public void visitSwitchStatement(SwitchStatementTree tree) {


                doCheck = true;


                super.visitSwitchStatement(tree);


                doCheck = false;


        }



        @Override


        public void visitIfStatement(IfStatementTree tree) {


                doCheck = true;


                super.visitIfStatement(tree);


                doCheck = false;


        }



        @Override


        public void visitIdentifier(IdentifierTree tree) {


                super.visitIdentifier(tree);


                if (doCheck) {


                        if (tree.symbol().isUnknown()) {


                                context.reportIssue(this, tree, "identifier tree symbol is !unknown!");


                        }


                        else {


                                LOGGER.info("identifier tree symbol: " + tree.symbol().name());


                        }


                }


        }



}



Output of "mvn -X sonar:sonar":

Apache Maven 3.5.2 (138edd61fd100ec658bfa2d307c43b76940a5d7d; 2017-10-18T09:58:13+02:00)


Maven home: C:\AZ_DATEN\apache-maven-3.5.2\bin\..


Java version: 1.8.0_112, vendor: Oracle Corporation


Java home: C:\Program Files\Java\JRE8


Default locale: de_DE, platform encoding: Cp1252


OS name: "windows 7", version: "6.1", arch: "amd64", family: "windows"


[DEBUG] Created new class realm maven.api


[DEBUG] Importing foreign packages into class realm maven.api


[DEBUG]   Imported: javax.annotation.* < plexus.core


[DEBUG]   Imported: javax.enterprise.inject.* < plexus.core


[DEBUG]   Imported: javax.enterprise.util.* < plexus.core


[DEBUG]   Imported: javax.inject.* < plexus.core


[DEBUG]   Imported: org.apache.maven.* < plexus.core


[DEBUG]   Imported: org.apache.maven.artifact < plexus.core


[DEBUG]   Imported: org.apache.maven.classrealm < plexus.core


[DEBUG]   Imported: org.apache.maven.cli < plexus.core


[DEBUG]   Imported: org.apache.maven.configuration < plexus.core


[DEBUG]   Imported: org.apache.maven.exception < plexus.core


[DEBUG]   Imported: org.apache.maven.execution < plexus.core


[DEBUG]   Imported: org.apache.maven.execution.scope < plexus.core


[DEBUG]   Imported: org.apache.maven.lifecycle < plexus.core


[DEBUG]   Imported: org.apache.maven.model < plexus.core


[DEBUG]   Imported: org.apache.maven.monitor < plexus.core


[DEBUG]   Imported: org.apache.maven.plugin < plexus.core


[DEBUG]   Imported: org.apache.maven.profiles < plexus.core


[DEBUG]   Imported: org.apache.maven.project < plexus.core


[DEBUG]   Imported: org.apache.maven.reporting < plexus.core


[DEBUG]   Imported: org.apache.maven.repository < plexus.core


[DEBUG]   Imported: org.apache.maven.rtinfo < plexus.core


[DEBUG]   Imported: org.apache.maven.settings < plexus.core


[DEBUG]   Imported: org.apache.maven.toolchain < plexus.core


[DEBUG]   Imported: org.apache.maven.usability < plexus.core


[DEBUG]   Imported: org.apache.maven.wagon.* < plexus.core


[DEBUG]   Imported: org.apache.maven.wagon.authentication < plexus.core


[DEBUG]   Imported: org.apache.maven.wagon.authorization < plexus.core


[DEBUG]   Imported: org.apache.maven.wagon.events < plexus.core


[DEBUG]   Imported: org.apache.maven.wagon.observers < plexus.core


[DEBUG]   Imported: org.apache.maven.wagon.proxy < plexus.core


[DEBUG]   Imported: org.apache.maven.wagon.repository < plexus.core


[DEBUG]   Imported: org.apache.maven.wagon.resource < plexus.core


[DEBUG]   Imported: org.codehaus.classworlds < plexus.core


[DEBUG]   Imported: org.codehaus.plexus.* < plexus.core


[DEBUG]   Imported: org.codehaus.plexus.classworlds < plexus.core


[DEBUG]   Imported: org.codehaus.plexus.component < plexus.core


[DEBUG]   Imported: org.codehaus.plexus.configuration < plexus.core


[DEBUG]   Imported: org.codehaus.plexus.container < plexus.core


[DEBUG]   Imported: org.codehaus.plexus.context < plexus.core


[DEBUG]   Imported: org.codehaus.plexus.lifecycle < plexus.core


[DEBUG]   Imported: org.codehaus.plexus.logging < plexus.core


[DEBUG]   Imported: org.codehaus.plexus.personality < plexus.core


[DEBUG]   Imported: org.codehaus.plexus.util.xml.Xpp3Dom < plexus.core


[DEBUG]   Imported: org.codehaus.plexus.util.xml.pull.XmlPullParser < plexus.core


[DEBUG]   Imported: org.codehaus.plexus.util.xml.pull.XmlPullParserException < plexus.core


[DEBUG]   Imported: org.codehaus.plexus.util.xml.pull.XmlSerializer < plexus.core


[DEBUG]   Imported: org.eclipse.aether.* < plexus.core


[DEBUG]   Imported: org.eclipse.aether.artifact < plexus.core


[DEBUG]   Imported: org.eclipse.aether.collection < plexus.core


[DEBUG]   Imported: org.eclipse.aether.deployment < plexus.core


[DEBUG]   Imported: org.eclipse.aether.graph < plexus.core


[DEBUG]   Imported: org.eclipse.aether.impl < plexus.core


[DEBUG]   Imported: org.eclipse.aether.installation < plexus.core


[DEBUG]   Imported: org.eclipse.aether.internal.impl < plexus.core


[DEBUG]   Imported: org.eclipse.aether.metadata < plexus.core


[DEBUG]   Imported: org.eclipse.aether.repository < plexus.core


[DEBUG]   Imported: org.eclipse.aether.resolution < plexus.core


[DEBUG]   Imported: org.eclipse.aether.spi < plexus.core


[DEBUG]   Imported: org.eclipse.aether.transfer < plexus.core


[DEBUG]   Imported: org.eclipse.aether.version < plexus.core


[DEBUG]   Imported: org.fusesource.jansi.* < plexus.core


[DEBUG]   Imported: org.slf4j.* < plexus.core


[DEBUG]   Imported: org.slf4j.helpers.* < plexus.core


[DEBUG]   Imported: org.slf4j.spi.* < plexus.core


[DEBUG] Populating class realm maven.api


[INFO] Error stacktraces are turned on.


[DEBUG] Message scheme: color


[DEBUG] Message styles: debug info warning error success failure strong mojo project


[DEBUG] Reading global settings from C:\AZ_DATEN\apache-maven-3.5.2\bin\..\conf\settings.xml


[DEBUG] Reading user settings from C:\Users\mcfamvj\.m2\settings.xml


[DEBUG] Reading global toolchains from C:\AZ_DATEN\apache-maven-3.5.2\bin\..\conf\toolchains.xml


[DEBUG] Reading user toolchains from C:\Users\mcfamvj\.m2\toolchains.xml


[DEBUG] Using local repository at C:\AZ_DATEN\mvn_repository


[DEBUG] Using manager EnhancedLocalRepositoryManager with priority 10.0 for C:\AZ_DATEN\mvn_repository


[INFO] Scanning for projects...


[DEBUG] Extension realms for project wh.ee.sonar.testcode:wh.ee.sonar.testcode:jar:0.0.1-SNAPSHOT: (none)


[DEBUG] Looking up lifecycle mappings for packaging jar from ClassRealm[plexus.core, parent: null]


[DEBUG] Resolving plugin prefix sonar from [org.apache.maven.plugins, org.codehaus.mojo]


[DEBUG] Could not find metadata org.apache.maven.plugins/maven-metadata.xml in local (C:\AZ_DATEN\mvn_repository)


[DEBUG] Skipped remote request for org.apache.maven.plugins/maven-metadata.xml, locally cached metadata up-to-date.


[DEBUG] Could not find metadata org.codehaus.mojo/maven-metadata.xml in local (C:\AZ_DATEN\mvn_repository)


[DEBUG] Skipped remote request for org.codehaus.mojo/maven-metadata.xml, locally cached metadata up-to-date.


[DEBUG] Resolved plugin prefix sonar to org.codehaus.mojo:sonar-maven-plugin from repository central


[DEBUG] Could not find metadata org.codehaus.mojo:sonar-maven-plugin/maven-metadata.xml in local (C:\AZ_DATEN\mvn_repository)


[DEBUG] Skipped remote request for org.codehaus.mojo:sonar-maven-plugin/maven-metadata.xml, locally cached metadata up-to-date.


[DEBUG] Resolved plugin version for org.codehaus.mojo:sonar-maven-plugin to 3.4.0.905 from repository central (https://repo.maven.apache.org/maven2, default, releases)


[DEBUG] === REACTOR BUILD PLAN ================================================


[DEBUG] Project: wh.ee.sonar.testcode:wh.ee.sonar.testcode:jar:0.0.1-SNAPSHOT


[DEBUG] Tasks:   [sonar:sonar]


[DEBUG] Style:   Aggregating


[DEBUG] =======================================================================


[INFO]


[INFO] ------------------------------------------------------------------------


[INFO] Building wh.ee.sonar.testcode 0.0.1-SNAPSHOT


[INFO] ------------------------------------------------------------------------


[DEBUG] Resolving plugin prefix sonar from [org.apache.maven.plugins, org.codehaus.mojo]


[DEBUG] Could not find metadata org.apache.maven.plugins/maven-metadata.xml in local (C:\AZ_DATEN\mvn_repository)


[DEBUG] Skipped remote request for org.apache.maven.plugins/maven-metadata.xml, locally cached metadata up-to-date.


[DEBUG] Could not find metadata org.codehaus.mojo/maven-metadata.xml in local (C:\AZ_DATEN\mvn_repository)


[DEBUG] Skipped remote request for org.codehaus.mojo/maven-metadata.xml, locally cached metadata up-to-date.


[DEBUG] Resolved plugin prefix sonar to org.codehaus.mojo:sonar-maven-plugin from repository central


[DEBUG] Could not find metadata org.codehaus.mojo:sonar-maven-plugin/maven-metadata.xml in local (C:\AZ_DATEN\mvn_repository)


[DEBUG] Skipped remote request for org.codehaus.mojo:sonar-maven-plugin/maven-metadata.xml, locally cached metadata up-to-date.


[DEBUG] Resolved plugin version for org.codehaus.mojo:sonar-maven-plugin to 3.4.0.905 from repository central (https://repo.maven.apache.org/maven2, default, releases)


[DEBUG] Lifecycle default -> [validate, initialize, generate-sources, process-sources, generate-resources, process-resources, compile, process-classes, generate-test-sources, process-test-sources, generate-test-resources, process-test-resources, test-compile, process-test-classes, test, prepare-package, package, pre-integration-test, integration-test, post-integration-test, verify, install, deploy]


[DEBUG] Lifecycle clean -> [pre-clean, clean, post-clean]


[DEBUG] Lifecycle site -> [pre-site, site, post-site, site-deploy]


[DEBUG] === PROJECT BUILD PLAN ================================================


[DEBUG] Project:       wh.ee.sonar.testcode:wh.ee.sonar.testcode:0.0.1-SNAPSHOT


[DEBUG] Dependencies (collect): []


[DEBUG] Dependencies (resolve): [test]


[DEBUG] Repositories (dependencies): [central (https://repo.maven.apache.org/maven2, default, releases)]


[DEBUG] Repositories (plugins)     : [central (https://repo.maven.apache.org/maven2, default, releases)]


[DEBUG] -----------------------------------------------------------------------


[DEBUG] Goal:          org.sonarsource.scanner.maven:sonar-maven-plugin:3.4.0.905:sonar (default-cli)


[DEBUG] Style:         Aggregating


[DEBUG] Configuration: <?xml version="1.0" encoding="UTF-8"?>


<configuration>


  <mojoExecution default-value="${mojoExecution}"/>


  <session default-value="${session}"/>


  <skip default-value="false">${sonar.skip}</skip>


</configuration>


[DEBUG] =======================================================================


[DEBUG] Dependency collection stats: {ConflictMarker.analyzeTime=60167, ConflictMarker.markTime=436850, ConflictMarker.nodeCount=1, ConflictIdSorter.graphTime=37924, ConflictIdSorter.topsortTime=926208, ConflictIdSorter.conflictIdCount=0, ConflictIdSorter.conflictIdCycleCount=0, ConflictResolver.totalTime=1834185, ConflictResolver.conflictItemCount=0, DefaultDependencyCollector.collectTime=238480, DefaultDependencyCollector.transformTime=5463172}


[DEBUG] wh.ee.sonar.testcode:wh.ee.sonar.testcode:jar:0.0.1-SNAPSHOT


[INFO]


[INFO] --- sonar-maven-plugin:3.4.0.905:sonar (default-cli) @ wh.ee.sonar.testcode ---


[DEBUG] Dependency collection stats: {ConflictMarker.analyzeTime=979812, ConflictMarker.markTime=27349, ConflictMarker.nodeCount=7, ConflictIdSorter.graphTime=121793, ConflictIdSorter.topsortTime=26255, ConflictIdSorter.conflictIdCount=6, ConflictIdSorter.conflictIdCycleCount=0, ConflictResolver.totalTime=2056620, ConflictResolver.conflictItemCount=7, DefaultDependencyCollector.collectTime=50752581, DefaultDependencyCollector.transformTime=3274548}


[DEBUG] org.sonarsource.scanner.maven:sonar-maven-plugin:jar:3.4.0.905:


[DEBUG]    org.sonatype.plexus:plexus-sec-dispatcher:jar:1.4:compile


[DEBUG]       org.sonatype.plexus:plexus-cipher:jar:1.4:compile


[DEBUG]    org.codehaus.plexus:plexus-utils:jar:3.0.22:compile


[DEBUG]    org.sonarsource.scanner.api:sonar-scanner-api:jar:2.10.0.1189:compile


[DEBUG]    commons-lang:commons-lang:jar:2.6:compile


[DEBUG] Created new class realm plugin>org.codehaus.mojo:sonar-maven-plugin:3.4.0.905


[DEBUG] Importing foreign packages into class realm plugin>org.codehaus.mojo:sonar-maven-plugin:3.4.0.905


[DEBUG]   Imported:  < maven.api


[DEBUG] Populating class realm plugin>org.codehaus.mojo:sonar-maven-plugin:3.4.0.905


[DEBUG]   Included: org.sonarsource.scanner.maven:sonar-maven-plugin:jar:3.4.0.905


[DEBUG]   Included: org.sonatype.plexus:plexus-sec-dispatcher:jar:1.4


[DEBUG]   Included: org.sonatype.plexus:plexus-cipher:jar:1.4


[DEBUG]   Included: org.codehaus.plexus:plexus-utils:jar:3.0.22


[DEBUG]   Included: org.sonarsource.scanner.api:sonar-scanner-api:jar:2.10.0.1189


[DEBUG]   Included: commons-lang:commons-lang:jar:2.6


[DEBUG] Configuring mojo org.sonarsource.scanner.maven:sonar-maven-plugin:3.4.0.905:sonar from plugin realm ClassRealm[plugin>org.codehaus.mojo:sonar-maven-plugin:3.4.0.905, parent: sun.misc.Launcher$AppClassLoader@55f96302]


[DEBUG] Configuring mojo 'org.sonarsource.scanner.maven:sonar-maven-plugin:3.4.0.905:sonar' with basic configurator -->


[DEBUG]   (f) mojoExecution = org.sonarsource.scanner.maven:sonar-maven-plugin:3.4.0.905:sonar {execution: default-cli}


[DEBUG]   (f) session = org.apache.maven.execution.MavenSession@6a62689d


[DEBUG]   (f) skip = false


[DEBUG] -- end configuration --


[DEBUG] Lifecycle default -> [validate, initialize, generate-sources, process-sources, generate-resources, process-resources, compile, process-classes, generate-test-sources, process-test-sources, generate-test-resources, process-test-resources, test-compile, process-test-classes, test, prepare-package, package, pre-integration-test, integration-test, post-integration-test, verify, install, deploy]


[DEBUG] Lifecycle clean -> [pre-clean, clean, post-clean]


[DEBUG] Lifecycle site -> [pre-site, site, post-site, site-deploy]


[DEBUG] 18:17:12.373 Setting proxy properties


[DEBUG] 18:17:12.575 keyStore is :


[DEBUG] 18:17:12.575 keyStore type is : jks


[DEBUG] 18:17:12.575 keyStore provider is :


[DEBUG] 18:17:12.575 init keystore


[DEBUG] 18:17:12.575 init keymanager of type SunX509


[DEBUG] 18:17:13.005 Create: C:\Users\mcfamvj\.sonar\cache


[INFO] 18:17:13.005 User cache: C:\Users\mcfamvj\.sonar\cache


[DEBUG] 18:17:13.005 Create: C:\Users\mcfamvj\.sonar\cache\_tmp


[DEBUG] 18:17:13.005 Extract sonar-scanner-api-batch in temp...


[DEBUG] 18:17:13.015 Get bootstrap index...


[DEBUG] 18:17:13.015 Download: http://localhost:9000/batch/index


[DEBUG] 18:17:13.125 Get bootstrap completed


[DEBUG] 18:17:13.125 Create isolated classloader...


[DEBUG] 18:17:13.135 Start temp cleaning...


[DEBUG] 18:17:13.135 Temp cleaning done


[DEBUG] 18:17:13.135 Execution getVersion


[INFO] 18:17:13.135 SonarQube version: 6.7.3


[INFO] 18:17:13.145 Default locale: "de_DE", source code encoding: "windows-1252" (analysis is platform dependent)


[DEBUG] 18:17:13.155 Work directory: C:\AZ_DATEN\eclipse_workspaces_wolfgang\ee-sonar\wh.ee.sonar.testcode\target\sonar


[DEBUG] 18:17:13.155 Execution execute


[INFO] 18:17:13.495 Publish mode


[INFO] 18:17:13.625 Load global settings


[DEBUG] 18:17:13.675 GET 200 http://localhost:9000/api/settings/values.protobuf | time=40ms


[INFO] 18:17:13.695 Load global settings (done) | time=70ms


[INFO] 18:17:13.705 Server id: AWM6yHihy8FLWfRw_WR1


[INFO] 18:17:13.705 User cache: C:\Users\[REDACTED]\.sonar\cache


[INFO] 18:17:13.915 Load plugins index


[DEBUG] 18:17:13.925 GET 200 http://localhost:9000/api/plugins/installed | time=10ms


[INFO] 18:17:13.975 Load plugins index (done) | time=60ms


[DEBUG] 18:17:13.975 Load plugins


[DEBUG] 18:17:13.985 Load plugins (done) | time=10ms


[DEBUG] 18:17:14.065 Plugins:


[DEBUG] 18:17:14.065   * SonarC# 6.5.0.3766 (csharp)


[DEBUG] 18:17:14.065   * SonarPython 1.8.0.1496 (python)


[DEBUG] 18:17:14.065   * SonarJava 5.3.0.13828 (java)


[DEBUG] 18:17:14.065   * sonar-testwh-plugin 0.2.8 (testwh)


[DEBUG] 18:17:14.065   * Flex 2.3 (flex)


[DEBUG] 18:17:14.065   * SonarQube :: Plugins :: SCM :: Git 1.3.0.869 (scmgit)


[DEBUG] 18:17:14.065   * SonarXML 1.4.3.1027 (xml)


[DEBUG] 18:17:14.065   * SonarPHP 2.11.0.2485 (php)


[DEBUG] 18:17:14.075   * SonarTS 1.1.0.1079 (typescript)


[DEBUG] 18:17:14.075   * SonarQube :: Plugins :: SCM :: SVN 1.6.0.860 (scmsvn)


[DEBUG] 18:17:14.075   * SonarJS 3.2.0.5506 (javascript)


[INFO] 18:17:14.446 Process project properties


[DEBUG] 18:17:14.455 Process project properties (done) | time=9ms


[INFO] 18:17:14.497 Load project repositories


[DEBUG] 18:17:14.517 GET 200 http://localhost:9000/batch/project.protobuf?key=wh.ee.sonar.testcode%3Awh.ee.sonar.testcode | time=20ms


[INFO] 18:17:14.607 Load project repositories (done) | time=110ms


[DEBUG] 18:17:14.951 Available languages:


[DEBUG] 18:17:14.951   * C# => "cs"


[DEBUG] 18:17:14.951   * Python => "py"


[DEBUG] 18:17:14.951   * Java => "java"


[DEBUG] 18:17:14.951   * Flex => "flex"


[DEBUG] 18:17:14.951   * XML => "xml"


[DEBUG] 18:17:14.951   * PHP => "php"


[DEBUG] 18:17:14.951   * TypeScript => "ts"


[DEBUG] 18:17:14.951   * JavaScript => "js"


[INFO] 18:17:14.961 Load quality profiles


[DEBUG] 18:17:15.063 GET 200 http://localhost:9000/api/qualityprofiles/search.protobuf?projectKey=wh.ee.sonar.testcode%3Awh.ee.sonar.testcode | time=102ms


[INFO] 18:17:15.073 Load quality profiles (done) | time=112ms


[INFO] 18:17:15.083 Load active rules


[DEBUG] 18:17:15.193 GET 200 http://localhost:9000/api/rules/search.protobuf?f=repo,name,severity,lang,internalKey,templateKey,params,actives,createdAt&activation=true&qprofile=AWM6yKx-y8FLWfRw_WsO&p=1&ps=500 | time=110ms


[DEBUG] 18:17:15.263 GET 200 http://localhost:9000/api/rules/search.protobuf?f=repo,name,severity,lang,internalKey,templateKey,params,actives,createdAt&activation=true&qprofile=AWM_fvyX7U2voexxSua_&p=1&ps=500 | time=30ms


[DEBUG] 18:17:15.303 GET 200 http://localhost:9000/api/rules/search.protobuf?f=repo,name,severity,lang,internalKey,templateKey,params,actives,createdAt&activation=true&qprofile=AWM6yLEfy8FLWfRw_W5U&p=1&ps=500 | time=40ms


[DEBUG] 18:17:15.333 GET 200 http://localhost:9000/api/rules/search.protobuf?f=repo,name,severity,lang,internalKey,templateKey,params,actives,createdAt&activation=true&qprofile=AWM6yLCjy8FLWfRw_W4V&p=1&ps=500 | time=30ms


[DEBUG] 18:17:15.363 GET 200 http://localhost:9000/api/rules/search.protobuf?f=repo,name,severity,lang,internalKey,templateKey,params,actives,createdAt&activation=true&qprofile=AWM6yLNCy8FLWfRw_W-6&p=1&ps=500 | time=30ms


[DEBUG] 18:17:15.393 GET 200 http://localhost:9000/api/rules/search.protobuf?f=repo,name,severity,lang,internalKey,templateKey,params,actives,createdAt&activation=true&qprofile=AWM6yLQMy8FLWfRw_XA5&p=1&ps=500 | time=30ms


[DEBUG] 18:17:15.413 GET 200 http://localhost:9000/api/rules/search.protobuf?f=repo,name,severity,lang,internalKey,templateKey,params,actives,createdAt&activation=true&qprofile=AWM6yLa7y8FLWfRw_XDq&p=1&ps=500 | time=20ms


[DEBUG] 18:17:15.433 GET 200 http://localhost:9000/api/rules/search.protobuf?f=repo,name,severity,lang,internalKey,templateKey,params,actives,createdAt&activation=true&qprofile=AWM6yLvpy8FLWfRw_XEu&p=1&ps=500 | time=20ms


[INFO] 18:17:15.443 Load active rules (done) | time=360ms


[INFO] 18:17:15.443 Load metrics repository


[DEBUG] 18:17:15.453 GET 200 http://localhost:9000/api/metrics/search?f=name,description,direction,qualitative,custom&ps=500&p=1 | time=10ms


[INFO] 18:17:15.463 Load metrics repository (done) | time=20ms


[WARNING] 18:17:15.513 SCM provider autodetection failed. No SCM provider claims to support this project. Please use sonar.scm.provider to define SCM of your project.


[INFO] 18:17:15.513 Project key: wh.ee.sonar.testcode:wh.ee.sonar.testcode


[DEBUG] 18:17:15.513 Start recursive analysis of project modules


[INFO] 18:17:15.513 -------------  Scan wh.ee.sonar.testcode


[INFO] 18:17:15.603 Load server rules


[DEBUG] 18:17:15.703 GET 200 http://localhost:9000/api/rules/list.protobuf | time=100ms


[INFO] 18:17:15.713 Load server rules (done) | time=110ms


[INFO] 18:17:15.753 Base dir: C:\AZ_DATEN\eclipse_workspaces_wolfgang\ee-sonar\wh.ee.sonar.testcode


[INFO] 18:17:15.753 Working dir: C:\AZ_DATEN\eclipse_workspaces_wolfgang\ee-sonar\wh.ee.sonar.testcode\target\sonar


[INFO] 18:17:15.753 Source paths: src/main/java/wh/ee/sonar/testcode


[INFO] 18:17:15.753 Test paths: src/test/java


[INFO] 18:17:15.753 Source encoding: windows-1252, default locale: de_DE


[DEBUG] 18:17:15.833 Declared extensions of language C# were converted to sonar.lang.patterns.cs : **/*.cs


[DEBUG] 18:17:15.833 Declared extensions of language Python were converted to sonar.lang.patterns.py : **/*.py


[DEBUG] 18:17:15.833 Declared extensions of language Java were converted to sonar.lang.patterns.java : **/*.java,**/*.jav


[DEBUG] 18:17:15.833 Declared extensions of language Flex were converted to sonar.lang.patterns.flex : **/*.as


[DEBUG] 18:17:15.833 Declared extensions of language XML were converted to sonar.lang.patterns.xml : **/*.xml,**/*.xsd,**/*.xsl


[DEBUG] 18:17:15.833 Declared extensions of language PHP were converted to sonar.lang.patterns.php : **/*.php,**/*.php3,**/*.php4,**/*.php5,**/*.phtml,**/*.inc


[DEBUG] 18:17:15.833 Declared extensions of language TypeScript were converted to sonar.lang.patterns.ts : **/*.ts,**/*.tsx


[DEBUG] 18:17:15.833 Declared extensions of language JavaScript were converted to sonar.lang.patterns.js : **/*.js,**/*.jsx,**/*.vue


[DEBUG] 18:17:15.843 Initializers :


[INFO] 18:17:15.843 Index files


[DEBUG] 18:17:15.853 'src\main\java\wh\ee\sonar\testcode\TestCode.java' indexed with language 'java'


[DEBUG] 18:17:15.853 'src\main\java\wh\ee\sonar\testcode\TestEnum.java' indexed with language 'java'


[DEBUG] 18:17:15.853 'src\main\java\wh\ee\sonar\testcode\MyClass.java' indexed with language 'java'


[INFO] 18:17:15.853 3 files indexed


[INFO] 18:17:15.853 Quality profile for java: ee-test


[DEBUG] 18:17:16.535 'Generic Coverage Report' skipped because one of the required properties is missing


[DEBUG] 18:17:16.535 'Generic Test Executions Report' skipped because one of the required properties is missing


[DEBUG] 18:17:16.535 'C#' skipped because there is no related file in current project


[DEBUG] 18:17:16.535 'C# Tests Coverage Report Import' skipped because there is no related file in current project


[DEBUG] 18:17:16.535 '[Deprecated] C# Integration Tests Coverage Report Import' skipped because there is no related file in current project


[DEBUG] 18:17:16.535 'C# Unit Test Results Import' skipped because there is no related file in current project


[DEBUG] 18:17:16.535 'Python Squid Sensor' skipped because there is no related file in current project


[DEBUG] 18:17:16.536 'Flex' skipped because there is no related file in current project


[DEBUG] 18:17:16.536 'Flex Cobertura' skipped because there is no related file in current project


[DEBUG] 18:17:16.536 'XML Sensor' skipped because there is no related file in current project


[DEBUG] 18:17:16.536 'PHP sensor' skipped because there is no related file in current project


[DEBUG] 18:17:16.536 'TypeScript Sensor' skipped because there is no related file in current project


[DEBUG] 18:17:16.536 'TypeScript LCOV Coverage Sensor' skipped because there is no related file in current project


[DEBUG] 18:17:16.536 'JavaScript Squid Sensor' skipped because there is no related file in current project


[DEBUG] 18:17:16.536 'Generic Coverage Report' skipped because one of the required properties is missing


[DEBUG] 18:17:16.536 'Generic Test Executions Report' skipped because one of the required properties is missing


[DEBUG] 18:17:16.536 'C#' skipped because there is no related file in current project


[DEBUG] 18:17:16.536 'C# Tests Coverage Report Import' skipped because there is no related file in current project


[DEBUG] 18:17:16.536 '[Deprecated] C# Integration Tests Coverage Report Import' skipped because there is no related file in current project


[DEBUG] 18:17:16.536 'C# Unit Test Results Import' skipped because there is no related file in current project


[DEBUG] 18:17:16.536 'Python Squid Sensor' skipped because there is no related file in current project


[DEBUG] 18:17:16.536 'Flex' skipped because there is no related file in current project


[DEBUG] 18:17:16.536 'Flex Cobertura' skipped because there is no related file in current project


[DEBUG] 18:17:16.536 'XML Sensor' skipped because there is no related file in current project


[DEBUG] 18:17:16.536 'PHP sensor' skipped because there is no related file in current project


[DEBUG] 18:17:16.536 'TypeScript Sensor' skipped because there is no related file in current project


[DEBUG] 18:17:16.536 'TypeScript LCOV Coverage Sensor' skipped because there is no related file in current project


[DEBUG] 18:17:16.536 'JavaScript Squid Sensor' skipped because there is no related file in current project


[DEBUG] 18:17:16.536 Sensors : JavaSquidSensor -> SurefireSensor -> JaCoCoSensor -> SonarJavaXmlFileSensor -> Analyzer for "php.ini" files -> Zero Coverage Sensor -> CPD Block Indexer


[INFO] 18:17:16.536 Sensor JavaSquidSensor [java]


[INFO] 18:17:16.707 Configured Java source version (sonar.java.source): 5


[DEBUG] 18:17:16.727 com.sonar.plugins.security.api.JavaRules is not found, no security rules added to Sonar way java profile: com.sonar.plugins.security.api.JavaRules


[INFO] 18:17:16.727 JavaClasspath initialization


[WARNING] 18:17:16.737 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


[INFO] 18:17:16.737 JavaClasspath initialization (done) | time=10ms


[INFO] 18:17:16.747 JavaTestClasspath initialization


[INFO] 18:17:16.747 JavaTestClasspath initialization (done) | time=0ms


[DEBUG] 18:17:17.027 ----- Classpath analyzed by Squid:


[DEBUG] 18:17:17.027 C:\AZ_DATEN\eclipse_workspaces_wolfgang\ee-sonar\wh.ee.sonar.testcode\target\classes


[DEBUG] 18:17:17.027 -----


[DEBUG] 18:17:17.027 ----- Classpath analyzed by Squid:


[DEBUG] 18:17:17.027 C:\AZ_DATEN\eclipse_workspaces_wolfgang\ee-sonar\wh.ee.sonar.testcode\target\test-classes


[DEBUG] 18:17:17.027 C:\AZ_DATEN\eclipse_workspaces_wolfgang\ee-sonar\wh.ee.sonar.testcode\target\classes


[DEBUG] 18:17:17.027 -----


[INFO] 18:17:17.027 Java Main Files AST scan


[INFO] 18:17:17.027 3 source files to be analyzed


[DEBUG] 18:17:17.047 'src/main/java/wh/ee/sonar/testcode/MyClass.java' generated metadata  with charset 'windows-1252'


[DEBUG] 18:17:17.179 .class not found for wh.ee.sonar.testcode.wh


[DEBUG] 18:17:17.180 .class not found for java.lang.package-info


[DEBUG] 18:17:17.180 .class not found for java.lang.wh


[DEBUG] 18:17:17.180 .class not found for java.lang.Synthetic$wh


[DEBUG] 18:17:17.180 .class not found for wh.ee


[DEBUG] 18:17:17.180 .class not found for wh.ee.sonar


[INFO] 18:17:17.249 Scanning: MyClass.java


[DEBUG] 18:17:17.269 'src/main/java/wh/ee/sonar/testcode/TestCode.java' generated metadata  with charset 'windows-1252'


[DEBUG] 18:17:17.309 .class not found for wh.ee.sonar.testcode.wh


[DEBUG] 18:17:17.309 .class not found for java.lang.package-info


[DEBUG] 18:17:17.309 .class not found for java.lang.wh


[DEBUG] 18:17:17.309 .class not found for java.lang.Synthetic$wh


[DEBUG] 18:17:17.309 .class not found for wh.ee


[DEBUG] 18:17:17.309 .class not found for wh.ee.sonar


[INFO] 18:17:17.319 Scanning: TestCode.java


[INFO] 18:17:17.319 identifier tree symbol: t


[INFO] 18:17:17.349 identifier tree symbol: TestEnum


[INFO] 18:17:17.349 identifier tree symbol: TEST1


[INFO] 18:17:17.349 identifier tree symbol: equals


[INFO] 18:17:17.349 identifier tree symbol: t


[INFO] 18:17:17.349 identifier tree symbol: TestEnum


[INFO] 18:17:17.349 identifier tree symbol: TEST2


[INFO] 18:17:17.349 identifier tree symbol: equals


[INFO] 18:17:17.349 identifier tree symbol: t


[DEBUG] 18:17:17.359 'src/main/java/wh/ee/sonar/testcode/TestEnum.java' generated metadata  with charset 'windows-1252'


[DEBUG] 18:17:17.379 .class not found for wh.ee.sonar.testcode.wh


[DEBUG] 18:17:17.379 .class not found for java.lang.package-info


[DEBUG] 18:17:17.379 .class not found for java.lang.wh


[DEBUG] 18:17:17.379 .class not found for java.lang.Synthetic$wh


[DEBUG] 18:17:17.379 .class not found for wh.ee


[DEBUG] 18:17:17.379 .class not found for wh.ee.sonar


[INFO] 18:17:17.389 Scanning: TestEnum.java


[INFO] 18:17:17.389 3/3 source files have been analyzed


[INFO] 18:17:17.389 Java Main Files AST scan (done) | time=362ms


[INFO] 18:17:17.389 Java Test Files AST scan


[INFO] 18:17:17.389 0 source files to be analyzed


[INFO] 18:17:17.389 Java Test Files AST scan (done) | time=0ms


[INFO] 18:17:17.399 Sensor JavaSquidSensor [java] (done) | time=863ms


[INFO] 18:17:17.399 Sensor SurefireSensor [java]


[INFO] 18:17:17.399 0/0 source files have been analyzed


[INFO] 18:17:17.399 parsing [C:\AZ_DATEN\eclipse_workspaces_wolfgang\ee-sonar\wh.ee.sonar.testcode\target\surefire-reports]


[INFO] 18:17:17.399 Sensor SurefireSensor [java] (done) | time=0ms


[INFO] 18:17:17.399 Sensor JaCoCoSensor [java]


[INFO] 18:17:17.399 Sensor JaCoCoSensor [java] (done) | time=0ms


[INFO] 18:17:17.399 Sensor SonarJavaXmlFileSensor [java]


[INFO] 18:17:17.399 Sensor SonarJavaXmlFileSensor [java] (done) | time=0ms


[INFO] 18:17:17.399 Sensor Analyzer for "php.ini" files [php]


[INFO] 18:17:17.399 Sensor Analyzer for "php.ini" files [php] (done) | time=0ms


[INFO] 18:17:17.399 Sensor Zero Coverage Sensor


[INFO] 18:17:17.419 Sensor Zero Coverage Sensor (done) | time=20ms


[INFO] 18:17:17.419 Sensor CPD Block Indexer


[DEBUG] 18:17:17.419 org.sonar.scanner.cpd.deprecated.JavaCpdBlockIndexer is used for java


[DEBUG] 18:17:17.429 Populating index from src/main/java/wh/ee/sonar/testcode/MyClass.java


[DEBUG] 18:17:17.429 Not enough content in 'src/main/java/wh/ee/sonar/testcode/MyClass.java' to have CPD blocks, it will not be part of the duplication detection


[DEBUG] 18:17:17.429 Populating index from src/main/java/wh/ee/sonar/testcode/TestCode.java


[DEBUG] 18:17:17.439 Not enough content in 'src/main/java/wh/ee/sonar/testcode/TestCode.java' to have CPD blocks, it will not be part of the duplication detection


[DEBUG] 18:17:17.439 Populating index from src/main/java/wh/ee/sonar/testcode/TestEnum.java


[DEBUG] 18:17:17.439 Not enough content in 'src/main/java/wh/ee/sonar/testcode/TestEnum.java' to have CPD blocks, it will not be part of the duplication detection


[INFO] 18:17:17.439 Sensor CPD Block Indexer (done) | time=20ms


[INFO] 18:17:17.439 No SCM system was detected. You can use the 'sonar.scm.provider' property to explicitly specify it.


[INFO] 18:17:17.439 3 files had no CPD blocks


[INFO] 18:17:17.439 Calculating CPD for 0 files


[INFO] 18:17:17.439 CPD calculation finished


[INFO] 18:17:17.549 Analysis report generated in 100ms, dir size=33 KB


[INFO] 18:17:17.589 Analysis reports compressed in 40ms, zip size=11 KB


[INFO] 18:17:17.589 Analysis report generated in C:\AZ_DATEN\eclipse_workspaces_wolfgang\ee-sonar\wh.ee.sonar.testcode\target\sonar\scanner-report


[DEBUG] 18:17:17.589 Upload report


[DEBUG] 18:17:17.619 POST 200 http://localhost:9000/api/ce/submit?projectKey=wh.ee.sonar.testcode:wh.ee.sonar.testcode&projectName=wh.ee.sonar.testcode | time=30ms


[INFO] 18:17:17.629 Analysis report uploaded in 40ms


[INFO] 18:17:17.629 ANALYSIS SUCCESSFUL, you can browse http://localhost:9000/dashboard/index/wh.ee.sonar.testcode:wh.ee.sonar.testcode


[INFO] 18:17:17.629 Note that you will be able to access the updated dashboard once the server has processed the submitted analysis report


[INFO] 18:17:17.629 More about the report processing at http://localhost:9000/api/ce/task?id=AWOIo_kzX9AJE-EBfQKr


[DEBUG] 18:17:17.629 Report metadata written to C:\AZ_DATEN\eclipse_workspaces_wolfgang\ee-sonar\wh.ee.sonar.testcode\target\sonar\report-task.txt


[DEBUG] 18:17:17.639 Post-jobs :


[INFO] 18:17:17.639 Task total time: 3.554 s


[INFO] ------------------------------------------------------------------------


[INFO] BUILD SUCCESS


[INFO] ------------------------------------------------------------------------


[INFO] Total time: 6.366 s


[INFO] Finished at: 2018-05-22T18:17:18+02:00


[INFO] Final Memory: 19M/418M


[INFO] ------------------------------------------------------------------------




wolfgang....@gmail.com

unread,
May 22, 2018, 12:39:32 PM5/22/18
to SonarQube


Here's a screenshot of the custom rule flagging the unknown Symbol in a Switch, but not in an if:





Andrei Epure

unread,
Jun 8, 2018, 10:26:16 AM6/8/18
to SonarQube
Hello Wolfgang!

Thank you very much for this detailed report, I confirm it is a bug. I've opened SONARJAVA-2784 to have it on the road-map.

Kind regards,
Andrei

P.S.: Starting June 11th we'll have a new awesome forum. Details here

Andrei Epure | SonarSource

Software Developer

https://sonarsource.com


Are you using SonarLint in your IDE?


Reply all
Reply to author
Forward
0 new messages