Sonar Java Plugin json not found

487 views
Skip to first unread message

jjj...@gmail.com

unread,
Mar 16, 2017, 7:40:04 AM3/16/17
to SonarQube
Hi,

I am working on my final Project which consists in analyse Java source code with custom rules to identify vulnerabilities in applications. I am following the SonarQube documentation for writing custom rules in Java (https://docs.sonarqube.org/display/PLUG/Writing+Custom+Java+Rules+101). I am facing issues when trying to run the test file through Junit as indicated in the documentation. I get a "<Rule name>_java.json not found" for each test I try to run, I have even tried to run Junit tests from the sample project provided in SonarQube documentation (https://github.com/SonarSource/sonar-custom-rules-examples/tree/master/java-custom-rules) which is fully functional. I have been looking for this error around Internet for about a week and found anything so I decided to try here. Does anyone know how to solve this error? Any help would be appreciated.

Thanks in advance,
Joaquin

jjj...@gmail.com

unread,
Mar 16, 2017, 2:08:15 PM3/16/17
to SonarQube, jjj...@gmail.com
To be more accurate that's what I get when I try to run the Junit test:

WARN  o.s.j.checks.verifier.CheckVerifier - Exception parsing JSON for rule MyFirstCustomCheck

java.io.IOException: /org/sonar/l10n/java/rules/squid/MyFirstCustomCheck_java.json not found


I don't know what's happening, do I have to create those JSON files myself?


Thanks in advance,

Joaquin

Michael Gumowski

unread,
Mar 17, 2017, 3:14:24 PM3/17/17
to jjj...@gmail.com, SonarQube
Hello Joaquin,

Thank you for the feedback. Unfortunately, it seems that some internal work we did to enforce our usage of rule remediation cost had unexpected and definitely unintended impact on the JavaCheckVerifier API. This regression has been introduced in SonarJava 4.5 and broke compatibility with the tutorial. I created the following ticket to fix the issue: SONARJAVA-2197

For the time being, your only option in order to continue your development would be to downgrade to version 4.4.0.8066 of the SonarJava check test kit in the dependency of your custom plugin (see pom.xml file). 

<dependency>
<groupId>org.sonarsource.java</groupId>
<artifactId>java-checks-testkit</artifactId>
<!-- <version>${java.plugin.version}</version> -->
<version>4.4.0.8066</version>
<scope>test</scope>
</dependency>


It would allow you to continue to rely on the @Rule annotation, as described in the tutorial. As it's only the testing framework which is failing, this should not have impact on the rest of your code and you should be able to safely continue developing your rules.

HTH,

Michael


--
You received this message because you are subscribed to the Google Groups "SonarQube" group.
To unsubscribe from this group and stop receiving emails from it, send an email to sonarqube+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/sonarqube/954a47d0-22dd-4899-9dac-3a6469046f91%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
--

Michael GUMOWSKI | SonarSource
Software Developer @ Language Team
http://sonarsource.com

jjj...@gmail.com

unread,
Mar 18, 2017, 5:55:00 PM3/18/17
to SonarQube
Hi Michael,

Thank you so much for your response, I will definitely try changing the version of that component to see if it works. I'll let you know once tested.

Regards,
Joaquin 

Tibor Blenessy

unread,
Mar 20, 2017, 9:23:56 AM3/20/17
to jjj...@gmail.com, SonarQube
Hello Joaquin,

after further investigation it seems to me, that if the JSON file is not provided the exception is logged in the log, however the test itself doesn't fail. Can you please confirm if your tests are really failing due to JSON file missing?  Ideally if you can sent full log of your maven build. 

Thanks

Tibor

--
You received this message because you are subscribed to the Google Groups "SonarQube" group.
To unsubscribe from this group and stop receiving emails from it, send an email to sonarqube+...@googlegroups.com.

For more options, visit https://groups.google.com/d/optout.
--
Tibor BLENESSY | SonarSource
SonarJava Developer

jjj...@gmail.com

unread,
Mar 20, 2017, 2:09:34 PM3/20/17
to SonarQube, jjj...@gmail.com
Hi Tibor,

Thanks for your time. Please find below the output of the command mvn clean install, which is the one indicated in the tutorial (if you want me to send you another log please let me know):

[INFO] Scanning for projects...
[INFO]                                                                         
[INFO] ------------------------------------------------------------------------
[INFO] Building Java Custom Rules - Template 1.0-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO] 
[INFO] --- maven-clean-plugin:2.5:clean (default-clean) @ java-custom-rules-template ---
[INFO] Deleting /home/joaquin/Project/workspace/java-custom-rules-template/target
[INFO] 
[INFO] --- sonar-packaging-maven-plugin:1.17:check (default-check) @ java-custom-rules-template ---
[INFO] 
[INFO] --- maven-resources-plugin:3.0.2:resources (default-resources) @ java-custom-rules-template ---
[WARNING] Using platform encoding (UTF-8 actually) to copy filtered resources, i.e. build is platform dependent!
[INFO] skip non existing resourceDirectory /home/joaquin/Project/workspace/java-custom-rules-template/src/main/resources
[INFO] 
[INFO] --- maven-compiler-plugin:3.6.0:compile (default-compile) @ java-custom-rules-template ---
[INFO] Changes detected - recompiling the module!
[WARNING] File encoding has not been set, using platform encoding UTF-8, i.e. build is platform dependent!
[INFO] Compiling 6 source files to /home/joaquin/Project/workspace/java-custom-rules-template/target/classes
[INFO] 
[INFO] --- maven-resources-plugin:3.0.2:testResources (default-testResources) @ java-custom-rules-template ---
[WARNING] Using platform encoding (UTF-8 actually) to copy filtered resources, i.e. build is platform dependent!
[INFO] skip non existing resourceDirectory /home/joaquin/Project/workspace/java-custom-rules-template/src/test/resources
[INFO] 
[INFO] --- maven-compiler-plugin:3.6.0:testCompile (default-testCompile) @ java-custom-rules-template ---
[INFO] Changes detected - recompiling the module!
[WARNING] File encoding has not been set, using platform encoding UTF-8, i.e. build is platform dependent!
[INFO] Compiling 2 source files to /home/joaquin/Project/workspace/java-custom-rules-template/target/test-classes
[INFO] 
[INFO] --- maven-surefire-plugin:2.19.1:test (default-test) @ java-custom-rules-template ---

