The SonarLint rule is not in effect in Eclipse

Please provide

  • Operating system:
    windows 10 x64
  • IDE name and flavor/env:
    Eclipse 2020-12 (4.18.0)
  • SonarLint plugin version:
    sonarlint 7.4
  • Is connected mode used:
    • Connected to SonarCloud or SonarQube (and which version):
      No

And a thorough description of the problem / question:
In sonarlint rules configuration ,I checked a rule .And i modified the source code to trigger the rule .
Then i analyzed the source code via SonarLint but did not show errors for this rule.


Hello @honghua,

Could you please share with us the full analysis logs ?
Thanks

Hi Damien,

Thank you for your reply. the analysis logs as bellow:

SonarLint processing file /sonarqube-scanner-gradle/src/main/java/com/acme/App.java...
Found 0 issue(s)
Trigger: MANUAL
Clear markers on 0 excluded files
SonarLint processing file /sonarqube-scanner-gradle/src/main/java/com/acme/App.java...
Binary directory '/sonarqube-scanner-gradle/bin/default' was not added because it was not found. Maybe you should enable auto build of your project.
Standalone mode (project not bound)
Starting analysis with configuration:
[
  baseDir: E:\source\bitbucket\gradle-basic
  extraProperties: {sonar.java.target=11, sonar.java.libraries=E:\software\JDK\openlogic-openjdk-11.0.8+10-win-x64\jdk\lib\jrt-fs.jar,C:\Users\shdsd\.gradle\caches\modules-2\files-2.1\com.google.guava\guava\21.0\3a3d111be1be1b745edfa7d91678a12d7ed38709\guava-21.0.jar, sonar.java.source=11, sonar.java.binaries=E:/source/bitbucket/gradle-basic/bin/main, sonar.java.test.binaries=E:/source/bitbucket/gradle-basic/bin/test, sonar.java.test.libraries=E:/source/bitbucket/gradle-basic/bin/main,E:\software\JDK\openlogic-openjdk-11.0.8+10-win-x64\jdk\lib\jrt-fs.jar,C:\Users\shdsd\.gradle\caches\modules-2\files-2.1\com.google.guava\guava\21.0\3a3d111be1be1b745edfa7d91678a12d7ed38709\guava-21.0.jar,C:\Users\shdsd\.gradle\caches\modules-2\files-2.1\junit\junit\4.12\2973d150c0dc1fefe998f834810d68f278ea58ec\junit-4.12.jar,C:\Users\shdsd\.gradle\caches\modules-2\files-2.1\org.hamcrest\hamcrest-core\1.3\42a25dc3219429f0e5d060061f71acb49bf010a0\hamcrest-core-1.3.jar}
  moduleKey: null
  excludedRules: [java:S100, java:S101, java:S106, java:S1065, java:S1066, java:S1068, java:S107, java:S1075, java:S108, java:S110, java:S1104, java:S1110, java:S1111, java:S1113, java:S1114, java:S1116, java:S1117, java:S1118, java:S1119, java:S112, java:S1121, java:S1123, java:S1124, java:S1125, java:S1126, java:S1128, java:S1130, java:S1133, java:S1134, java:S1135, java:S114, java:S1141, java:S1143, java:S1144, java:S1149, java:S115, java:S1150, java:S1153, java:S1155, java:S1157, java:S1158, java:S116, java:S1161, java:S1163, java:S1165, java:S1168, java:S117, java:S1170, java:S1171, java:S1172, java:S1174, java:S1175, java:S1181, java:S1182, java:S1185, java:S1186, java:S119, java:S1190, java:S1191, java:S1192, java:S1193, java:S1195, java:S1197, java:S1199, java:S120, java:S1201, java:S1206, java:S1210, java:S1214, java:S1215, java:S1217, java:S1219, java:S1220, java:S1221, java:S1223, java:S1226, java:S125, java:S1264, java:S127, java:S128, java:S1301, java:S131, java:S1317, java:S1319, java:S135, java:S1444, java:S1450, java:S1452, java:S1479, java:S1481, java:S1488, java:S1596, java:S1598, java:S1602, java:S1604, java:S1607, java:S1610, java:S1611, java:S1612, java:S1640, java:S1643, java:S1656, java:S1659, java:S1700, java:S1710, java:S1751, java:S1764, java:S1844, java:S1845, java:S1849, java:S1854, java:S1858, java:S1860, java:S1862, java:S1871, java:S1872, java:S1874, java:S1905, java:S1940, java:S1948, java:S1989, java:S1994, java:S2053, java:S2055, java:S2060, java:S2061, java:S2062, java:S2065, java:S2066, java:S2093, java:S2094, java:S2095, java:S2097, java:S2109, java:S2110, java:S2111, java:S2112, java:S2114, java:S2115, java:S2116, java:S2118, java:S2119, java:S2121, java:S2122, java:S2123, java:S2127, java:S2129, java:S2130, java:S2131, java:S2133, java:S2134, java:S2139, java:S2140, java:S2142, java:S2147, java:S2151, java:S2153, java:S2154, java:S2157, java:S2159, java:S2160, java:S2165, java:S2166, java:S2167, java:S2168, java:S2175, java:S2176, java:S2177, java:S2178, java:S2183, java:S2184, java:S2185, java:S2186, java:S2187, java:S2188, java:S2189, java:S2200, java:S2201, java:S2204, java:S2209, java:S2222, java:S2225, java:S2226, java:S2229, java:S2230, java:S2232, java:S2234, java:S2235, java:S2236, java:S2251, java:S2252, java:S2254, java:S2259, java:S2272, java:S2273, java:S2274, java:S2275, java:S2276, java:S2293, java:S2326, java:S2386, java:S2387, java:S2388, java:S2390, java:S2437, java:S2438, java:S2440, java:S2441, java:S2442, java:S2445, java:S2446, java:S2447, java:S2479, java:S2583, java:S2589, java:S2629, java:S2637, java:S2638, java:S2639, java:S2647, java:S2674, java:S2675, java:S2676, java:S2677, java:S2681, java:S2689, java:S2692, java:S2695, java:S2696, java:S2699, java:S2718, java:S2737, java:S2755, java:S2761, java:S2786, java:S2789, java:S2864, java:S2885, java:S2886, java:S2924, java:S2925, java:S2970, java:S2975, java:S3008, java:S3010, java:S3011, java:S3012, java:S3014, java:S3020, java:S3034, java:S3038, java:S3039, java:S3042, java:S3046, java:S3064, java:S3065, java:S3066, java:S3067, java:S3077, java:S3078, java:S3252, java:S3305, java:S3329, java:S3346, java:S3358, java:S3398, java:S3400, java:S3415, java:S3416, java:S3436, java:S3457, java:S3516, java:S3518, java:S3551, java:S3577, java:S3599, java:S3626, java:S3631, java:S3655, java:S3740, java:S3751, java:S3753, java:S3776, java:S3824, java:S3864, java:S3878, java:S3923, java:S3958, java:S3959, java:S3972, java:S3973, java:S3981, java:S3984, java:S3985, java:S3986, java:S4032, java:S4034, java:S4042, java:S4065, java:S4087, java:S4143, java:S4144, java:S4165, java:S4201, java:S4274, java:S4275, java:S4276, java:S4347, java:S4348, java:S4349, java:S4351, java:S4423, java:S4425, java:S4426, java:S4433, java:S4449, java:S4454, java:S4488, java:S4517, java:S4524, java:S4601, java:S4602, java:S4635, java:S4682, java:S4684, java:S4719, java:S4738, java:S4830, java:S4838, java:S4925, java:S4929, java:S4970, java:S4973, java:S4977, java:S5164, java:S5261, java:S5301, java:S5329, java:S5344, java:S5361, java:S5411, java:S5413, java:S5445, java:S5527, java:S5542, java:S5547, java:S5659, java:S5663, java:S5664, java:S5665, java:S5669, java:S5679, java:S5738, java:S5776, java:S5777, java:S5778, java:S5779, java:S5783, java:S5785, java:S5786, java:S5790, java:S5803, java:S5808, java:S5810, java:S5826, java:S5831, java:S5833, java:S5838, java:S5841, java:S5842, java:S5843, java:S5845, java:S5846, java:S5850, java:S5853, java:S5854, java:S5855, java:S5856, java:S5857, java:S5860, java:S5863, java:S5866, java:S5868, java:S5869, java:S5876, java:S5917, java:S5958, java:S5960, java:S5961, java:S5967, java:S5969, java:S5973, java:S5976, java:S5993, java:S5994, java:S5996, java:S5998, java:S6001, java:S6002, java:S6019, java:S6035, java:S6068, java:S6070, java:S6103, java:S6104, java:S6126, java:S6201, java:S6202, java:S6203, java:S6204, java:S6205, java:S6206, java:S6207, java:S6208, java:S6209, java:S6213, java:S6216, java:S6217, java:S6218, java:S6219, java:S6301, java:S6355, java:S6373, java:S6374, java:S6376, java:S6377, java:S899]
  includedRules: []
  ruleParameters: {}
  inputFiles: [
    file:/E:/source/bitbucket/gradle-basic/src/main/java/com/acme/App.java (UTF-8)
  ]
]

