Unable to resolve missing requirement osgi.wiring.package JiraThreadLocalUtil

Hi Everyone,

I am facing below error on Jira Server 8.5.4. Does anyone have any knowledge of how to mitigate this error.

Caused by: org.osgi.framework.BundleException: Unable to resolve plugin.name [261](R 261.0): missing requirement [plugin.name [261](R 261.0)] osgi.wiring.package; (osgi.wiring.package=com.atlassian.jira.util.thread.JiraThreadLocalUtil) Unresolved requirements: [[plugin.name [261](R 261.0)] osgi.wiring.package; (osgi.wiring.package=com.atlassian.jira.util.thread.JiraThreadLocalUtil)]

Relevant part of pom -

                        <Import-Package>
                            com.atlassian.jira.plugin.webfragment.conditions,
                            com.atlassian.jira.util.thread.JiraThreadLocalUtil,
                            *;resolution:="optional"
                        </Import-Package>

and if I don’t include the the package in import-package and try to use it directly. The system throws exception while initializing the plugin pasted below -

org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'issueStateCalculatorImpl': Unsatisfied dependency expressed through constructor parameter 5; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'jqlExecutorImpl': Unsatisfied dependency expressed through constructor parameter 2; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type 'com.atlassian.jira.util.thread.JiraThreadLocalUtil' available: expected at least 1 bean which qualifies as autowire candidate. Dependency annotations: {@com.atlassian.plugin.spring.scanner.annotation.imports.ComponentImport(value=)}

The actual problem is present somewhere else, as the same code is being used in compiling another jar and is working fine.
When I try to import the service via below LOC to find out the original root cause of the problem.

final JiraThreadLocalUtil jiraThreadLocalUtil = ComponentAccessor.getComponent(JiraThreadLocalUtil.class);

It throws below error when trying to run the above LOC-

<?xml version="1.0" encoding="UTF-8" standalone="yes"?><status><status-code>500</status-code><message>loader constraint violation: when resolving interface method "com.atlassian.jira.util.thread.JiraThreadLocalUtil.postCall(Lorg/apache/log4j/Logger;)V" the class loader (instance of org/apache/felix/framework/BundleWiringImpl$BundleClassLoader) of the current class, com/adc/commons/jira/service/JqlExecutorImpl, and the class loader (instance of org/apache/catalina/loader/ParallelWebappClassLoader) for the method's defining class, com/atlassian/jira/util/thread/JiraThreadLocalUtil, have different Class objects for the type org/apache/log4j/Logger used in the signature</message><stack-trace>java.lang.LinkageError: loader constraint violation: when resolving interface method "com.atlassian.jira.util.thread.JiraThreadLocalUtil.postCall(Lorg/apache/log4j/Logger;)V" the class loader (instance of org/apache/felix/framework/BundleWiringImpl$BundleClassLoader) of the current class, com/adc/commons/jira/service/JqlExecutorImpl, and the class loader (instance of org/apache/catalina/loader/ParallelWebappClassLoader) for the method's defining class, com/atlassian/jira/util/thread/JiraThreadLocalUtil, have different Class objects for the type org/apache/log4j/Logger used in the signature&#13;

If I remove everything related to JiraThreadLocalUtil from my plugin. Then everything is working fine except the specific part of plugin (JqlSearch) which needs to use JiraThreadLocalUtil.

For anyone else who went through this problem -
I used below link to rectify the above problem based on last error.

Code changes I did in my pom file.


        <dependency>
            <groupId>com.atlassian.jira</groupId>
            <artifactId>jira-core</artifactId>
            <version>${jira.version}</version>
            <scope>provided</scope>
            <exclusions>
                <exclusion>
                    <groupId>com.atlassian</groupId>
                    <artifactId>atlassian-logging</artifactId>
                </exclusion>
                <exclusion>
                    <groupId>log4j</groupId>
                    <artifactId>log4j</artifactId>
                </exclusion>
            </exclusions>
        </dependency>
        <dependency>
            <groupId>org.sweble.wikitext</groupId>
            <artifactId>swc-engine</artifactId>
            <scope>compile</scope>
            <exclusions>
                <exclusion>
                    <groupId>log4j</groupId>
                    <artifactId>log4j</artifactId>
                </exclusion>
            </exclusions>
        </dependency>


The problem was of duplicate log4j jar being present on the class path. I removed log4j from jira-core and swc-engine just to be safe. The only log4j present on class path is from jira-api.