-------------------------------------------------------
 T E S T S
-------------------------------------------------------
Running org.sonar.template.java.JavaCustomRulesDefinitionTest
Tests run: 1, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.39 sec - in org.sonar.template.java.JavaCustomRulesDefinitionTest
Running org.sonar.template.java.checks.MyFirstCustomCheckTest
10:27:36.312 [main] INFO  org.sonar.squidbridge.ProgressReport - 1 source files to be analyzed
10:27:36.475 [main] DEBUG o.s.java.bytecode.ClassLoaderBuilder - ----- Classpath analyzed by Squid:
10:27:36.475 [main] DEBUG o.s.java.bytecode.ClassLoaderBuilder - /home/joaquin/Project/workspace/java-custom-rules-template/target/test-classes
10:27:36.475 [main] DEBUG o.s.java.bytecode.ClassLoaderBuilder - -----
10:27:36.840 [Report about progress of Java AST analyzer] INFO  org.sonar.squidbridge.ProgressReport - 1/1 source files have been analyzed
10:27:36.855 [main] WARN  o.s.j.checks.verifier.CheckVerifier - Exception parsing JSON for rule MyFirstCustomCheck
java.io.IOException: /org/sonar/l10n/java/rules/squid/MyFirstCustomCheck_java.json not found
at org.sonar.java.checks.verifier.CheckVerifier.getRuleJSON(CheckVerifier.java:228) [java-checks-testkit-4.6.0.8784.jar:na]
at org.sonar.java.checks.verifier.CheckVerifier.remediationFunction(CheckVerifier.java:205) [java-checks-testkit-4.6.0.8784.jar:na]
at org.sonar.java.checks.verifier.CheckVerifier.assertMultipleIssue(CheckVerifier.java:178) [java-checks-testkit-4.6.0.8784.jar:na]
at org.sonar.java.checks.verifier.CheckVerifier.checkIssues(CheckVerifier.java:171) [java-checks-testkit-4.6.0.8784.jar:na]
at org.sonar.java.checks.verifier.JavaCheckVerifier.scanFile(JavaCheckVerifier.java:274) [java-checks-testkit-4.6.0.8784.jar:na]
at org.sonar.java.checks.verifier.JavaCheckVerifier.scanFile(JavaCheckVerifier.java:256) [java-checks-testkit-4.6.0.8784.jar:na]
at org.sonar.java.checks.verifier.JavaCheckVerifier.scanFile(JavaCheckVerifier.java:222) [java-checks-testkit-4.6.0.8784.jar:na]
at org.sonar.java.checks.verifier.JavaCheckVerifier.verify(JavaCheckVerifier.java:105) [java-checks-testkit-4.6.0.8784.jar:na]
at org.sonar.template.java.checks.MyFirstCustomCheckTest.test(MyFirstCustomCheckTest.java:10) [test-classes/:na]
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.8.0_121]
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[na:1.8.0_121]
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:1.8.0_121]
at java.lang.reflect.Method.invoke(Method.java:498) ~[na:1.8.0_121]
at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:47) [junit-4.11.jar:na]
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12) [junit-4.11.jar:na]
at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:44) [junit-4.11.jar:na]
at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17) [junit-4.11.jar:na]
at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:271) [junit-4.11.jar:na]
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:70) [junit-4.11.jar:na]
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:50) [junit-4.11.jar:na]
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:238) [junit-4.11.jar:na]
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:63) [junit-4.11.jar:na]
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:236) [junit-4.11.jar:na]
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:53) [junit-4.11.jar:na]
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:229) [junit-4.11.jar:na]
at org.junit.runners.ParentRunner.run(ParentRunner.java:309) [junit-4.11.jar:na]
at org.apache.maven.surefire.junit4.JUnit4Provider.execute(JUnit4Provider.java:367) [surefire-junit4-2.19.1.jar:2.19.1]
at org.apache.maven.surefire.junit4.JUnit4Provider.executeWithRerun(JUnit4Provider.java:274) [surefire-junit4-2.19.1.jar:2.19.1]
at org.apache.maven.surefire.junit4.JUnit4Provider.executeTestSet(JUnit4Provider.java:238) [surefire-junit4-2.19.1.jar:2.19.1]
at org.apache.maven.surefire.junit4.JUnit4Provider.invoke(JUnit4Provider.java:161) [surefire-junit4-2.19.1.jar:2.19.1]
at org.apache.maven.surefire.booter.ForkedBooter.invokeProviderInSameClassLoader(ForkedBooter.java:290) [surefire-booter-2.19.1.jar:2.19.1]
at org.apache.maven.surefire.booter.ForkedBooter.runSuitesInProcess(ForkedBooter.java:242) [surefire-booter-2.19.1.jar:2.19.1]
at org.apache.maven.surefire.booter.ForkedBooter.main(ForkedBooter.java:121) [surefire-booter-2.19.1.jar:2.19.1]
Tests run: 1, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 1.024 sec - in org.sonar.template.java.checks.MyFirstCustomCheckTest

