How to work bitbucket with OsgiPlugin Error

Hi, I have a error like this

ERROR [ThreadPoolAsyncTaskExecutor::Thread 25] c.a.plugin.osgi.factory.OsgiPlugin Unable to start the plugin container for plugin ‘com.curvc.atlas.bitbucket.plugin.bitbucket-sso-plugin’
org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name ‘adminItem01Rest’: Unsatisfied dependency expressed through constructor parameter 0; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name ‘pluginConfig’: Bean instantiation via constructor failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [com.curvc.atlas.bitbucket.plugin.sso.config.PluginConfig]: Constructor threw exception; nested exception is java.lang.NullPointerException
at org.springframework.beans.factory.support.ConstructorResolver.createArgumentArray(ConstructorResolver.java:769)
at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:877)
at org.eclipse.gemini.blueprint.context.support.AbstractDelegatedExecutionApplicationContext.access$1600(AbstractDelegatedExecutionApplicationContext.java:57)
at org.eclipse.gemini.blueprint.context.support.AbstractDelegatedExecutionApplicationContext$4.run(AbstractDelegatedExecutionApplicationContext.java:322)
at org.eclipse.gemini.blueprint.util.internal.PrivilegedUtils.executeWithCustomTCCL(PrivilegedUtils.java:85)
at org.eclipse.gemini.blueprint.context.support.AbstractDelegatedExecutionApplicationContext.completeRefresh(AbstractDelegatedExecutionApplicationContext.java:287)
at org.eclipse.gemini.blueprint.extender.internal.dependencies.startup.DependencyWaiterApplicationContextExecutor$CompleteRefreshTask.run(DependencyWaiterApplicationContextExecutor.java:137)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
at java.lang.Thread.run(Thread.java:748)
… 11 frames trimmed
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name ‘pluginConfig’: Bean instantiation via constructor failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [com.curvc.atlas.bitbucket.plugin.sso.config.PluginConfig]: Constructor threw exception; nested exception is java.lang.NullPointerException
at org.springframework.beans.factory.support.ConstructorResolver.instantiate(ConstructorResolver.java:304)
… 9 common frames omitted
Caused by: org.springframework.beans.BeanInstantiationException: Failed to instantiate [com.curvc.atlas.bitbucket.plugin.sso.config.PluginConfig]: Constructor threw exception; nested exception is java.lang.NullPointerException
at org.springframework.beans.BeanUtils.instantiateClass(BeanUtils.java:184)
… 9 common frames omitted
Caused by: java.lang.NullPointerException: null
at com.atlassian.sal.api.component.ComponentLocator.getComponent(ComponentLocator.java:39)
at com.curvc.atlas.bitbucket.plugin.sso.config.PluginConfig.(PluginConfig.java:48)
at org.springframework.beans.BeanUtils.instantiateClass(BeanUtils.java:172)
… 9 common frames omitted

and I resolve to add "Component-import"annotation. But I couldn’t realize this error first time because when I build this add-on in my local environment the error message not shown. And then I upload this add-on in my server environment this error message shown and add-on status disabled. Even if it was initially disabled, the add-on was enabled, and after that, the add-on worked without error. I wonder how the code can work even with errors.

Hi 11175,

without some more context it’s difficult to say what went wrong. I don’t think it’s necessarily an OSGi problem, it looks like you were trying to use ComponentLocator.getComponent() before the SAL plugin was fully instantiated. To resolve this, you could try using @ComponentImport for ComponentLocator in your constructor. This will create an OSGi dependency for it and make sure it’s initialized before your class.

Cheers,
Wolfgang