[jboss-user] [Javassist] - ClassCastException when modifiying JOptionPane behaviour

Telcontar Thorongil do-not-reply at jboss.com
Fri Mar 23 08:35:59 EDT 2012


Telcontar Thorongil [https://community.jboss.org/people/telcontarvi] created the discussion

"ClassCastException when modifiying JOptionPane behaviour"

To view the discussion, visit: https://community.jboss.org/message/725909#725909

--------------------------------------------------------------
I'm triying to modify the JOptionPane behaviour to log all the user responses. If do it when the class is loaded with HotsSapper is OK, but i can't do it whith the HotSwapper because the application it's launched by Java Web Start and i haven't be able to open the needed socket.

If i try to modify the class before it's loaded i have an ClassCastException throwed by BasicOptionPaneUI. there is the code i use:


public class Test2 {
    public static void main(String[] args) throws Exception {
        ClassPool cp = ClassPool.getDefault();
        CtClass cc = cp.get("javax.swing.JOptionPane");
        CtMethod[] methods = cc.getMethods();
        for (CtMethod method : methods) {
            if (method.getName().equals("showConfirmDialog")) {
                if(method.getLongName().equals("javax.swing.JOptionPane.showConfirmDialog(java.awt.Component,java.lang.Object,                               java.lang.String,int,int,javax.swing.Icon)")){
                    String after = "System.out.println(\"User answered: \" + $_ );";
                    method.insertAfter(after);
                }
            }
        }
        try{
            Class c=cc.toClass();
            c.newInstance();
        }catch(CannotCompileException ex){
            ex.printStackTrace();
        }
        JOptionPane.showConfirmDialog(null,"Yer or Not?");
    }
}

Why is this happening? how can i fix it?
--------------------------------------------------------------

Reply to this message by going to Community
[https://community.jboss.org/message/725909#725909]

Start a new discussion in Javassist at Community
[https://community.jboss.org/choose-container!input.jspa?contentType=1&containerType=14&container=2062]

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.jboss.org/pipermail/jboss-user/attachments/20120323/b0b29a50/attachment.html 


More information about the jboss-user mailing list