Results :

Tests run: 2, Failures: 0, Errors: 0, Skipped: 0

[INFO] 
[INFO] --- sonar-packaging-maven-plugin:1.17:sonar-plugin (default-sonar-plugin) @ java-custom-rules-template ---
[INFO] -------------------------------------------------------
[INFO] Plugin definition in update center
[INFO]     Key: javatemplatecustom
[INFO]     Name: Java Template Custom Rules
[INFO]     Description: Empty Template for Custom Rules
[INFO]     Version: 1.0-SNAPSHOT
[INFO]     Entry-point Class: org.sonar.template.java.JavaCustomRulesPlugin
[INFO]     Required Plugins: 
[INFO]     Does the plugin support SonarLint?: true
[INFO]     Use Child-first ClassLoader: false
[INFO]     Base Plugin: 
[INFO]     Homepage URL: 
[INFO]     Minimal SonarQube Version: 5.6
[INFO]     Licensing: 
[INFO]     Organization: 
[INFO]     Organization URL: 
[INFO]     Terms and Conditions: 
[INFO]     Issue Tracker URL: 
[INFO]     Build date: 2017-03-20T10:27:37-0700
[INFO]     Sources URL: 
[INFO]     Developers: 
[INFO]     Dependencies: META-INF/lib/maven-artifact-manager-2.0.7.jar META-INF/lib/cglib-nodep-3.1.jar META-INF/lib/jsr305-1.3.9.jar META-INF/lib/guava-19.0.jar META-INF/lib/sslr-squid-bridge-2.6.1.jar META-INF/lib/maven-project-2.0.7.jar META-INF/lib/maven-model-2.0.7.jar META-INF/lib/maven-repository-metadata-2.0.7.jar META-INF/lib/java-maven-model-4.6.0.8784.jar META-INF/lib/maven-plugin-registry-2.0.7.jar META-INF/lib/classworlds-1.1-alpha-2.jar META-INF/lib/commons-lang-2.6.jar META-INF/lib/maven-artifact-2.0.7.jar META-INF/lib/java-frontend-4.6.0.8784.jar META-INF/lib/maven-settings-2.0.7.jar META-INF/lib/wagon-provider-api-1.0-beta-2.jar META-INF/lib/sslr-core-1.21.jar META-INF/lib/asm-debug-all-5.0.3.jar META-INF/lib/slf4j-api-1.6.2.jar META-INF/lib/maven-profile-2.0.7.jar META-INF/lib/plexus-container-default-1.0-alpha-9-stable-1.jar META-INF/lib/plexus-utils-1.4.1.jar META-INF/lib/picocontainer-2.14.1.jar
[INFO] -------------------------------------------------------
[INFO] Building jar: /home/joaquin/Project/workspace/java-custom-rules-template/target/java-custom-rules-template-1.0-SNAPSHOT.jar
[INFO]  already added, skipping
[INFO] 
[INFO] --- maven-install-plugin:2.5.2:install (default-install) @ java-custom-rules-template ---
[INFO] Installing /home/joaquin/Project/workspace/java-custom-rules-template/target/java-custom-rules-template-1.0-SNAPSHOT.jar to /home/joaquin/.m2/repository/org/sonar/samples/java-custom-rules-template/1.0-SNAPSHOT/java-custom-rules-template-1.0-SNAPSHOT.jar
[INFO] Installing /home/joaquin/Project/workspace/java-custom-rules-template/pom.xml to /home/joaquin/.m2/repository/org/sonar/samples/java-custom-rules-template/1.0-SNAPSHOT/java-custom-rules-template-1.0-SNAPSHOT.pom
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 8.686 s
[INFO] Finished at: 2017-03-20T10:27:38-07:00
[INFO] Final Memory: 24M/218M
[INFO] ------------------------------------------------------------------------


