RulesDefinition missing method on SonarQube 9.0

Upgrading sonarqube from 8.9.x to 9.0.x causes a plugin to fail:

2021.08.19 10:12:32 ERROR web[][o.s.s.p.Platform] Background initialization failed. Stopping SonarQube
java.lang.NoSuchMethodError: org.sonar.api.server.rule.RulesDefinition$NewRule.setEffortToFixDescription(Ljava/lang/String;)Lorg/sonar/api/server/rule/RulesDefinition$NewRule;
	at [...]
	at org.sonar.core.platform.ComponentContainer.startComponents(ComponentContainer.java:136)
	at org.sonar.server.platform.platformlevel.PlatformLevel.start(PlatformLevel.java:90)
	at org.sonar.server.platform.platformlevel.PlatformLevelStartup.access$001(PlatformLevelStartup.java:49)
	at org.sonar.server.platform.platformlevel.PlatformLevelStartup$1.doPrivileged(PlatformLevelStartup.java:87)
	at org.sonar.server.user.DoPrivileged.execute(DoPrivileged.java:45)
	at org.sonar.server.platform.platformlevel.PlatformLevelStartup.start(PlatformLevelStartup.java:84)
	at org.sonar.server.platform.PlatformImpl.executeStartupTasks(PlatformImpl.java:198)
	at org.sonar.server.platform.PlatformImpl$1.lambda$doRun$1(PlatformImpl.java:122)
	at org.sonar.server.platform.PlatformImpl$AutoStarterRunnable.runIfNotAborted(PlatformImpl.java:370)
	at org.sonar.server.platform.PlatformImpl$1.doRun(PlatformImpl.java:122)
	at org.sonar.server.platform.PlatformImpl$AutoStarterRunnable.run(PlatformImpl.java:354)
	at java.base/java.lang.Thread.run(Thread.java:834)
2021.08.19 10:12:32 INFO  web[][o.s.p.ProcessEntryPoint] Hard stopping process
2021.08.19 10:12:32 INFO  web[][o.s.s.n.NotificationDaemon] Notification service stopped

With version 9.0 the class RulesDefinition has been deprecated. Ok, but it should still be available with previous API.

Further, I’m wondering why the documentation on API basics (configuration) still lists RulesDefinition as extension point.

Is there a API migration guide?

The plugin is currently using the following configuration

    <sonar.version>7.9</sonar.version>
    <sonarQubeMinVersion>7.9</sonarQubeMinVersion>

Hi,

Could we have the full stacktrace?

It’s quite likely we forgot to update those docs.

 
Ann

Call stack:

2021.08.19 10:12:32 ERROR web[][o.s.s.p.Platform] Background initialization failed. Stopping SonarQube
java.lang.NoSuchMethodError: org.sonar.api.server.rule.RulesDefinition$NewRule.setEffortToFixDescription(Ljava/lang/String;)Lorg/sonar/api/server/rule/RulesDefinition$NewRule;
	at org.sonar.***.AnnotationBasedRulesDefinition.setupSqaleModel(AnnotationBasedRulesDefinition.java:184)
	at org.sonar.***.AnnotationBasedRulesDefinition.addRuleClasses(AnnotationBasedRulesDefinition.java:102)
	at org.sonar.***.AnnotationBasedRulesDefinition.addRuleClasses(AnnotationBasedRulesDefinition.java:88)
	at org.***.***RuleRepository.define(***RuleRepository.java:34)
	at org.sonar.server.rule.RuleDefinitionsLoader.load(RuleDefinitionsLoader.java:53)
	at org.sonar.server.rule.RegisterRules.start(RegisterRules.java:117)
	at org.sonar.core.platform.StartableCloseableSafeLifecyleStrategy.start(StartableCloseableSafeLifecyleStrategy.java:40)
	at org.picocontainer.injectors.AbstractInjectionFactory$LifecycleAdapter.start(AbstractInjectionFactory.java:84)
	at org.picocontainer.behaviors.AbstractBehavior.start(AbstractBehavior.java:169)
	at org.picocontainer.behaviors.Stored$RealComponentLifecycle.start(Stored.java:132)
	at org.picocontainer.behaviors.Stored.start(Stored.java:110)
	at org.picocontainer.DefaultPicoContainer.potentiallyStartAdapter(DefaultPicoContainer.java:1016)
	at org.picocontainer.DefaultPicoContainer.startAdapters(DefaultPicoContainer.java:1009)
	at org.picocontainer.DefaultPicoContainer.start(DefaultPicoContainer.java:767)
	at org.sonar.core.platform.ComponentContainer.startComponents(ComponentContainer.java:136)
	at org.sonar.server.platform.platformlevel.PlatformLevel.start(PlatformLevel.java:90)
	at org.sonar.server.platform.platformlevel.PlatformLevelStartup.access$001(PlatformLevelStartup.java:49)
	at org.sonar.server.platform.platformlevel.PlatformLevelStartup$1.doPrivileged(PlatformLevelStartup.java:87)
	at org.sonar.server.user.DoPrivileged.execute(DoPrivileged.java:45)
	at org.sonar.server.platform.platformlevel.PlatformLevelStartup.start(PlatformLevelStartup.java:84)
	at org.sonar.server.platform.PlatformImpl.executeStartupTasks(PlatformImpl.java:198)
	at org.sonar.server.platform.PlatformImpl$1.lambda$doRun$1(PlatformImpl.java:122)
	at org.sonar.server.platform.PlatformImpl$AutoStarterRunnable.runIfNotAborted(PlatformImpl.java:370)
	at org.sonar.server.platform.PlatformImpl$1.doRun(PlatformImpl.java:122)
	at org.sonar.server.platform.PlatformImpl$AutoStarterRunnable.run(PlatformImpl.java:354)
	at java.base/java.lang.Thread.run(Thread.java:834)
2021.08.19 10:12:32 INFO  web[][o.s.p.ProcessEntryPoint] Hard stopping process
2021.08.19 10:12:32 INFO  web[][o.s.s.n.NotificationDaemon] Notification service stopped

Is there a API migration guide?

Hi,

Are these asterisks what was actually printed in the log?

    at org.sonar.***.AnnotationBasedRulesDefinition.setupSqaleModel(AnnotationBasedRulesDefinition.java:184)
	at org.sonar.***.AnnotationBasedRulesDefinition.addRuleClasses(AnnotationBasedRulesDefinition.java:102)
	at org.sonar.***.AnnotationBasedRulesDefinition.addRuleClasses(AnnotationBasedRulesDefinition.java:88)
	at org.***.***RuleRepository.define(***RuleRepository.java:34)

 
Ann

No, I have removed them because it is internal.

Okay, so this is your internally developed plugin?

I’m going to move this thread to the Plugin Development category & flag it for more expert attention.

 
Ann

Hi,
I looks like the plugin was using a method in the API that was removed in v9.0.
The method had been deprecated in v5.5: https://github.com/SonarSource/sonar-enterprise/blob/branch-7.9/sonar-plugin-api/src/main/java/org/sonar/api/server/rule/RulesDefinition.java#L909

The plugin is not compatible with SQ 9.0+.

FTFY: sonarqube/RulesDefinition.java at branch-7.9 · SonarSource/sonarqube · GitHub (sonarqube repository instead of sonar-enterprise)

@lg2de replace setEffortToFixDescription by setGapDescription :wink:

1 Like