Rules applied in SonarLint but not in SonarQube

SonarQube version 8.5 analyzing Java with SonarWay quality profile
Spring Tool Suite 3.9.5.RELEASE based on Eclipse Photon 4.8.0
SonarLint for Eclipse 5.2.1.18852

I have noticed some discrepancies between SonarLint and SonarQube. Sometimes an issue shows up in SonarLint and not in SonarQube. SonarLint gets its rules from our SonarQube server.

An example is final HashMap<BankAccountType, AccountType> map = new HashMap<>(); where BankAccountType is an enum. SonarLint invokes rule S1640, Maps with keys that are enum values should be replaced with EnumMap. But SonarQube does not point it out. The rule is active in SonarQube’s SonarWay rule set.

SonarLint shows many-many issues that SonarQube does not, from Critical down to Info.

None of the code is using @SuppressWarnings to cancel a rule. Some issues (but certainly not all) have been resolved as “false positive” or “won’t fix” in SQ, and this info has not made it into SonarLint.

Does anyone have suggestions for where I should look? Is there some SQ setting that I don’t know about? Is this an “old code” vs. “new code” issue? The project is legacy code that’s been around since before we started using SonarQube.

Fred Robinson

Hi @Fred_Robinson

Probably unrelated, but any reason why you are not using the latest release?

I understand you are using connected mode, right. Is your binding up to date? SonarLint is caching locally data coming from the server (rules configuration, analyzers, …) so if you don’t update the binding from time to time, you may have differences.

This make me think the connected mode is not set up properly.

Please go to the SonarLint Console, enable verbose and analysis logs. Clear the console.

Open the view “SonarLint Bindings” and right click on your connection to trigger an “update all project bindings”.
Copy the logs in the SonarLint Console, and paste them in this thread (ensure they do not contain information that you consider as sensitive)
Clear the console.

Then trigger an analysis on a file where you see differences with SonarQube (right click on the file -> SonarLint -> analyze, or simply close/reopen the file).
Copy the logs produced also in this thread.

Thanks

Thanks for the reply. I’m using that version of SonarLint because I haven’t bothered looking for a newer version. We tend to rely on SonarQube to pick apart our code; SonarLint is fairly new to us. I’ll update it anyway.

At any rate the problem isn’t with SonarLint, it’s with SonarQube. SonarQube is not picking up on issues that I think it should be, such as the HashMap/EnumMap thing described above. The rules are active in SonarQube, but I can’t find anything that might prevent them from being applied in a SonarQube analysis. I am positive that I have not marked them as “Resolved” in SQ, because it’s easy enough to fix them. Resolving in SQ is a last-ditch effort, primarily for false positives.

Addendum: I upgraded SonarLint to 5.5.1 and it started throwing AbstractMethodError exceptions. Uninstalled and reinstalled it, same thing. Maybe because my STS/Eclipse is kind of old. It will remain uninstalled for now.

Fred Robinson

To me it sounds like a type resolution problem. To report the issue on EnumMap, our analyzer has to understand that BankAccountType is an enum.

What is the scanner you are using? Maven? (mvn sonar:sonar) Are you manually passing properties like sonar.java.libraries or sonar.java.binaries? Is you project compiled before running the analysis?
Do you see any log during the analysis about type resolution issue?

Would you mind providing the full stacktrace of the AbstractMethodError? You might have to look at Eclipse error logs view.

We are using Maven, launched from Jenkins. The project is built with the goals clean install sonar:sonar.

BankAccountType comes from a JAR produced by another project. This JAR is a dependency of the project in question. Can you provide pointers to pages that explain how and where to use sonar.java.libraries and sonar.java.binaries? In the mean time, I’ll do some looking around myself.

Here is one of the errors from the Error Log. The error popped up when STS was started, and whenever a code module was re-scanned by SonarLint.

Open for error log

eclipse.buildId=3.9.5.201807031753-RELEASE-e48
java.version=1.8.0_201
java.vendor=Oracle Corporation
BootLoader constants: OS=win32, ARCH=x86_64, WS=win32, NL=en_US
Framework arguments: -product org.springsource.sts.ide -product org.springsource.sts.ide -product org.springsource.sts.ide -product org.springsource.sts.ide -product org.springsource.sts.ide -product org.springsource.sts.ide -product org.springsource.sts.ide -product org.springsource.sts.ide
Command-line arguments: -os win32 -ws win32 -arch x86_64 -product org.springsource.sts.ide -product org.springsource.sts.ide -product org.springsource.sts.ide -product org.springsource.sts.ide -product org.springsource.sts.ide -product org.springsource.sts.ide -product org.springsource.sts.ide -data file:/C:/Workspaces/Fred/frontend/ -product org.springsource.sts.ide

