This Bugzilla instance is a read-only archive of historic NetBeans bug reports. To report a bug in NetBeans please follow the project's instructions for reporting issues.

Bug 50642 - Can't use jakarta commons-logging in gui beans
Summary: Can't use jakarta commons-logging in gui beans
Status: RESOLVED FIXED
Alias: None
Product: guibuilder
Classification: Unclassified
Component: Code (show other bugs)
Version: 4.x
Hardware: PC Windows ME/2000
: P3 blocker with 1 vote (vote)
Assignee: issues@guibuilder
URL:
Keywords:
Depends on: 167993
Blocks:
  Show dependency tree
 
Reported: 2004-10-20 09:50 UTC by aldobrucale
Modified: 2009-07-14 16:18 UTC (History)
1 user (show)

See Also:
Issue Type: DEFECT
Exception Reporter:


Attachments
A stack trace of the error I get (19.63 KB, text/plain)
2004-10-20 09:51 UTC, aldobrucale
Details
ide.log at startup after disabling modules (9.33 KB, text/plain)
2004-10-27 10:43 UTC, aldobrucale
Details

Note You need to log in before you can comment on or make changes to this bug.
Description aldobrucale 2004-10-20 09:50:39 UTC
When trying to instantiate in the form editor a 
bean which uses org.apache.commons.logging it 
cannot be instantiated because of this exception:

org.apache.commons.logging.LogConfigurationExcepti
on: Invalid class loader hierarchy.  You have 
more than one version 
of 'org.apache.commons.logging.Log' visible, 
which is not allowed.
Comment 1 aldobrucale 2004-10-20 09:51:51 UTC
Created attachment 18392 [details]
A stack trace of the error I get
Comment 2 aldobrucale 2004-10-20 10:09:10 UTC
If I remove commons-logging.jar from the project's classpath (it's a 
freeform project) i get a NoClassDefFoundError.
Comment 3 Jan Stola 2004-10-26 09:26:28 UTC
This is an interesting and complicated problem.
There is a clash between usage of classloaders
by NetBeans IDE and the Commons Logging.

Form editor attempts to avoid conflicts between
Java Bean classes and the classes of the NetBeans IDE.
It contains a code that ensures that the classes
needed by some Java Bean are loaded from the same
project/JAR/library the bean comes from.

Unfortunately the Commons Logging library
(namely the LogFactory and LogFactoryImpl classes)
attempts to load another classes by a classloader
different from LogFactory(Impl).class.getClassLoader().
It directly uses Thread.getContextClassLoader(),
but this is a classloader of the NetBeans IDE.
The Commons Logging library loads its classes
(e.g. org.apache.commons.logging.impl.Jdk14Logger)
using this classloader, but these classes are
also part of the NetBeans IDE (JSP Parser module).
This results in the conflict between class
org.apache.commons.logging.Log loaded from
the bean's project and the same class loaded
from the JSP Parser module.

I am afraid that we cannot do much in this case.
As a workaround you can disable all NetBeans modules
that uses JSP Parser module (e.g. JSP/Servlet,
JSP/Servlet Breakpoint Support and Web Samples).
Comment 4 aldobrucale 2004-10-27 10:42:20 UTC
Thank you for your answer. I still have not tried the workaround, but 
disabling the modules the ide hangs up with an exception when 
restarted... I will attach my messages.log file.

Should I file this as another issue?
Comment 5 aldobrucale 2004-10-27 10:43:21 UTC
Created attachment 18553 [details]
ide.log at startup after disabling modules
Comment 6 Jan Stola 2004-10-27 11:02:37 UTC
I am sorry, I am not sure what went wrong in your case. 
Please, fill another issue (probably against web module)
and describe what modules (and how e.g. using Tools > Setup Wizard)
did you disable.
Comment 7 wiverson 2005-11-02 06:31:50 UTC
This is a pretty obnoxious bug - I have a component which uses a library that in
turn depends on Commons Logging.

Looking at the Commons Logging source, it looks like it would be possible to add
a custom NetBeans logger implementation that would map the logging information
to the NetBeans error log infrastruture.  In other words, the LogFactory falls
back on the LogFactoryImpl, which in turn eventually fails in the manner described.

Right now, this is the worst of both worlds - Commons Logging is embedded into
the NetBeans platform, but component authors that use Logging (directly or
indirectly) are pretty much hosed.  Either make the Commons Logging integration
work, or remove it from the platform.

From the looks of it, simply adding a org.apache.commons.logging.Log system
property to point to a better log impl may fix the issue.

http://jakarta.apache.org/commons/logging/api/org/apache/commons/logging/package-summary.html

I think I can wedge a fix for this in to my dev environment, e.g. 

