/** Hang so that test fails */ static void hang() { try { // ten minute nap Thread.currentThread().sleep(10 * 60 * 1000); } catch (InterruptedException exc) { // shouldn't happen } }
class EarlyReturnTarg { static boolean debuggerWatching = false; static int failureCount = 0; /* * These are the values that will be used by methods * returning normally. */ static URL[] urls = new URL[1]; public static byte byteValue = 89; public static char charValue = 'x'; public static double doubleValue = 2.2; public static float floatValue = 3.3f; public static int intValue = 1; public static long longValue = Long.MAX_VALUE; public static short shortValue = 8; public static boolean booleanValue = false; public static Class classValue = Object.class; public static ClassLoader classLoaderValue; { try { urls[0] = new URL("hi there"); } catch (java.net.MalformedURLException ee) { } classLoaderValue = new URLClassLoader(urls); } public static Thread threadValue = Thread.currentThread(); public static ThreadGroup threadGroupValue = threadValue.getThreadGroup(); public static String stringValue = "abc"; public static int[] intArrayValue = new int[] {1, 2, 3}; public static EarlyReturnTarg objectValue = new EarlyReturnTarg(); public String ivar = stringValue; /* * These are the values that will be used by methods * returning early. These are != the normal values * defined above. */ static URL[] eurls = new URL[1]; public static byte ebyteValue = 42; public static char echarValue = 'a'; public static double edoubleValue = 6.6; public static float efloatValue = 9.9f; public static int eintValue = 7; public static long elongValue = Long.MIN_VALUE; public static short eshortValue = 3; public static boolean ebooleanValue = true; public static Class eclassValue = String.class; public static ClassLoader eclassLoaderValue; { try { urls[0] = new URL("been there, done that"); } catch (java.net.MalformedURLException ee) { } classLoaderValue = new URLClassLoader(urls); } public static Thread ethreadValue; public static ThreadGroup ethreadGroupValue; public static String estringValue = "wxyz"; public static int[] eintArrayValue = new int[] {10, 11, 12}; public static java.util.Date eobjectValue = new java.util.Date(); // Used to check the return values seen on the debugee side public static boolean chk(byte v) { return v == (debuggerWatching ? ebyteValue : byteValue); } public static boolean chk(char v) { return v == (debuggerWatching ? echarValue : charValue); } public static boolean chk(double v) { return v == (debuggerWatching ? edoubleValue : doubleValue); } public static boolean chk(float v) { return v == (debuggerWatching ? efloatValue : floatValue); } public static boolean chk(int v) { return v == (debuggerWatching ? eintValue : intValue); } public static boolean chk(long v) { return v == (debuggerWatching ? elongValue : longValue); } public static boolean chk(short v) { return v == (debuggerWatching ? eshortValue : shortValue); } public static boolean chk(boolean v) { return v == (debuggerWatching ? ebooleanValue : booleanValue); } public static boolean chk(String v) { return v.equals(debuggerWatching ? estringValue : stringValue); } public static boolean chk(Object v) { return v.equals(debuggerWatching ? eobjectValue : objectValue); } // Used to show which set of tests follows public static String s_show(String p1) { return p1; } // These are the static methods public static byte s_bytef(int p1) { return byteValue; } public static char s_charf() { return charValue; } public static double s_doublef() { return doubleValue; } public static float s_floatf() { return floatValue; } public static int s_intf() { return intValue; } public static long s_longf() { return longValue; } public static short s_shortf() { return shortValue; } public static boolean s_booleanf() { return booleanValue; } public static String s_stringf() { return stringValue; } public static Class s_classf() { return classValue; } public static ClassLoader s_classLoaderf() { return classLoaderValue; } public static Thread s_threadf() { return threadValue; } public static ThreadGroup s_threadGroupf() { return threadGroupValue; } public static int[] s_intArrayf() { return intArrayValue; } public static Object s_nullObjectf() { return null; } public static Object s_objectf() { return objectValue; } public static void s_voidf() { System.err.println("debugee in s_voidf"); } // These are the instance methods public byte i_bytef(int p1) { return byteValue; } public char i_charf() { return charValue; } public double i_doublef() { return doubleValue; } public float i_floatf() { return floatValue; } public int i_intf() { return intValue; } public long i_longf() { return longValue; } public short i_shortf() { return shortValue; } public boolean i_booleanf() { return booleanValue; } public String i_stringf() { return stringValue; } public Class i_classf() { return classValue; } public ClassLoader i_classLoaderf() { return classLoaderValue; } public Thread i_threadf() { return threadValue; } public ThreadGroup i_threadGroupf() { return threadGroupValue; } public int[] i_intArrayf() { return intArrayValue; } public Object i_nullObjectf() { return null; } public Object i_objectf() { return objectValue; } public void i_voidf() {} static void doit(EarlyReturnTarg xx) throws Exception { System.err.print("debugee in doit "); if (debuggerWatching) { System.err.println("with a debugger watching. Early returns expected."); } else { System.err.println("with no debugger watching. Normal returns."); } s_show("========== Testing static methods ================"); if (!chk(s_bytef(88))) failureCount++; if (!chk(s_charf())) failureCount++; if (!chk(s_doublef())) failureCount++; if (!chk(s_floatf())) failureCount++; if (!chk(s_intf())) failureCount++; if (!chk(s_longf())) failureCount++; if (!chk(s_shortf())) failureCount++; if (!chk(s_booleanf())) failureCount++; if (!chk(s_stringf())) failureCount++; s_classf(); s_classLoaderf(); s_threadf(); s_threadGroupf(); s_intArrayf(); s_nullObjectf(); if (!chk(s_objectf())) failureCount++; s_voidf(); s_show("========== Testing instance methods ================"); if (!chk(xx.i_bytef(89))) failureCount++; if (!chk(xx.i_charf())) failureCount++; if (!chk(xx.i_doublef())) failureCount++; if (!chk(xx.i_floatf())) failureCount++; if (!chk(xx.i_intf())) failureCount++; if (!chk(xx.i_longf())) failureCount++; if (!chk(xx.i_shortf())) failureCount++; if (!chk(xx.i_booleanf())) failureCount++; if (!chk(xx.i_stringf())) failureCount++; xx.i_intArrayf(); xx.i_classf(); xx.i_classLoaderf(); xx.i_threadf(); xx.i_threadGroupf(); xx.i_nullObjectf(); if (!chk(xx.i_objectf())) failureCount++; xx.i_voidf(); } /** Hang so that test fails */ static void hang() { try { // ten minute nap Thread.currentThread().sleep(10 * 60 * 1000); } catch (InterruptedException exc) { // shouldn't happen } } public static void main(String[] args) throws Exception { // The debugger will stop at the start of main, // set breakpoints and then do a resume. System.err.println("debugee in main"); EarlyReturnTarg xx = new EarlyReturnTarg(); doit(xx); if (debuggerWatching && failureCount > 0) { hang(); throw new Exception("EarlyReturnTarg: failed"); } } }