Creating transient module container
Start analysis
Index files
Language of file 'file:/E:/source/bitbucket/gradle-basic/src/main/java/com/acme/App.java' is detected to be 'Java'
1 file indexed
Execute Sensor: JavaSensor
No workDir in SonarLint
Configured Java source version (sonar.java.source): 11
JavaClasspath initialization
Property 'sonar.java.jdkHome' resolved with:
[]
Property 'sonar.java.libraries' resolved with:
[E:\software\JDK\openlogic-openjdk-11.0.8+10-win-x64\jdk\lib\jrt-fs.jar,
C:\Users\shdsd\.gradle\caches\modules-2\files-2.1\com.google.guava\guava\21.0\3a3d111be1be1b745edfa7d91678a12d7ed38709\guava-21.0.jar]
JavaClasspath initialization (done) | time=1ms
JavaTestClasspath initialization
Property 'sonar.java.jdkHome' resolved with:
[]
Property 'sonar.java.test.libraries' resolved with:
[E:\source\bitbucket\gradle-basic\bin\main,
E:\software\JDK\openlogic-openjdk-11.0.8+10-win-x64\jdk\lib\jrt-fs.jar,
C:\Users\shdsd\.gradle\caches\modules-2\files-2.1\com.google.guava\guava\21.0\3a3d111be1be1b745edfa7d91678a12d7ed38709\guava-21.0.jar,
C:\Users\shdsd\.gradle\caches\modules-2\files-2.1\junit\junit\4.12\2973d150c0dc1fefe998f834810d68f278ea58ec\junit-4.12.jar,
C:\Users\shdsd\.gradle\caches\modules-2\files-2.1\org.hamcrest\hamcrest-core\1.3\42a25dc3219429f0e5d060061f71acb49bf010a0\hamcrest-core-1.3.jar]
JavaTestClasspath initialization (done) | time=0ms
Java "Main" source files AST scan
1 source file to be analyzed
1/1 source file has been analyzed
Java "Main" source files AST scan (done) | time=18ms
No "Test" source files to scan.
No "Generated" source files to scan.
Execute Sensor: HTML
Execute Sensor: Sonar Secrets Detection Sensor
'XML Sensor' skipped because there is no related files in the current project
'PHP sensor' skipped because there is no related files in the current project
'Analyzer for "php.ini" files' skipped because there is no related files in the current project
'Python Sensor' skipped because there is no related files in the current project
Found 0 issue(s)
Done in 64 ms