org.apache.commons.logging.Log=org.apache.commons.logging.impl.SimpleLog

...but I just spent way too much time sorting this out, and I think a lot of
other component devs would just give up.
Comment 8 wiverson 2005-11-02 06:59:28 UTC
Sorry - I just tried adding that org.apache.commons.logging.Log system property
to my netbeans.conf file and that didn't seem to help.  There might be another
way to reconfigure, but not knowing how the various pieces interact here is
tripping me up.
Comment 9 wiverson 2005-11-03 22:00:14 UTC
FYI, as a workaround, I went ahead and used a, ahh, refactoring tool to create a
fork of the Commons logging library to work around this.  Basically, I changed
the package statements for Commons logging and rebound my code to that package
(basically, org.apache.commons.* -> hack.org.apache.commons.*).  So, my code
works fine now, but I now have a fork of the Commons Logging (and BeanUtil) code
in my codebase.  Bleach.

I'd suggest that the fix for this be doing this instead for the NetBeans commons
implementation, i.e. org.apache.commons.* -> org.netbeans.org.apache.commons.*).
 You'll need to "reapply" the hack everytime you pick up the Logging library
from Apache, but to date that's not been a high frequency release train.
Comment 10 Jan Stola 2005-12-01 16:56:31 UTC
The classloading infrastructure of the form module has been changed
significantly during the last year. Now, we are able to introduce
a hack to fix this issue:

/cvs/form/src/org/netbeans/modules/form/project/ProjectClassLoader.java,v
new revision: 1.3; previous revision: 1.2
Comment 11 ludom 2009-01-09 13:29:07 UTC
Gui builder refuse to open form containing custom component using common logging API.
For example, whith following code :

public class BTextField extends JTextField {

    private static Log log=LogFactory.getLog(BTable.class);

    public BTextField() {
        super();
        log.warn("create textfield");
    }
}

I get this error in message log :
ATTENTION [org.netbeans.ProxyClassLoader]: Will not load class org.apache.commons.logging.impl.LogFactoryImpl
arbitrarily from one of org.netbeans.StandardModule$OneModuleClassLoader@b78915[org.netbeans.libs.commons_logging] and
org.netbeans.StandardModule$OneModuleClassLoader@1b1ff47[org.netbeans.modules.maven.embedder]; see
http://wiki.netbeans.org/DevFaqModuleCCE
USER: Could not initialize class testcomposant.BTextField
INFO: Could not initialize class testcomposant.BTextField
org.openide.ErrorManager$AnnException: msg
	at org.openide.ErrorManager$AnnException.findOrCreate(ErrorManager.java:861)
	at org.openide.ErrorManager$DelegatingErrorManager.annotate(ErrorManager.java:650)
	at org.openide.ErrorManager.annotate(ErrorManager.java:452)
	at org.netbeans.modules.form.MetaComponentCreator.showClassLoadingErrorMessage(MetaComponentCreator.java:1372)
	at org.netbeans.modules.form.MetaComponentCreator.prepareClass0(MetaComponentCreator.java:1314)
	at org.netbeans.modules.form.MetaComponentCreator.access$800(MetaComponentCreator.java:84)
	at org.netbeans.modules.form.MetaComponentCreator$4.run(MetaComponentCreator.java:1271)
	at org.netbeans.modules.form.FormLAF$2.run(FormLAF.java:274)
	at org.openide.util.Mutex.doEventAccess(Mutex.java:1355)
	at org.openide.util.Mutex.readAccess(Mutex.java:317)
	at org.netbeans.modules.form.FormLAF.executeWithLookAndFeel(FormLAF.java:259)
	at org.netbeans.modules.form.MetaComponentCreator.prepareClass(MetaComponentCreator.java:1268)
	at org.netbeans.modules.form.MetaComponentCreator.precreateVisualComponent(MetaComponentCreator.java:213)
	at org.netbeans.modules.form.HandleLayer$NewComponentDrag.init(HandleLayer.java:2963)
	at org.netbeans.modules.form.HandleLayer$NewComponentDrag.<init>(HandleLayer.java:2958)
	at org.netbeans.modules.form.HandleLayer.mouseMoved(HandleLayer.java:2035)
	at java.awt.Component.processMouseMotionEvent(Component.java:6179)
	at javax.swing.JComponent.processMouseMotionEvent(JComponent.java:3283)
	at java.awt.Component.processEvent(Component.java:5903)
	at java.awt.Container.processEvent(Container.java:2023)
	at java.awt.Component.dispatchEventImpl(Component.java:4501)
	at java.awt.Container.dispatchEventImpl(Container.java:2081)
	at java.awt.Component.dispatchEvent(Component.java:4331)
	at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4301)
	at java.awt.LightweightDispatcher.processMouseEvent(Container.java:3978)
	at java.awt.LightweightDispatcher.dispatchEvent(Container.java:3895)
	at java.awt.Container.dispatchEventImpl(Container.java:2067)
	at java.awt.Window.dispatchEventImpl(Window.java:2458)
	at java.awt.Component.dispatchEvent(Component.java:4331)
	at java.awt.EventQueue.dispatchEvent(EventQueue.java:599)
	at org.netbeans.core.TimableEventQueue.dispatchEvent(TimableEventQueue.java:104)
	at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:269)
	at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:184)
	at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:174)
	at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:169)
	at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:161)
	at java.awt.EventDispatchThread.run(EventDispatchThread.java:122)
