1

My Jira 5.0 plugin is broken with the following exception:

java.lang.reflect.InvocationTargetException
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        ...
Caused by: java.lang.ExceptionInInitializerError
    at org.apache.axis.description.OperationDesc.<clinit>(OperationDesc.java:65)
    at com.xyz.germander.AddTestTrackLinkDialogAction.doConfirm(AddTestTrackLinkDialogAction.java:23)
    ... 148 more
Caused by: java.lang.ClassCastException: org.apache.commons.logging.impl.SLF4JLogFactory cannot be cast to org.apache.commons.logging.LogFactory
    at org.apache.axis.components.logger.LogFactory.getLogFactory(LogFactory.java:41)
    at org.apache.axis.components.logger.LogFactory.<clinit>(LogFactory.java:33)
    ... 150 more

For reference, this is the method throwing the ClassCastException:

private static final org.apache.commons.logging.LogFactory getLogFactory() {
    return (org.apache.commons.logging.LogFactory)
        AccessController.doPrivileged(
            new PrivilegedAction() {
                public Object run() {
                    return DiscoverSingleton.find(org.apache.commons.logging.LogFactory.class,
                                   org.apache.commons.logging.LogFactory.FACTORY_PROPERTIES,
                                   org.apache.commons.logging.LogFactory.FACTORY_DEFAULT);
                }
            });
}

... for further reference, org.apache.commons.logging.LogFactory.FACTORY_DEFAULT is "org.apache.commons.logging.impl.LogFactoryImpl", and FACTORY_PROPERTIES is supposed to be the name of the properties file to search for, which in my org.apache.commons.logging jar is "commons-logging.properties".

I've tried creating a commons-logging.properties file in the resource dir of the plugin; that file contains this:

priority=1
org.apache.commons.logging.Log=org.apache.commons.logging.impl.LogFactoryImpl

... but it seems to get ignored since getLogFactory() still gets SLF4JLogFactory and fails to cast it. So it looks like:

  • This commons-logging.properties file needs to be somewhere else
  • I need to set the logging class to be something else
  • The project is otherwise misconfigured, maybe at the Jira level or maybe at the plugin or maybe Maven or... I don't even know

I'm pretty stumped, and would appreciate any guidance.

There is a similar question here, except that poster was getting the same exception in getLogFactory from the initialization of org.apache.axis.attachments.AttachmentsImpl instead of org.apache.axis.description.OperationDesc. (Also a Confluence plugin, not Jira.) Nobody responded there, though.

Community
  • 1
  • 1
Turnsole
  • 3,422
  • 5
  • 30
  • 52
  • Were you able to properly implement logging in your Jira plugin? I have a similar question here https://answers.atlassian.com/questions/74097/how-to-use-logging-from-inside-jira-plugins?page=1#74108 – sorin Nov 21 '12 at 10:20
  • 1
    It did work for me when I included axis as described in the accepted answer here. – Turnsole Nov 21 '12 at 22:10
  • Can you please provide a simple example of logging code that works from your plugin? Something similar with https://answers.atlassian.com/questions/74097/how-to-use-logging-from-inside-jira-plugins ? (which I'm trying to solve) – sorin Nov 22 '12 at 13:05
  • 1
    Sure thing. I'm on vacation right now so I don't have it handy, but I've made a note to come back and post that. (I'll crosspost on Atlassian Answers too, since lots of folks seem to run into issues with it.) – Turnsole Nov 26 '12 at 03:44

2 Answers2

2

Including axis-1.3-atlassian-1 only results

java.lang.ClassNotFoundException: org.apache.axis.transport.http.AdminServlet

Due to my application needs AdminServlet which is included in appache axis library. Finally when I included both it works fine with me.

    <dependency>
        <groupId>org.apache.axis</groupId>
        <artifactId>axis</artifactId>
        <version>1.4</version>
    </dependency>
    <dependency>
        <groupId>axis</groupId>
        <artifactId>axis</artifactId>
        <version>1.3-atlassian-1</version>
        <scope>provided</scope>
    </dependency>
amrjamil
  • 21
  • 2
1

Discoveries: Atlassian forked the axis library and Jira now uses axis-1.3-atlassian-1 and not the latest axis-1.4 from Apache; axis-1.3-atlassian-1 uses the 1.0.4 version of commons-logging, not 1.1.1 like axis-1.4.

Changing the dependency of the plugin from axis-1.4 to axis-1.3-atlassian-1 solved the problem. It is my suspicion that SLF4JLogFactory could cast to org.apache.commons.logging.LogFactory in 1.0.4 but not 1.1.1, but I haven't tested it.

If in Jira, be sure to give the scope of the dependency as "provided" or you'll run in to problems due to stuff being loaded twice. Here's a pom snippet:

    <dependency>
        <groupId>axis</groupId>
        <artifactId>axis</artifactId>
        <version>1.3-atlassian-1</version>
        <scope>provided</scope>
    </dependency>
Turnsole
  • 3,422
  • 5
  • 30
  • 52