8139508: Debug option does not work in appletviewer
Reviewed-by: prr, ssadetsky
This commit is contained in:
parent
71681ac4cb
commit
b1ccba1fcb
@ -30,8 +30,6 @@ import java.io.File;
|
||||
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 @@ public class Main {
|
||||
/**
|
||||
* 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 @@ public class Main {
|
||||
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 @@ public class Main {
|
||||
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 @@ public class Main {
|
||||
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();
|
||||
|
@ -74,7 +74,7 @@ public class MsgAppletViewer extends ListResourceBundle {
|
||||
{"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}"},
|
||||
|
Loading…
Reference in New Issue
Block a user