United StatesChange Country, Oracle Worldwide Web Sites Communities I am a... I want to...
Bug ID: JDK-6655515 MBeans tab: operation return values of type Component displayed as String
JDK-6655515 : MBeans tab: operation return values of type Component displayed as String

Details
Type:
Bug
Submit Date:
2008-01-25
Status:
Closed
Updated Date:
2011-03-08
Project Name:
JDK
Resolved Date:
2011-03-08
Component:
tools
OS:
generic
Sub-Component:
jconsole
CPU:
generic
Priority:
P4
Resolution:
Fixed
Affected Versions:
7
Fixed Versions:

Related Reports
Backport:

Sub Tasks

Description
Operation return values of type java.awt.Component are displayed as java.lan.String
instead of being displayed as AWT/Swing components in a container.

This is a regression introduced in JConsole 6/7.

                                    

Comments
EVALUATION

I was able to build JConsole using the instructions at <http://nb-openjdk.netbeans.org/get-and-build-jconsole.html> and apply the following fix:

diff -r 93cc3fad6803 src/share/classes/sun/tools/jconsole/inspector/XDataViewer.java
--- a/src/share/classes/sun/tools/jconsole/inspector/XDataViewer.java	Tue Jan 15 13:35:38 2008 +0100
+++ b/src/share/classes/sun/tools/jconsole/inspector/XDataViewer.java	Tue Feb 05 18:17:00 2008 +0100
@@ -108,6 +108,7 @@ public class XDataViewer {
     public Component createOperationViewer(Object value,
                                            XMBean mbean) {
         if(value instanceof Number) return null;
+        if(value instanceof Component) return (Component) value;
         return createAttributeViewer(value, mbean, null, null);
     }
 
So people for whom this is a blocking problem can always install a custom JConsole with this fix.

Having said that, it's not clear that it's a good idea for MBean operations to return Swing components.  Swing serialization is explicitly stated not to be compatible across releases, so this will only work if your JConsole is running on the same JDK as your application.  Furthermore you have to be extremely careful that your component does not reference any application-specific classes.  For example, tables created in the usual way are editable, and if you want to make one non-editable then the usual way to do that is to create a subclass of DefaultTableModel that overrides isCellEditable.  But if you do that then JConsole won't know your subclass and will fail mysteriously when it tries to read the result of your operation.

But it is true that this is a convenient if dangerous way to provide formatted data to human users, and it is very simple to modify JConsole to support it.  Given that the JDK 5.0 version did support it we should update JDK 6 to support it too.
                                     
2008-02-05
EVALUATION

Do not convert Components to Strings.
                                     
2008-01-25



Hardware and Software, Engineered to Work Together