msg
Caused: java.lang.NoClassDefFoundError: Could not initialize class testcomposant.BTextField
	at java.lang.Class.forName0(Native Method)
	at java.lang.Class.forName(Class.java:247)
	at org.netbeans.modules.form.project.ClassPathUtils.loadClass(ClassPathUtils.java:95)
[catch] at org.netbeans.modules.form.MetaComponentCreator.prepareClass0(MetaComponentCreator.java:1304)
	at org.netbeans.modules.form.MetaComponentCreator.access$800(MetaComponentCreator.java:84)
	at org.netbeans.modules.form.MetaComponentCreator$4.run(MetaComponentCreator.java:1271)
	at org.netbeans.modules.form.FormLAF$2.run(FormLAF.java:274)
	at org.openide.util.Mutex.doEventAccess(Mutex.java:1355)
	at org.openide.util.Mutex.readAccess(Mutex.java:317)
	at org.netbeans.modules.form.FormLAF.executeWithLookAndFeel(FormLAF.java:259)
	at org.netbeans.modules.form.MetaComponentCreator.prepareClass(MetaComponentCreator.java:1268)
	at org.netbeans.modules.form.MetaComponentCreator.precreateVisualComponent(MetaComponentCreator.java:213)
	at org.netbeans.modules.form.HandleLayer$NewComponentDrag.init(HandleLayer.java:2963)
	at org.netbeans.modules.form.HandleLayer$NewComponentDrag.<init>(HandleLayer.java:2958)
	at org.netbeans.modules.form.HandleLayer.mouseMoved(HandleLayer.java:2035)
	at java.awt.Component.processMouseMotionEvent(Component.java:6179)
	at javax.swing.JComponent.processMouseMotionEvent(JComponent.java:3283)
	at java.awt.Component.processEvent(Component.java:5903)
	at java.awt.Container.processEvent(Container.java:2023)
	at java.awt.Component.dispatchEventImpl(Component.java:4501)
	at java.awt.Container.dispatchEventImpl(Container.java:2081)
	at java.awt.Component.dispatchEvent(Component.java:4331)
	at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4301)
	at java.awt.LightweightDispatcher.processMouseEvent(Container.java:3978)
	at java.awt.LightweightDispatcher.dispatchEvent(Container.java:3895)
	at java.awt.Container.dispatchEventImpl(Container.java:2067)
	at java.awt.Window.dispatchEventImpl(Window.java:2458)
	at java.awt.Component.dispatchEvent(Component.java:4331)
	at java.awt.EventQueue.dispatchEvent(EventQueue.java:599)
	at org.netbeans.core.TimableEventQueue.dispatchEvent(TimableEventQueue.java:104)
	at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:269)
	at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:184)
	at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:174)
	at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:169)
	at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:161)
	at java.awt.EventDispatchThread.run(EventDispatchThread.java:122)
Cannot load component class testcomposant.BTextField from JAR file: D:\Mes
Documents\NetBeansProjects\TestComposant\dist\TestComposant.jar.
The class must be compiled and must be on the classpath of the project to which this form belongs.

It seems that doing issue 118020 in 6.5 has colided whith hack that solves this issue.
Or what else ?
Comment 12 ludom 2009-01-09 13:45:16 UTC
For component code, you should read :

public class BTextField extends JTextField {

    private static Log log=LogFactory.getLog(BTextField.class);

    public BTextField() {
        super();
        log.warn("create textfield");
    }
}

When using following, the problem disappears :

public class BTextField extends JTextField {

    //private static Log log=LogFactory.getLog(BTextField.class);

    public BTextField() {
        super();
        //log.warn("create textfield");
    }
}
Comment 13 Jan Stola 2009-07-14 16:18:26 UTC
The original issue was fixed 4 years ago, see my 'Thu Dec 1 16:56:31 +0000 2005' comment. The new problem is a 
duplicate of issue 168538. Hence, closing this issue as fixed again. See, issue 168538 for more information about the 
recent problem.