org.eclipse.ui.workbench
Error
Fri Nov 20 16:11:52 EST 2020
Problems occurred when invoking code from plug-in: “org.eclipse.ui.workbench”.

java.lang.AbstractMethodError
at org.eclipse.ui.internal.WorkbenchPage$19.run(WorkbenchPage.java:5109)
at org.eclipse.core.runtime.SafeRunner.run(SafeRunner.java:42)
at org.eclipse.ui.internal.WorkbenchPage.firePartDeactivated(WorkbenchPage.java:5106)
at org.eclipse.ui.internal.WorkbenchPage.access$21(WorkbenchPage.java:5087)
at org.eclipse.ui.internal.WorkbenchPage$E4PartListener.partDeactivated(WorkbenchPage.java:226)
at org.eclipse.e4.ui.internal.workbench.PartServiceImpl$4.run(PartServiceImpl.java:266)
at org.eclipse.core.runtime.SafeRunner.run(SafeRunner.java:42)
at org.eclipse.e4.ui.internal.workbench.PartServiceImpl.firePartDeactivated(PartServiceImpl.java:263)
at org.eclipse.e4.ui.internal.workbench.PartServiceImpl.activate(PartServiceImpl.java:748)
at org.eclipse.e4.ui.internal.workbench.PartServiceImpl.setPart(PartServiceImpl.java:218)
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.eclipse.e4.core.internal.di.MethodRequestor.execute(MethodRequestor.java:55)
at org.eclipse.e4.core.internal.contexts.ContextObjectSupplier$ContextInjectionListener.update(ContextObjectSupplier.java:90)
at org.eclipse.e4.core.internal.contexts.TrackableComputationExt.update(TrackableComputationExt.java:111)
at org.eclipse.e4.core.internal.contexts.EclipseContext.processScheduled(EclipseContext.java:362)
at org.eclipse.e4.core.internal.contexts.EclipseContext.set(EclipseContext.java:377)
at org.eclipse.e4.core.internal.contexts.EclipseContext.activate(EclipseContext.java:681)
at org.eclipse.e4.ui.internal.workbench.swt.ShellActivationListener$2.run(ShellActivationListener.java:127)
at org.eclipse.core.runtime.SafeRunner.run(SafeRunner.java:42)
at org.eclipse.e4.ui.internal.workbench.swt.ShellActivationListener.activate(ShellActivationListener.java:123)
at org.eclipse.e4.ui.internal.workbench.swt.ShellActivationListener.handleEvent(ShellActivationListener.java:73)
at org.eclipse.swt.widgets.EventTable.sendEvent(EventTable.java:86)
at org.eclipse.swt.widgets.Display.filterEvent(Display.java:1190)
at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1051)
at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1076)
at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1061)
at org.eclipse.swt.widgets.Decorations.WM_ACTIVATE(Decorations.java:1540)
at org.eclipse.swt.widgets.Shell.WM_ACTIVATE(Shell.java:2199)
at org.eclipse.swt.widgets.Control.windowProc(Control.java:4762)
at org.eclipse.swt.widgets.Canvas.windowProc(Canvas.java:345)
at org.eclipse.swt.widgets.Decorations.windowProc(Decorations.java:1499)
at org.eclipse.swt.widgets.Shell.windowProc(Shell.java:2159)
at org.eclipse.swt.widgets.Display.windowProc(Display.java:4757)
at org.eclipse.swt.internal.win32.OS.BringWindowToTop(Native Method)
at org.eclipse.swt.widgets.Decorations.bringToTop(Decorations.java:208)
at org.eclipse.swt.widgets.Shell.open(Shell.java:1250)
at org.eclipse.jface.window.Window.open(Window.java:790)
at org.eclipse.ui.internal.statushandlers.InternalDialog.open(InternalDialog.java:311)
at org.eclipse.ui.internal.statushandlers.WorkbenchStatusDialogManagerImpl.doAddStatusAdapter(WorkbenchStatusDialogManagerImpl.java:270)
at org.eclipse.ui.internal.statushandlers.WorkbenchStatusDialogManagerImpl.addStatusAdapter(WorkbenchStatusDialogManagerImpl.java:197)
at org.eclipse.ui.statushandlers.WorkbenchStatusDialogManager.addStatusAdapter(WorkbenchStatusDialogManager.java:158)
at org.eclipse.ui.statushandlers.WorkbenchErrorHandler.showStatusAdapter(WorkbenchErrorHandler.java:80)
at org.eclipse.ui.statushandlers.WorkbenchErrorHandler.handle(WorkbenchErrorHandler.java:49)
at org.eclipse.ui.internal.ide.IDEWorkbenchErrorHandler.handle(IDEWorkbenchErrorHandler.java:104)
at org.eclipse.ui.internal.WorkbenchErrorHandlerProxy.handle(WorkbenchErrorHandlerProxy.java:31)
at org.eclipse.ui.statushandlers.StatusManager.handle(StatusManager.java:213)
at org.eclipse.ui.internal.JFaceUtil$1.show(JFaceUtil.java:62)
at org.eclipse.jface.util.SafeRunnable.handleException(SafeRunnable.java:63)
at org.eclipse.core.runtime.SafeRunner.handleException(SafeRunner.java:75)
at org.eclipse.core.runtime.SafeRunner.run(SafeRunner.java:46)
at org.eclipse.ui.internal.WorkbenchPage.firePartDeactivated(WorkbenchPage.java:5106)
at org.eclipse.ui.internal.WorkbenchPage.access$21(WorkbenchPage.java:5087)
at org.eclipse.ui.internal.WorkbenchPage$E4PartListener.partDeactivated(WorkbenchPage.java:226)
at org.eclipse.e4.ui.internal.workbench.PartServiceImpl$4.run(PartServiceImpl.java:266)
at org.eclipse.core.runtime.SafeRunner.run(SafeRunner.java:42)
at org.eclipse.e4.ui.internal.workbench.PartServiceImpl.firePartDeactivated(PartServiceImpl.java:263)
at org.eclipse.e4.ui.internal.workbench.PartServiceImpl.activate(PartServiceImpl.java:748)
at org.eclipse.e4.ui.internal.workbench.PartServiceImpl.activate(PartServiceImpl.java:681)
at org.eclipse.e4.ui.internal.workbench.swt.AbstractPartRenderer.activate(AbstractPartRenderer.java:94)
at org.eclipse.e4.ui.workbench.renderers.swt.ContributedPartRenderer.lambda$0(ContributedPartRenderer.java:60)
at org.eclipse.swt.widgets.EventTable.sendEvent(EventTable.java:86)
at org.eclipse.swt.widgets.Display.sendEvent(Display.java:4118)
at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1052)
at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1076)
at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1061)
at org.eclipse.swt.widgets.Shell.setActiveControl(Shell.java:1514)
at org.eclipse.swt.widgets.Shell.WM_MOUSEACTIVATE(Shell.java:2344)
at org.eclipse.swt.widgets.Control.windowProc(Control.java:4809)
at org.eclipse.swt.widgets.Canvas.windowProc(Canvas.java:345)
at org.eclipse.swt.widgets.Decorations.windowProc(Decorations.java:1499)
at org.eclipse.swt.widgets.Shell.windowProc(Shell.java:2159)
at org.eclipse.swt.widgets.Display.windowProc(Display.java:4765)
at org.eclipse.swt.internal.win32.OS.DefWindowProcW(Native Method)
at org.eclipse.swt.internal.win32.OS.DefWindowProc(OS.java:2298)
at org.eclipse.swt.widgets.Scrollable.callWindowProc(Scrollable.java:88)
at org.eclipse.swt.widgets.Control.windowProc(Control.java:4863)
at org.eclipse.swt.widgets.Display.windowProc(Display.java:4765)
at org.eclipse.swt.internal.win32.OS.DefWindowProcW(Native Method)
at org.eclipse.swt.internal.win32.OS.DefWindowProc(OS.java:2298)
at org.eclipse.swt.widgets.Scrollable.callWindowProc(Scrollable.java:88)
at org.eclipse.swt.widgets.Control.windowProc(Control.java:4863)
at org.eclipse.swt.widgets.Display.windowProc(Display.java:4765)
at org.eclipse.swt.internal.win32.OS.DefWindowProcW(Native Method)
at org.eclipse.swt.internal.win32.OS.DefWindowProc(OS.java:2298)
at org.eclipse.swt.widgets.Scrollable.callWindowProc(Scrollable.java:88)
at org.eclipse.swt.widgets.Control.windowProc(Control.java:4863)
at org.eclipse.swt.widgets.Display.windowProc(Display.java:4765)
at org.eclipse.swt.internal.win32.OS.DefWindowProcW(Native Method)
at org.eclipse.swt.internal.win32.OS.DefWindowProc(OS.java:2298)
at org.eclipse.swt.widgets.Scrollable.callWindowProc(Scrollable.java:88)
at org.eclipse.swt.widgets.Control.windowProc(Control.java:4863)
at org.eclipse.swt.widgets.Display.windowProc(Display.java:4765)
at org.eclipse.swt.internal.win32.OS.DefWindowProcW(Native Method)
at org.eclipse.swt.internal.win32.OS.DefWindowProc(OS.java:2298)
at org.eclipse.swt.widgets.Scrollable.callWindowProc(Scrollable.java:88)
at org.eclipse.swt.widgets.Control.windowProc(Control.java:4863)
at org.eclipse.swt.widgets.Display.windowProc(Display.java:4765)
at org.eclipse.swt.internal.win32.OS.DefWindowProcW(Native Method)
at org.eclipse.swt.internal.win32.OS.DefWindowProc(OS.java:2298)
at org.eclipse.swt.widgets.Scrollable.callWindowProc(Scrollable.java:88)
at org.eclipse.swt.widgets.Control.windowProc(Control.java:4863)
at org.eclipse.swt.widgets.Display.windowProc(Display.java:4765)
at org.eclipse.swt.internal.win32.OS.DefWindowProcW(Native Method)
at org.eclipse.swt.internal.win32.OS.DefWindowProc(OS.java:2298)
at org.eclipse.swt.widgets.Scrollable.callWindowProc(Scrollable.java:88)
at org.eclipse.swt.widgets.Control.windowProc(Control.java:4863)
at org.eclipse.swt.widgets.Display.windowProc(Display.java:4765)
at org.eclipse.swt.internal.win32.OS.DefWindowProcW(Native Method)
at org.eclipse.swt.internal.win32.OS.DefWindowProc(OS.java:2298)
at org.eclipse.swt.widgets.Scrollable.callWindowProc(Scrollable.java:88)
at org.eclipse.swt.widgets.Control.windowProc(Control.java:4863)
at org.eclipse.swt.widgets.Display.windowProc(Display.java:4765)
at org.eclipse.swt.internal.win32.OS.DefWindowProcW(Native Method)
at org.eclipse.swt.internal.win32.OS.DefWindowProc(OS.java:2298)
at org.eclipse.swt.widgets.Scrollable.callWindowProc(Scrollable.java:88)
at org.eclipse.swt.widgets.Control.windowProc(Control.java:4863)
at org.eclipse.swt.widgets.Display.windowProc(Display.java:4765)
at org.eclipse.swt.internal.win32.OS.DefWindowProcW(Native Method)
at org.eclipse.swt.internal.win32.OS.DefWindowProc(OS.java:2298)
at org.eclipse.swt.widgets.Scrollable.callWindowProc(Scrollable.java:88)
at org.eclipse.swt.widgets.Control.windowProc(Control.java:4863)
at org.eclipse.swt.widgets.Display.windowProc(Display.java:4765)
at org.eclipse.swt.internal.win32.OS.DefWindowProcW(Native Method)
at org.eclipse.swt.internal.win32.OS.DefWindowProc(OS.java:2298)
at org.eclipse.swt.widgets.Scrollable.callWindowProc(Scrollable.java:88)
at org.eclipse.swt.widgets.Control.windowProc(Control.java:4863)
at org.eclipse.swt.widgets.Display.windowProc(Display.java:4765)
at org.eclipse.swt.internal.win32.OS.DefWindowProcW(Native Method)
at org.eclipse.swt.internal.win32.OS.DefWindowProc(OS.java:2298)
at org.eclipse.swt.widgets.Scrollable.callWindowProc(Scrollable.java:88)
at org.eclipse.swt.widgets.Control.windowProc(Control.java:4863)
at org.eclipse.swt.widgets.Display.windowProc(Display.java:4765)
at org.eclipse.swt.internal.win32.OS.DefWindowProcW(Native Method)
at org.eclipse.swt.internal.win32.OS.DefWindowProc(OS.java:2298)
at org.eclipse.swt.widgets.Scrollable.callWindowProc(Scrollable.java:88)
at org.eclipse.swt.widgets.Control.windowProc(Control.java:4863)
at org.eclipse.swt.widgets.Display.windowProc(Display.java:4765)
at org.eclipse.swt.internal.win32.OS.DefWindowProcW(Native Method)
at org.eclipse.swt.internal.win32.OS.DefWindowProc(OS.java:2298)
at org.eclipse.swt.widgets.Scrollable.callWindowProc(Scrollable.java:88)
at org.eclipse.swt.widgets.Control.windowProc(Control.java:4863)
at org.eclipse.swt.widgets.Display.windowProc(Display.java:4765)
at org.eclipse.swt.internal.win32.OS.DefWindowProcW(Native Method)
at org.eclipse.swt.internal.win32.OS.DefWindowProc(OS.java:2298)
at org.eclipse.swt.widgets.Scrollable.callWindowProc(Scrollable.java:88)
at org.eclipse.swt.widgets.Control.windowProc(Control.java:4863)
at org.eclipse.swt.widgets.Canvas.windowProc(Canvas.java:345)
at org.eclipse.swt.widgets.Display.windowProc(Display.java:4765)
at org.eclipse.swt.internal.win32.OS.DefWindowProcW(Native Method)
at org.eclipse.swt.internal.win32.OS.DefWindowProc(OS.java:2298)
at org.eclipse.swt.widgets.Scrollable.callWindowProc(Scrollable.java:88)
at org.eclipse.swt.widgets.Control.windowProc(Control.java:4863)
at org.eclipse.swt.widgets.Canvas.windowProc(Canvas.java:345)
at org.eclipse.swt.widgets.Display.windowProc(Display.java:4765)
at org.eclipse.swt.internal.win32.OS.PeekMessageW(Native Method)
at org.eclipse.swt.internal.win32.OS.PeekMessage(OS.java:2787)
at org.eclipse.swt.widgets.Display.readAndDispatch(Display.java:3529)
at org.eclipse.e4.ui.internal.workbench.swt.PartRenderingEngine$5.run(PartRenderingEngine.java:1170)
at org.eclipse.core.databinding.observable.Realm.runWithDefault(Realm.java:336)
at org.eclipse.e4.ui.internal.workbench.swt.PartRenderingEngine.run(PartRenderingEngine.java:1059)
at org.eclipse.e4.ui.internal.workbench.E4Workbench.createAndRunUI(E4Workbench.java:153)
at org.eclipse.ui.internal.Workbench.lambda$3(Workbench.java:667)
at org.eclipse.core.databinding.observable.Realm.runWithDefault(Realm.java:336)
at org.eclipse.ui.internal.Workbench.createAndRunWorkbench(Workbench.java:597)
at org.eclipse.ui.PlatformUI.createAndRunWorkbench(PlatformUI.java:148)
at org.eclipse.ui.internal.ide.application.IDEApplication.start(IDEApplication.java:152)
at org.eclipse.equinox.internal.app.EclipseAppHandle.run(EclipseAppHandle.java:196)
at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.runApplication(EclipseAppLauncher.java:134)
at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.start(EclipseAppLauncher.java:104)
at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:388)
at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:243)
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.eclipse.equinox.launcher.Main.invokeFramework(Main.java:656)
at org.eclipse.equinox.launcher.Main.basicRun(Main.java:592)
at org.eclipse.equinox.launcher.Main.run(Main.java:1498)

Fred Robinson

Update. I checked the effective POM and found

<sonar.java.libraries>**\*.jar</sonar.java.libraries>
<sonar.java.binaries>**\classes</sonar.java.binaries>

Fred Robinson

If you are using the Maven plugin to run the SonarQube analysis, you should not try to define yourself path to dependencies. The plugin will compute them itself by looking at Maven dependencies. I suggest to find where those properties are defined and remove them.

I managed to reproduce, and created a ticket:

Thanks for the feedback!

I jiggered the projects and made these two properties go away. It had no effect on the SonarQube analysis.

I’m missing something, but I don’t know enough to be able to explain what it is.

Fred Robinson