0 Replies Latest reply on Mar 23, 2012 8:35 AM by telcontarvi

    ClassCastException when modifiying JOptionPane behaviour


      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: \" + $_ );";






                  Class c=cc.toClass();


              }catch(CannotCompileException ex){



              JOptionPane.showConfirmDialog(null,"Yer or Not?");




      Why is this happening? how can i fix it?