Hello Chen,

Sorry for the late response. I see this line which might be important:

Binary directory ‘/sonarqube-scanner-gradle/bin/default’ was not added because it was not found. Maybe you should enable auto build of your project.

There is an option in Eclipse in Project > Build Automatically, could you try to enable it ?

Hi Damien,

Thank you for your reply.
Project > Build Automatically has been enable ,but it does’t work.

Thanks Chen,

I managed to reproduce this problem. It looks like the rule does not raise an issue on variable declarations, only on assignment statements. I don’t get any issue when doing:

int i = 0;
int j =+ i;

But I get an issue when doing:

int i = 0;
int j;
j =+ i;

I will forward this to the team in charge. Thanks for reporting!

Hello @honghua,

Just to clarify, there is nothing wrong here. This rule is simply not targeting what you wrote. The rule targets wrong usage and potential mistakes when trying to use += and typing =+ instead, which can only occur in assignments.

For an assignment, this error has consequences:

int i = 42;

i += 1;   // i = 43
i =+ 1;   // i = 1, which is not necessarily expected and therefore an issue is reported

For a variable initialization, there are no consequences, since the opposite does not compile!

int i =+ 1;   // i = 1
int j += 42;  // does not compile, why reporting?

All in all, it seems to me that you just tested the rule with the wrong code. :slight_smile:

Cheers,
Michael

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.