While upgrading our WLS console to use the latest libraries i.e. to use the latest Struts, Beehive, WebLogic Portal versions. I ran into this problem that caught me completely off gaurd and took me a while to figure whats going on. Struts 1.2.7 distribution comes with commons logging 1.0.4 and log4j 1.2.8. Once I upgraded our console to struts 1.2.7 and tried to deploy it to the server the deployment failed with the error below.
java.lang.NoSuchMethodError: isEnabledFor
······at org.apache.commons.logging.impl.Log4JCategoryLog.isErrorEnabled(Log4JCategoryLog.java:189)
······at org.apache.beehive.netui.util.logging.Logger.isErrorEnabled(Logger.java:97)
······at org.apache.beehive.netui.pageflow.internal.AdapterManager.getServletContainerAdapter(AdapterManager.java:47)
······at org.apache.beehive.netui.pageflow.PageFlowUtils.createURLTemplatesFactory(PageFlowUtils.java:1716)
Well, initially I thought this is caused due to another version of commons-logging.jar lurking around somewhere in the system classpath and is being picked up by the application. But after carefully reviewing the classpath and other libraries in the application I did not find any foul play, this just drove me crazy. Thought I would instrument the Log4JCategoryLog class to see what methods it is seeing in “org.apache.log4j.Category” that is making it to fail with NSME. After compiling and re-packaging it in commons-logging.jar to my surprise everything worked as normal. I could see my debug output that I put in while instrumenting Log4jCategoryLog. At this point it made me think if the class file packaged in commons-logging.jar is erroneous. To prove that I had to isolate the problem to just commons-logging and log4j. Thanks to another colleague, this simple reproducer revealed the issue.
public class Foo {
···// Ensure that your classpath has commons-logging-1.0.4.jar and log4j-1.2.8.jar
···public static void main(String[] args) {
······org.apache.commons.logging.impl.Log4JCategoryLog x = new org.apache.commons.logging.impl.Log4JCategoryLog();
······x.isErrorEnabled();
···}
}
This simple client failed with the exact same error I was seeing while deploying the console. I believe the problem is the classes in commons-logging-1.0.4 that come from apache have been compiled with the wrong log4j Category class.
If you do javap -c org.apache.commons.logging.impl.Log4JCategoryLog with commons-logging-1.0.4.jar in classpath you will see that for isErrorEnabled method,
public boolean isErrorEnabled();
Code:
0: aload_0
1: getfield #7; //Field category:Lorg/apache/log4j/Category;
4: getstatic #14; //Field org/apache/log4j/Level.ERROR:Lorg/apache/log4j/Level;
7: invokevirtual #17; //Method org/apache/log4j/Category.isEnabledFor:(Lorg/apache/log4j/Level;)Z
10: ireturn
Here the log4j’s Category’s isEnabledFor takes Level as an argument, but Log4JCategoryLog is expecting an object of type Priority. If I re-compile Log4JCategoryLog and re-package it and do a javap -c on the class I get,
public boolean isErrorEnabled();
Code:
0: aload_0
1: getfield #2; //Field category:Lorg/apache/log4j/Category;
4: getstatic #9; //Field org/apache/log4j/Priority.ERROR:Lorg/apache/log4j/Priority;
7: invokevirtual #12; //Method org/apache/log4j/Category.isEnabledFor:(Lorg/apache/log4j/Priority;)Z
10: ireturn
As you see the log4j’s Category’s isEnabledFor method takes an object of type Priority as an argument which is right. After googling a little bit I found that this has been corrected with the new commons-logging jar available at http://www.ibiblio.org/maven/commons-logging/jars/commons-logging-1.1-dev.jar.
_uacct = “UA-2684269-2″;
urchinTracker();