SonarLint throwing no class definition found for apache commons logging class

Hi,
I have my own custom sonar plugin which call Apache Hive for reading its properties and Apache Hive use commons logging class. (commons-logging )
As SonarQube plugin mandates not to include any logging jars as part of plugin, hence in my plugin pom it is in provided scope.
When I run the scan (via command line or Jenkins) the plugin is perfectly fine without any problem an d is able to do it’s job.

Today I have installed SonarLint Eclipse plugin version 5.2 and it started throwing the following exception after connecting to my SonarQube server (Version 7.7):

Caused by: java.lang.NoClassDefFoundError: org/apache/commons/logging/LogFactory
at org.apache.hadoop.hive.conf.SystemVariables.(SystemVariables.java:33)
at org.apache.hadoop.hive.conf.HiveConf$ConfVars.(HiveConf.java:2328)
at org.apache.hadoop.hive.conf.HiveConf$ConfVars.(HiveConf.java:2303)
at org.apache.hadoop.hive.conf.HiveConf$ConfVars.(HiveConf.java:222)
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 java.lang.Class.getEnumConstantsShared(Class.java:3320)
at java.lang.System$2.getEnumConstantsShared(System.java:1249)
at java.util.EnumSet.getUniverse(EnumSet.java:407)
at java.util.EnumSet.noneOf(EnumSet.java:110)
at java.util.EnumSet.allOf(EnumSet.java:131)
at com.a.b.c.loadMandatoryProperties(HivePropertiesRule.java:271)
at com.a.b.c.Rule.(HivePropertiesRule.java:92)
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
at java.lang.Class.newInstance(Class.java:442)
at org.sonar.api.batch.rule.Checks.instantiate(Checks.java:160)
at org.sonar.api.batch.rule.Checks.addAnnotatedChecks(Checks.java:136)
at org.sonar.java.SonarComponents.registerCheckClasses(SonarComponents.java:183)
at org.sonar.java.SonarComponents.(SonarComponents.java:132)
at org.sonar.java.SonarComponents.(SonarComponents.java:98)
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
at org.sonarsource.sonarlint.shaded.org.picocontainer.injectors.AbstractInjector.newInstance(AbstractInjector.java:145)
at org.sonarsource.sonarlint.shaded.org.picocontainer.injectors.ConstructorInjector$1.run(ConstructorInjector.java:342)
at org.sonarsource.sonarlint.shaded.org.picocontainer.injectors.AbstractInjector$ThreadLocalCyclicDependencyGuard.observe(AbstractInjector.java:270)
at org.sonarsource.sonarlint.shaded.org.picocontainer.injectors.ConstructorInjector.getComponentInstance(ConstructorInjector.java:364)
at org.sonarsource.sonarlint.shaded.org.picocontainer.injectors.AbstractInjectionFactory$LifecycleAdapter.getComponentInstance(AbstractInjectionFactory.java:56)
at org.sonarsource.sonarlint.shaded.org.picocontainer.behaviors.AbstractBehavior.getComponentInstance(AbstractBehavior.java:64)
at org.sonarsource.sonarlint.shaded.org.picocontainer.behaviors.Stored.getComponentInstance(Stored.java:91)
at org.sonarsource.sonarlint.shaded.org.picocontainer.DefaultPicoContainer.getInstance(DefaultPicoContainer.java:699)
at org.sonarsource.sonarlint.shaded.org.picocontainer.DefaultPicoContainer.getComponent(DefaultPicoContainer.java:647)
at org.sonarsource.sonarlint.core.container.ComponentContainer$ExtendedDefaultPicoContainer.getComponent(ComponentContainer.java:57)
… 49 more
Caused by: java.lang.ClassNotFoundException: org.apache.commons.logging.LogFactory
at org.sonar.classloader.ParentFirstStrategy.loadClass(ParentFirstStrategy.java:39)
at org.sonar.classloader.ClassRealm.loadClass(ClassRealm.java:87)
at org.sonar.classloader.ClassRealm.loadClass(ClassRealm.java:76)
… 88 more

Below is snipped of code in my plugin, from which error is thrown

ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
try {
Thread.currentThread().setContextClassLoader(getClass().getClassLoader());
//Exception is thrown from below line
EnumSet.allOf(HiveConf.ConfVars.class).forEach(hivePropName -> {

      }

     }

Also pasting the Hive code that is throwing the exception

public class SystemVariables {

The below line is throwing exception*
private static final Log l4j = LogFactory.getLog(SystemVariables.class);
protected static Pattern varPat = Pattern.compile("\$\{[^\}\$\u0020]+\}");
private static final SystemVariables INSTANCE = new SystemVariables();
private static final Map<String, VariableCoercion> COERCIONS =
ImmutableMap.<String, VariableCoercion>builder()
.put(JavaIOTmpdirVariableCoercion.INSTANCE.getName(), JavaIOTmpdirVariableCoercion.INSTANCE)
.build();

Any help would be appreciated. Thanks in advance.

Hi,

SonarLint is not designed to run all SonarQube plugins. Only official SonarSource analyzers + custom rules plugins are supported. You should change your plugin MANIFEST to remove the sonarLintSupported flag so that it won’t get downloaded by SonarLint, and so you can use connected mode.

Hi Julien,
I really appreciate your quick reply.
Would it be possible for you, to explain me the following:

  1. What is the cause of this issue?
  2. Is there any workaround that I can do in my plugin, so that SonarlLint can use the rules from my plugin and apply on the code.?

SonarLint doesn’t provide commons-logging at runtime, contrary to SonarQube.

Except if your plugin is made of custom rules for official SonarSource analyzers, we can’t support you, sorry.

Thanks Julien

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