8139508: Debug option does not work in appletviewer
authoralexsch
Thu, 11 Feb 2016 00:19:38 +0400
changeset 36444 223801243559
parent 36443 d9d59282fc1a
child 36445 8784d61c0476
8139508: Debug option does not work in appletviewer Reviewed-by: prr, ssadetsky
jdk/src/java.desktop/share/classes/sun/applet/Main.java
jdk/src/java.desktop/share/classes/sun/applet/resources/MsgAppletViewer.java
--- a/jdk/src/java.desktop/share/classes/sun/applet/Main.java	Mon Feb 01 15:00:02 2016 -0800
+++ b/jdk/src/java.desktop/share/classes/sun/applet/Main.java	Thu Feb 11 00:19:38 2016 +0400
@@ -30,8 +30,6 @@
 import java.io.FileInputStream;
 import java.io.FileOutputStream;
 import java.io.IOException;
-import java.lang.reflect.Method;
-import java.lang.reflect.InvocationTargetException;
 import java.net.URL;
 import java.net.MalformedURLException;
 import java.util.Enumeration;
@@ -75,7 +73,6 @@
     /**
      * Member variables set according to options passed in to AppletViewer.
      */
-    private boolean debugFlag = false;
     private boolean helpFlag  = false;
     private String  encoding  = null;
     private boolean noSecurityFlag  = false;
@@ -136,14 +133,6 @@
             return 1;
         }
 
-        if (debugFlag) {
-            // START A DEBUG SESSION
-            // Given the current architecture, we will end up decoding the
-            // arguments again, but at least we are guaranteed to have
-            // arguments which are valid.
-            return invokeDebugger(args);
-        }
-
         // INSTALL THE SECURITY MANAGER (if necessary)
         if (!noSecurityFlag && (System.getSecurityManager() == null))
             init();
@@ -191,9 +180,6 @@
                 throw new ParseException(lookup("main.err.dupoption", arg));
             encoding = args[++i];
             return 2;
-        } else if ("-debug".equals(arg)) {
-            debugFlag = true;
-            return 1;
         } else if ("-Xnosecurity".equals(arg)) {
             // This is an undocumented (and, in the future, unsupported)
             // flag which prevents AppletViewer from installing its own
@@ -267,68 +253,6 @@
         return u;
     }
 
-    /**
-     * Invoke the debugger with the arguments passed in to appletviewer.
-     *
-     * @param args The arguments passed into the debugger.
-     * @return     {@code 0} if the debugger is invoked successfully,
-     *             {@code 1} otherwise.
-     */
-    private int invokeDebugger(String [] args) {
-        // CONSTRUCT THE COMMAND LINE
-        String [] newArgs = new String[args.length + 1];
-        int current = 0;
-
-        // Add a -classpath argument that prevents
-        // the debugger from launching appletviewer with the default of
-        // ".". appletviewer's classpath should never contain valid
-        // classes since they will result in security exceptions.
-        // Ideally, the classpath should be set to "", but the VM won't
-        // allow an empty classpath, so a phony directory name is used.
-        String phonyDir = System.getProperty("java.home") +
-                          File.separator + "phony";
-        newArgs[current++] = "-Djava.class.path=" + phonyDir;
-
-        // Appletviewer's main class is the debuggee
-        newArgs[current++] = "sun.applet.Main";
-
-        // Append all the of the original appletviewer arguments,
-        // leaving out the "-debug" option.
-        for (int i = 0; i < args.length; i++) {
-            if (!("-debug".equals(args[i]))) {
-                newArgs[current++] = args[i];
-            }
-        }
-
-        // LAUNCH THE DEBUGGER
-        // Reflection is used for two reasons:
-        // 1) The debugger classes are on classpath and thus must be loaded
-        // by the application class loader. (Currently, appletviewer are
-        // loaded through the boot class path out of rt.jar.)
-        // 2) Reflection removes any build dependency between appletviewer
-        // and jdb.
-        try {
-            Class<?> c = Class.forName("com.sun.tools.example.debug.tty.TTY", true,
-                                    ClassLoader.getSystemClassLoader());
-            Method m = c.getDeclaredMethod("main",
-                                           new Class<?>[] { String[].class });
-            m.invoke(null, new Object[] { newArgs });
-        } catch (ClassNotFoundException cnfe) {
-            System.err.println(lookup("main.debug.cantfinddebug"));
-            return 1;
-        } catch (NoSuchMethodException nsme) {
-            System.err.println(lookup("main.debug.cantfindmain"));
-            return 1;
-        } catch (InvocationTargetException ite) {
-            System.err.println(lookup("main.debug.exceptionindebug"));
-            return 1;
-        } catch (IllegalAccessException iae) {
-            System.err.println(lookup("main.debug.cantaccess"));
-            return 1;
-        }
-        return 0;
-    }
-
     private void init() {
         // GET APPLETVIEWER USER-SPECIFIC PROPERTIES
         Properties avProps = getAVProps();
--- a/jdk/src/java.desktop/share/classes/sun/applet/resources/MsgAppletViewer.java	Mon Feb 01 15:00:02 2016 -0800
+++ b/jdk/src/java.desktop/share/classes/sun/applet/resources/MsgAppletViewer.java	Thu Feb 11 00:19:38 2016 +0400
@@ -74,7 +74,7 @@
             {"appletviewer.parse.warning.embed.requireswidth", "Warning: <embed> tag requires width attribute."},
             {"appletviewer.parse.warning.appnotLongersupported", "Warning: <app> tag no longer supported, use <applet> instead:"},
             {"appletviewer.deprecated", "AppletViewer is deprecated."},
-            {"appletviewer.usage", "Usage: appletviewer <options> url(s)\n\nwhere <options> include:\n  -debug                  Start the applet viewer in the Java debugger\n  -encoding <encoding>    Specify character encoding used by HTML files\n  -J<runtime flag>        Pass argument to the java interpreter\n\nThe -J option is non-standard and subject to change without notice."},
+            {"appletviewer.usage", "Usage: appletviewer <options> url(s)\n\nwhere <options> include:\n  -encoding <encoding>    Specify character encoding used by HTML files\n  -J<runtime flag>        Pass argument to the java interpreter\n\nThe -J option is non-standard and subject to change without notice."},
             {"appletviewer.main.err.unsupportedopt", "Unsupported option: {0}"},
             {"appletviewer.main.err.unrecognizedarg", "Unrecognized argument: {0}"},
             {"appletviewer.main.err.dupoption", "Duplicate use of option: {0}"},