I have downgraded java-checks-testkit version to 4.4.0.8066 and now the test doesn't throw that JSON error. However, the test is still failing:

Tests run: 1, Failures: 0, Errors: 1, Skipped: 0, Time elapsed: 0.832 sec <<< FAILURE! - in org.sonar.template.java.checks.MyFirstCustomCheckTest

test(org.sonar.template.java.checks.MyFirstCustomCheckTest)  Time elapsed: 0.832 sec  <<< ERROR!

java.lang.NoClassDefFoundError: org/assertj/core/api/Fail

at org.sonar.template.java.checks.MyFirstCustomCheckTest.test(MyFirstCustomCheckTest.java:10)

Caused by: java.lang.ClassNotFoundException: org.assertj.core.api.Fail

at org.sonar.template.java.checks.MyFirstCustomCheckTest.test(MyFirstCustomCheckTest.java:10)


Maybe it's a Maven problem, but it throws this error all the time, I've tried updating the project, cleaning and installing again, but it doesn't seem to work. I will keep trying.

Thanks and regards,
Joaquin

jjj...@gmail.com

unread,
Mar 20, 2017, 3:19:57 PM3/20/17
to SonarQube
Hi,

I have added the following dependency and now it works fine:

<dependency>

  <groupId>org.assertj</groupId>

<artifactId>assertj-core</artifactId>

  <version>3.6.2</version>

  <scope>test</scope>

</dependency>


Thank you all for being so helpful,

Joaquin

Tibor Blenessy

unread,
Mar 21, 2017, 4:35:47 AM3/21/17
to jjj...@gmail.com, SonarQube
Hello Joaquin,

great, so as you can see the IOException in the log is not related, though I agree it is confusing and it will be removed.

And you correctly discovered that we forgot to update maven pom file in the custom rule example repo, when we replaced fest-assert library by assertj library. We will update this too.

Thanks for reporting those problems, it helps up to make the analyzer better for everybody.

Regards

Tibor


--
You received this message because you are subscribed to the Google Groups "SonarQube" group.
To unsubscribe from this group and stop receiving emails from it, send an email to sonarqube+...@googlegroups.com.

For more options, visit https://groups.google.com/d/optout.

jjj...@gmail.com

unread,
Mar 21, 2017, 7:08:45 AM3/21/17
to SonarQube, jjj...@gmail.com
Hi Tibor,

You are right, I could have simply ignored that exception because the test wasn't failing and the project build was correct. Sorry I didn't notice before. However, I will continue my development relying on version 4.4.0.8066 of the java-checks-testkit as it's working flawlessly. Thanks for your help.

Regards,
Joaquin

wanglei1...@gmail.com

unread,
May 18, 2017, 2:55:00 AM5/18/17
to SonarQube, jjj...@gmail.com
I have modify my pom.xml, but still it does not work! Plz help me have a look!


<dependency>
<groupId>org.sonarsource.java</groupId>
<artifactId>java-checks-testkit</artifactId>
<!--<version>${java.plugin.version}</version>-->
   <version>>4.4.0.8066</version>
<scope>test</scope>
</dependency>

<dependency>
<groupId>org.assertj</groupId>
<artifactId>assertj-core</artifactId>
<version>3.6.2</version>
<scope>test</scope>
</dependency>




在 2017年3月21日星期二 UTC+8下午7:08:45,jjj...@gmail.com写道:

wanglei1...@gmail.com

unread,
May 18, 2017, 2:55:55 AM5/18/17
to SonarQube, jjj...@gmail.com, wanglei1...@gmail.com
the result returns like this:
14:49:19.468 [Report about progress of Java AST analyzer] INFO  org.sonar.squidbridge.ProgressReport - 1/1 source files have been analyzed
14:49:19.476 [main] WARN  o.s.j.checks.verifier.CheckVerifier - Exception parsing JSON for rule MyFirstCustomRule
java.io.IOException: /org/sonar/l10n/java/rules/squid/MyFirstCustomRule_java.json not found
        at org.sonar.java.checks.verifier.CheckVerifier.getRuleJSON(CheckVerifier.java:251) [java-checks-testkit-4.7.1.9272.jar:na]
        at org.sonar.java.checks.verifier.CheckVerifier.remediationFunction(CheckVerifier.java:228) [java-checks-testkit-4.7.1.9272.jar:na]
        at org.sonar.java.checks.verifier.CheckVerifier.assertMultipleIssue(CheckVerifier.java:201) [java-checks-testkit-4.7.1.9272.jar:na]
        at org.sonar.java.checks.verifier.CheckVerifier.checkIssues(CheckVerifier.java:181) [java-checks-testkit-4.7.1.9272.jar:na]
        at org.sonar.java.checks.verifier.JavaCheckVerifier.scanFile(JavaCheckVerifier.java:274) [java-checks-testkit-4.7.1.9272.jar:na]
        at org.sonar.java.checks.verifier.JavaCheckVerifier.scanFile(JavaCheckVerifier.java:256) [java-checks-testkit-4.7.1.9272.jar:na]
        at org.sonar.java.checks.verifier.JavaCheckVerifier.scanFile(JavaCheckVerifier.java:222) [java-checks-testkit-4.7.1.9272.jar:na]
        at org.sonar.java.checks.verifier.JavaCheckVerifier.verify(JavaCheckVerifier.java:105) [java-checks-testkit-4.7.1.9272.jar:na]
        at org.sonar.samples.java.checks.MyFirstCustomCheckTest.test(MyFirstCustomCheckTest.java:14) [test-classes/:na]
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.8.0_121]
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[na:1.8.0_121]
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:1.8.0_121]
        at java.lang.reflect.Method.invoke(Method.java:498) ~[na:1.8.0_121]
        at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:47) [junit-4.11.jar:na]
        at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12) [junit-4.11.jar:na]
        at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:44) [junit-4.11.jar:na]
        at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17) [junit-4.11.jar:na]
        at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:271) [junit-4.11.jar:na]
        at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:70) [junit-4.11.jar:na]
        at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:50) [junit-4.11.jar:na]
        at org.junit.runners.ParentRunner$3.run(ParentRunner.java:238) [junit-4.11.jar:na]
        at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:63) [junit-4.11.jar:na]
        at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:236) [junit-4.11.jar:na]
        at org.junit.runners.ParentRunner.access$000(ParentRunner.java:53) [junit-4.11.jar:na]


在 2017年5月18日星期四 UTC+8下午2:55:00,wanglei1...@gmail.com写道:

Joaquin Lopez-Cortijo Guijarro

unread,
May 18, 2017, 3:02:26 AM5/18/17
to wanglei1...@gmail.com, SonarQube
I had the same problem, have you check if the tests are Ok? If so, you can simply ignore that exception because the project build will be ok too.

Regards,
Joaquín

pijush...@gmail.com

unread,
Feb 17, 2018, 3:21:09 PM2/17/18
to SonarQube
inside main resource create a json file copying another json file. It will remove that error.
Reply all
Reply to author
Forward
0 new messages