1 /*
2  * Copyright (C) 2006 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 import java.lang.reflect.*;
18 import java.io.IOException;
19 import java.util.Collections;
20 import java.util.ArrayList;
21 import java.util.Arrays;
22 import java.util.List;
23 import java.util.Map;
24 import java.util.Set;
25 
26 /**
27  * Reflection test.
28  */
29 public class Main {
30     private static boolean FULL_ACCESS_CHECKS = false;  // b/5861201
Main()31     public Main() {}
Main(ArrayList<Integer> stuff)32     public Main(ArrayList<Integer> stuff) {}
33 
printMethodInfo(Method meth)34     void printMethodInfo(Method meth) {
35         Class[] params, exceptions;
36         int i;
37 
38         System.out.println("Method name is " + meth.getName());
39         System.out.println(" Declaring class is "
40             + meth.getDeclaringClass().getName());
41         params = meth.getParameterTypes();
42         for (i = 0; i < params.length; i++)
43             System.out.println(" Arg " + i + ": " + params[i].getName());
44         exceptions = meth.getExceptionTypes();
45         for (i = 0; i < exceptions.length; i++)
46             System.out.println(" Exc " + i + ": " + exceptions[i].getName());
47         System.out.println(" Return type is " + meth.getReturnType().getName());
48         System.out.println(" Access flags are 0x"
49             + Integer.toHexString(meth.getModifiers()));
50         //System.out.println(" GenericStr is " + meth.toGenericString());
51     }
52 
printFieldInfo(Field field)53     void printFieldInfo(Field field) {
54         System.out.println("Field name is " + field.getName());
55         System.out.println(" Declaring class is "
56             + field.getDeclaringClass().getName());
57         System.out.println(" Field type is " + field.getType().getName());
58         System.out.println(" Access flags are 0x"
59             + Integer.toHexString(field.getModifiers()));
60     }
61 
showStrings(Target instance)62     private void showStrings(Target instance)
63         throws NoSuchFieldException, IllegalAccessException {
64 
65         Class target = Target.class;
66         String one, two, three, four;
67         Field field = null;
68 
69         field = target.getField("string1");
70         one = (String) field.get(instance);
71 
72         field = target.getField("string2");
73         two = (String) field.get(instance);
74 
75         field = target.getField("string3");
76         three = (String) field.get(instance);
77 
78         System.out.println("  ::: " + one + ":" + two + ":" + three);
79     }
80 
checkAccess()81     public static void checkAccess() {
82         try {
83             Class target = otherpackage.Other.class;
84             Object instance = new otherpackage.Other();
85             Method meth;
86 
87             meth = target.getMethod("publicMethod", (Class[]) null);
88             meth.invoke(instance);
89 
90             try {
91                 meth = target.getMethod("packageMethod", (Class[]) null);
92                 System.err.println("succeeded on package-scope method");
93             } catch (NoSuchMethodException nsme) {
94                 // good
95             }
96 
97 
98             instance = otherpackage.Other.getInnerClassInstance();
99             target = instance.getClass();
100             meth = target.getMethod("innerMethod", (Class[]) null);
101             try {
102                 if (!FULL_ACCESS_CHECKS) { throw new IllegalAccessException(); }
103                 meth.invoke(instance);
104                 System.err.println("inner-method invoke unexpectedly worked");
105             } catch (IllegalAccessException iae) {
106                 // good
107             }
108 
109             Field field = target.getField("innerField");
110             try {
111                 int x = field.getInt(instance);
112                 if (!FULL_ACCESS_CHECKS) { throw new IllegalAccessException(); }
113                 System.err.println("field get unexpectedly worked: " + x);
114             } catch (IllegalAccessException iae) {
115                 // good
116             }
117         } catch (Exception ex) {
118             System.out.println("----- unexpected exception -----");
119             ex.printStackTrace();
120         }
121     }
122 
run()123     public void run() {
124         Class target = Target.class;
125         Method meth = null;
126         Field field = null;
127         boolean excep;
128 
129         try {
130             meth = target.getMethod("myMethod", new Class[] { int.class });
131 
132             if (meth.getDeclaringClass() != target)
133                 throw new RuntimeException();
134             printMethodInfo(meth);
135 
136             meth = target.getMethod("myMethod", new Class[] { float.class });
137             printMethodInfo(meth);
138 
139             meth = target.getMethod("myNoargMethod", (Class[]) null);
140             printMethodInfo(meth);
141 
142             meth = target.getMethod("myMethod",
143                 new Class[] { String[].class, float.class, char.class });
144             printMethodInfo(meth);
145 
146             Target instance = new Target();
147             Object[] argList = new Object[] {
148                 new String[] { "hi there" },
149                 new Float(3.1415926f),
150                 new Character('Q')
151             };
152             System.out.println("Before, float is "
153                 + ((Float)argList[1]).floatValue());
154 
155             Integer boxval;
156             boxval = (Integer) meth.invoke(instance, argList);
157             System.out.println("Result of invoke: " + boxval.intValue());
158 
159             System.out.println("Calling no-arg void-return method");
160             meth = target.getMethod("myNoargMethod", (Class[]) null);
161             meth.invoke(instance, (Object[]) null);
162 
163             /* try invoking a method that throws an exception */
164             meth = target.getMethod("throwingMethod", (Class[]) null);
165             try {
166                 meth.invoke(instance, (Object[]) null);
167                 System.out.println("GLITCH: didn't throw");
168             } catch (InvocationTargetException ite) {
169                 System.out.println("Invoke got expected exception:");
170                 System.out.println(ite.getClass().getName());
171                 System.out.println(ite.getCause());
172             }
173             catch (Exception ex) {
174                 System.out.println("GLITCH: invoke got wrong exception:");
175                 ex.printStackTrace();
176             }
177             System.out.println("");
178 
179 
180             field = target.getField("string1");
181             if (field.getDeclaringClass() != target)
182                 throw new RuntimeException();
183             printFieldInfo(field);
184             String strVal = (String) field.get(instance);
185             System.out.println("  string1 value is '" + strVal + "'");
186 
187             showStrings(instance);
188 
189             field.set(instance, new String("a new string"));
190             strVal = (String) field.get(instance);
191             System.out.println("  string1 value is now '" + strVal + "'");
192 
193             showStrings(instance);
194 
195             try {
196                 field.set(instance, new Object());
197                 System.out.println("WARNING: able to store Object into String");
198             }
199             catch (IllegalArgumentException iae) {
200                 System.out.println("  got expected illegal obj store exc");
201             }
202 
203 
204             try {
205                 String four;
206                 field = target.getField("string4");
207                 four = (String) field.get(instance);
208                 System.out.println("WARNING: able to access string4: "
209                     + four);
210             }
211             catch (IllegalAccessException iae) {
212                 System.out.println("  got expected access exc");
213             }
214             catch (NoSuchFieldException nsfe) {
215                 System.out.println("  got the other expected access exc");
216             }
217             try {
218                 String three;
219                 field = target.getField("string3");
220                 three = (String) field.get(this);
221                 System.out.println("WARNING: able to get string3 in wrong obj: "
222                     + three);
223             }
224             catch (IllegalArgumentException iae) {
225                 System.out.println("  got expected arg exc");
226             }
227 
228             /*
229              * Try setting a field to null.
230              */
231             String four;
232             field = target.getDeclaredField("string3");
233             field.set(instance, null);
234 
235             /*
236              * Do some stuff with long.
237              */
238             long longVal;
239             field = target.getField("pubLong");
240             longVal = field.getLong(instance);
241             System.out.println("pubLong initial value is " +
242                 Long.toHexString(longVal));
243             field.setLong(instance, 0x9988776655443322L);
244             longVal = field.getLong(instance);
245             System.out.println("pubLong new value is " +
246                 Long.toHexString(longVal));
247 
248 
249             field = target.getField("superInt");
250             if (field.getDeclaringClass() == target)
251                 throw new RuntimeException();
252             printFieldInfo(field);
253             int intVal = field.getInt(instance);
254             System.out.println("  superInt value is " + intVal);
255             Integer boxedIntVal = (Integer) field.get(instance);
256             System.out.println("  superInt boxed is " + boxedIntVal);
257 
258             field.set(instance, new Integer(20202));
259             intVal = field.getInt(instance);
260             System.out.println("  superInt value is now " + intVal);
261             field.setShort(instance, (short)30303);
262             intVal = field.getInt(instance);
263             System.out.println("  superInt value (from short) is now " +intVal);
264             field.setInt(instance, 40404);
265             intVal = field.getInt(instance);
266             System.out.println("  superInt value is now " + intVal);
267             try {
268                 field.set(instance, new Long(123));
269                 System.out.println("FAIL: expected exception not thrown");
270             }
271             catch (IllegalArgumentException iae) {
272                 System.out.println("  got expected long->int failure");
273             }
274             try {
275                 field.setLong(instance, 123);
276                 System.out.println("FAIL: expected exception not thrown");
277             }
278             catch (IllegalArgumentException iae) {
279                 System.out.println("  got expected long->int failure");
280             }
281             try {
282                 field.set(instance, new String("abc"));
283                 System.out.println("FAIL: expected exception not thrown");
284             }
285             catch (IllegalArgumentException iae) {
286                 System.out.println("  got expected string->int failure");
287             }
288 
289             try {
290                 field.getShort(instance);
291                 System.out.println("FAIL: expected exception not thrown");
292             }
293             catch (IllegalArgumentException iae) {
294                 System.out.println("  got expected int->short failure");
295             }
296 
297             field = target.getField("superClassInt");
298             printFieldInfo(field);
299             int superClassIntVal = field.getInt(instance);
300             System.out.println("  superClassInt value is " + superClassIntVal);
301 
302             field = target.getField("staticDouble");
303             printFieldInfo(field);
304             double staticDoubleVal = field.getDouble(null);
305             System.out.println("  staticDoubleVal value is " + staticDoubleVal);
306 
307             try {
308                 field.getLong(instance);
309                 System.out.println("FAIL: expected exception not thrown");
310             }
311             catch (IllegalArgumentException iae) {
312                 System.out.println("  got expected double->long failure");
313             }
314 
315             excep = false;
316             try {
317                 field = target.getField("aPrivateInt");
318                 printFieldInfo(field);
319             }
320             catch (NoSuchFieldException nsfe) {
321                 System.out.println("as expected: aPrivateInt not found");
322                 excep = true;
323             }
324             if (!excep)
325                 System.out.println("BUG: got aPrivateInt");
326 
327 
328             field = target.getField("constantString");
329             printFieldInfo(field);
330             String val = (String) field.get(instance);
331             System.out.println("  Constant test value is " + val);
332 
333 
334             field = target.getField("cantTouchThis");
335             printFieldInfo(field);
336             intVal = field.getInt(instance);
337             System.out.println("  cantTouchThis is " + intVal);
338             try {
339                 field.setInt(instance, 99);
340                 System.out.println("ERROR: set-final did not throw exception");
341             } catch (IllegalAccessException iae) {
342                 System.out.println("  as expected: set-final throws exception");
343             }
344             intVal = field.getInt(instance);
345             System.out.println("  cantTouchThis is still " + intVal);
346 
347             System.out.println("  " + field + " accessible=" + field.isAccessible());
348             field.setAccessible(true);
349             System.out.println("  " + field + " accessible=" + field.isAccessible());
350             field.setInt(instance, 87);     // exercise int version
351             intVal = field.getInt(instance);
352             System.out.println("  cantTouchThis is now " + intVal);
353             field.set(instance, 88);        // exercise Object version
354             intVal = field.getInt(instance);
355             System.out.println("  cantTouchThis is now " + intVal);
356 
357             Constructor<Target> cons;
358             Target targ;
359             Object[] args;
360 
361             cons = target.getConstructor(new Class[] { int.class,float.class });
362             args = new Object[] { new Integer(7), new Float(3.3333) };
363             System.out.println("cons modifiers=" + cons.getModifiers());
364             targ = cons.newInstance(args);
365             targ.myMethod(17);
366 
367             try {
368                 Thrower thrower = Thrower.class.newInstance();
369                 System.out.println("ERROR: Class.newInstance did not throw exception");
370             } catch (UnsupportedOperationException uoe) {
371                 System.out.println("got expected exception for Class.newInstance");
372             } catch (Exception e) {
373                 System.out.println("ERROR: Class.newInstance got unexpected exception: " +
374                                    e.getClass().getName());
375             }
376 
377             try {
378                 Constructor<Thrower> constructor = Thrower.class.getDeclaredConstructor();
379                 Thrower thrower = constructor.newInstance();
380                 System.out.println("ERROR: Constructor.newInstance did not throw exception");
381             } catch (InvocationTargetException ite) {
382                 System.out.println("got expected exception for Constructor.newInstance");
383             } catch (Exception e) {
384                 System.out.println("ERROR: Constructor.newInstance got unexpected exception: " +
385                                    e.getClass().getName());
386             }
387 
388         } catch (Exception ex) {
389             System.out.println("----- unexpected exception -----");
390             ex.printStackTrace();
391         }
392 
393         System.out.println("ReflectTest done!");
394     }
395 
checkType()396     public static void checkType() {
397         Method m;
398 
399         try {
400             m = Collections.class.getDeclaredMethod("checkType",
401                             Object.class, Class.class);
402         } catch (NoSuchMethodException nsme) {
403             nsme.printStackTrace();
404             return;
405         }
406         System.out.println(m + " accessible=" + m.isAccessible());
407         m.setAccessible(true);
408         System.out.println(m + " accessible=" + m.isAccessible());
409         try {
410             m.invoke(null, new Object(), Object.class);
411         } catch (IllegalAccessException iae) {
412             iae.printStackTrace();
413             return;
414         } catch (InvocationTargetException ite) {
415             ite.printStackTrace();
416             return;
417         }
418 
419         try {
420             String s = "Should be ignored";
421             m.invoke(s, new Object(), Object.class);
422         } catch (IllegalAccessException iae) {
423             iae.printStackTrace();
424             return;
425         } catch (InvocationTargetException ite) {
426             ite.printStackTrace();
427             return;
428         }
429 
430         try {
431             System.out.println("checkType invoking null");
432             m.invoke(null, new Object(), int.class);
433             System.out.println("ERROR: should throw InvocationTargetException");
434         } catch (InvocationTargetException ite) {
435             System.out.println("checkType got expected exception");
436         } catch (IllegalAccessException iae) {
437             iae.printStackTrace();
438             return;
439         }
440     }
441 
checkClinitForFields()442     public static void checkClinitForFields() throws Exception {
443       // Loading a class constant shouldn't run <clinit>.
444       System.out.println("calling const-class FieldNoisyInitUser.class");
445       Class niuClass = FieldNoisyInitUser.class;
446       System.out.println("called const-class FieldNoisyInitUser.class");
447 
448       // Getting the declared fields doesn't run <clinit>.
449       Field[] fields = niuClass.getDeclaredFields();
450       System.out.println("got fields");
451 
452       Field field = niuClass.getField("staticField");
453       System.out.println("got field");
454       field.get(null);
455       System.out.println("read field value");
456 
457       // FieldNoisyInitUser should now be initialized, but FieldNoisyInit shouldn't be initialized yet.
458       FieldNoisyInitUser niu = new FieldNoisyInitUser();
459       FieldNoisyInit ni = new FieldNoisyInit();
460 
461       System.out.println("");
462     }
463 
checkClinitForMethods()464     public static void checkClinitForMethods() throws Exception {
465       // Loading a class constant shouldn't run <clinit>.
466       System.out.println("calling const-class MethodNoisyInitUser.class");
467       Class niuClass = MethodNoisyInitUser.class;
468       System.out.println("called const-class MethodNoisyInitUser.class");
469 
470       // Getting the declared methods doesn't run <clinit>.
471       Method[] methods = niuClass.getDeclaredMethods();
472       System.out.println("got methods");
473 
474       Method method = niuClass.getMethod("staticMethod", (Class[]) null);
475       System.out.println("got method");
476       method.invoke(null);
477       System.out.println("invoked method");
478 
479       // MethodNoisyInitUser should now be initialized, but MethodNoisyInit shouldn't be initialized yet.
480       MethodNoisyInitUser niu = new MethodNoisyInitUser();
481       MethodNoisyInit ni = new MethodNoisyInit();
482 
483       System.out.println("");
484     }
485 
486 
487     /*
488      * Test some generic type stuff.
489      */
490     public List<String> dummy;
fancyMethod(ArrayList<String> blah)491     public Map<Integer,String> fancyMethod(ArrayList<String> blah) { return null; }
checkGeneric()492     public static void checkGeneric() {
493         Field field;
494         try {
495             field = Main.class.getField("dummy");
496         } catch (NoSuchFieldException nsfe) {
497             throw new RuntimeException(nsfe);
498         }
499         Type listType = field.getGenericType();
500         System.out.println("generic field: " + listType);
501 
502         Method method;
503         try {
504             method = Main.class.getMethod("fancyMethod",
505                 new Class[] { ArrayList.class });
506         } catch (NoSuchMethodException nsme) {
507             throw new RuntimeException(nsme);
508         }
509         Type[] parmTypes = method.getGenericParameterTypes();
510         Type ret = method.getGenericReturnType();
511         System.out.println("generic method " + method.getName() + " params='"
512             + stringifyTypeArray(parmTypes) + "' ret='" + ret + "'");
513 
514         Constructor ctor;
515         try {
516             ctor = Main.class.getConstructor(new Class[] { ArrayList.class });
517         } catch (NoSuchMethodException nsme) {
518             throw new RuntimeException(nsme);
519         }
520         parmTypes = ctor.getGenericParameterTypes();
521         System.out.println("generic ctor " + ctor.getName() + " params='"
522             + stringifyTypeArray(parmTypes) + "'");
523     }
524 
525     /*
526      * Convert an array of Type into a string.  Start with an array count.
527      */
stringifyTypeArray(Type[] types)528     private static String stringifyTypeArray(Type[] types) {
529         StringBuilder stb = new StringBuilder();
530         boolean first = true;
531 
532         stb.append("[" + types.length + "]");
533 
534         for (Type t: types) {
535             if (first) {
536                 stb.append(" ");
537                 first = false;
538             } else {
539                 stb.append(", ");
540             }
541             stb.append(t.toString());
542         }
543 
544         return stb.toString();
545     }
546 
checkUnique()547     public static void checkUnique() {
548         Field field1, field2;
549         try {
550             field1 = Main.class.getField("dummy");
551             field2 = Main.class.getField("dummy");
552         } catch (NoSuchFieldException nsfe) {
553             throw new RuntimeException(nsfe);
554         }
555         if (field1 == field2) {
556             System.out.println("ERROR: fields shouldn't have reference equality");
557         } else {
558             System.out.println("fields are unique");
559         }
560         if (field1.hashCode() == field2.hashCode() && field1.equals(field2)) {
561             System.out.println("fields are .equals");
562         } else {
563             System.out.println("ERROR: fields fail equality");
564         }
565         Method method1, method2;
566         try {
567             method1 = Main.class.getMethod("fancyMethod", new Class[] { ArrayList.class });
568             method2 = Main.class.getMethod("fancyMethod", new Class[] { ArrayList.class });
569         } catch (NoSuchMethodException nsme) {
570             throw new RuntimeException(nsme);
571         }
572         if (method1 == method2) {
573             System.out.println("ERROR: methods shouldn't have reference equality");
574         } else {
575             System.out.println("methods are unique");
576         }
577         if (method1.hashCode() == method2.hashCode() && method1.equals(method2)) {
578             System.out.println("methods are .equals");
579         } else {
580             System.out.println("ERROR: methods fail equality");
581         }
582     }
583 
checkParametrizedTypeEqualsAndHashCode()584     public static void checkParametrizedTypeEqualsAndHashCode() {
585         Method method1;
586         Method method2;
587         Method method3;
588         try {
589             method1 = ParametrizedTypeTest.class.getDeclaredMethod("aMethod", Set.class);
590             method2 = ParametrizedTypeTest.class.getDeclaredMethod("aMethod", Set.class);
591             method3 = ParametrizedTypeTest.class.getDeclaredMethod("aMethodIdentical", Set.class);
592         } catch (NoSuchMethodException nsme) {
593             throw new RuntimeException(nsme);
594         }
595 
596         List<Type> types1 = Arrays.asList(method1.getGenericParameterTypes());
597         List<Type> types2 = Arrays.asList(method2.getGenericParameterTypes());
598         List<Type> types3 = Arrays.asList(method3.getGenericParameterTypes());
599 
600         Type type1 = types1.get(0);
601         Type type2 = types2.get(0);
602         Type type3 = types3.get(0);
603 
604         if (type1 instanceof ParameterizedType) {
605             System.out.println("type1 is a ParameterizedType");
606         }
607         if (type2 instanceof ParameterizedType) {
608             System.out.println("type2 is a ParameterizedType");
609         }
610         if (type3 instanceof ParameterizedType) {
611             System.out.println("type3 is a ParameterizedType");
612         }
613 
614         if (type1.equals(type2)) {
615             System.out.println("type1("+type1+") equals type2("+type2+")");
616         } else {
617             System.out.println("type1("+type1+") does not equal type2("+type2+")");
618         }
619 
620         if (type1.equals(type3)) {
621             System.out.println("type1("+type1+") equals type3("+type3+")");
622         } else {
623             System.out.println("type1("+type1+") does not equal type3("+type3+")");
624         }
625         if (type1.hashCode() == type2.hashCode()) {
626             System.out.println("type1("+type1+") hashCode equals type2("+type2+") hashCode");
627         } else {
628             System.out.println(
629                    "type1("+type1+") hashCode does not equal type2("+type2+") hashCode");
630         }
631 
632         if (type1.hashCode() == type3.hashCode()) {
633             System.out.println("type1("+type1+") hashCode equals type3("+type3+") hashCode");
634         } else {
635             System.out.println(
636                     "type1("+type1+") hashCode does not equal type3("+type3+") hashCode");
637         }
638     }
639 
checkGenericArrayTypeEqualsAndHashCode()640     public static void checkGenericArrayTypeEqualsAndHashCode() {
641         Method method1;
642         Method method2;
643         Method method3;
644         try {
645             method1 = GenericArrayTypeTest.class.getDeclaredMethod("aMethod", Object[].class);
646             method2 = GenericArrayTypeTest.class.getDeclaredMethod("aMethod", Object[].class);
647             method3 = GenericArrayTypeTest.class.getDeclaredMethod("aMethodIdentical", Object[].class);
648         } catch (NoSuchMethodException nsme) {
649             throw new RuntimeException(nsme);
650         }
651 
652         List<Type> types1 = Arrays.asList(method1.getGenericParameterTypes());
653         List<Type> types2 = Arrays.asList(method2.getGenericParameterTypes());
654         List<Type> types3 = Arrays.asList(method3.getGenericParameterTypes());
655 
656         Type type1 = types1.get(0);
657         Type type2 = types2.get(0);
658         Type type3 = types3.get(0);
659 
660         if (type1 instanceof GenericArrayType) {
661             System.out.println("type1 is a GenericArrayType");
662         }
663         if (type2 instanceof GenericArrayType) {
664             System.out.println("type2 is a GenericArrayType");
665         }
666         if (type3 instanceof GenericArrayType) {
667             System.out.println("type3 is a GenericArrayType");
668         }
669 
670         if (type1.equals(type2)) {
671             System.out.println("type1("+type1+") equals type2("+type2+")");
672         } else {
673             System.out.println("type1("+type1+") does not equal type2("+type2+")");
674         }
675 
676         if (type1.equals(type3)) {
677             System.out.println("type1("+type1+") equals type3("+type3+")");
678         } else {
679             System.out.println("type1("+type1+") does not equal type3("+type3+")");
680         }
681         if (type1.hashCode() == type2.hashCode()) {
682             System.out.println("type1("+type1+") hashCode equals type2("+type2+") hashCode");
683         } else {
684             System.out.println(
685                    "type1("+type1+") hashCode does not equal type2("+type2+") hashCode");
686         }
687 
688         if (type1.hashCode() == type3.hashCode()) {
689             System.out.println("type1("+type1+") hashCode equals type3("+type3+") hashCode");
690         } else {
691             System.out.println(
692                     "type1("+type1+") hashCode does not equal type3("+type3+") hashCode");
693         }
694     }
695 
main(String[] args)696     public static void main(String[] args) throws Exception {
697         Main test = new Main();
698         test.run();
699 
700         checkAccess();
701         checkType();
702         checkClinitForFields();
703         checkClinitForMethods();
704         checkGeneric();
705         checkUnique();
706         checkParametrizedTypeEqualsAndHashCode();
707         checkGenericArrayTypeEqualsAndHashCode();
708     }
709 }
710 
711 
712 class SuperTarget {
SuperTarget()713     public SuperTarget() {
714         System.out.println("SuperTarget constructor ()V");
715         superInt = 1010101;
716         superClassInt = 1010102;
717     }
718 
myMethod(float floatArg)719     public int myMethod(float floatArg) {
720         System.out.println("myMethod (F)I " + floatArg);
721         return 6;
722     }
723 
724     public int superInt;
725     public static int superClassInt;
726 }
727 
728 class Target extends SuperTarget {
Target()729     public Target() {
730         System.out.println("Target constructor ()V");
731     }
732 
Target(int ii, float ff)733     public Target(int ii, float ff) {
734         System.out.println("Target constructor (IF)V : ii="
735             + ii + " ff=" + ff);
736         anInt = ii;
737     }
738 
myMethod(int intarg)739     public int myMethod(int intarg) throws NullPointerException, IOException {
740         System.out.println("myMethod (I)I");
741         System.out.println(" arg=" + intarg + " anInt=" + anInt);
742         return 5;
743     }
744 
myMethod(String[] strarg, float f, char c)745     public int myMethod(String[] strarg, float f, char c) {
746         System.out.println("myMethod: " + strarg[0] + " " + f + " " + c + " !");
747         return 7;
748     }
749 
myNoargMethod()750     public static void myNoargMethod() {
751         System.out.println("myNoargMethod ()V");
752     }
753 
throwingMethod()754     public void throwingMethod() {
755         System.out.println("throwingMethod");
756         throw new NullPointerException("gratuitous throw!");
757     }
758 
misc()759     public void misc() {
760         System.out.println("misc");
761     }
762 
763     public int anInt;
764     public String string1 = "hey";
765     public String string2 = "yo";
766     public String string3 = "there";
767     private String string4 = "naughty";
768     public static final String constantString = "a constant string";
769     private int aPrivateInt;
770 
771     public final int cantTouchThis = 77;
772 
773     public long pubLong = 0x1122334455667788L;
774 
775     public static double staticDouble = 3.3;
776 }
777 
778 class FieldNoisyInit {
779   static {
780     System.out.println("FieldNoisyInit is initializing");
781     //Throwable th = new Throwable();
782     //th.printStackTrace();
783   }
784 }
785 
786 class FieldNoisyInitUser {
787   static {
788     System.out.println("FieldNoisyInitUser is initializing");
789   }
790   public static int staticField;
791   public static FieldNoisyInit noisy;
792 }
793 
794 class MethodNoisyInit {
795   static {
796     System.out.println("MethodNoisyInit is initializing");
797     //Throwable th = new Throwable();
798     //th.printStackTrace();
799   }
800 }
801 
802 class MethodNoisyInitUser {
803   static {
804     System.out.println("MethodNoisyInitUser is initializing");
805   }
staticMethod()806   public static void staticMethod() {}
createMethodNoisyInit(MethodNoisyInit ni)807   public void createMethodNoisyInit(MethodNoisyInit ni) {}
808 }
809 
810 class Thrower {
Thrower()811   public Thrower() throws UnsupportedOperationException {
812     throw new UnsupportedOperationException();
813   }
814 }
815 
816 class ParametrizedTypeTest {
aMethod(Set<String> names)817     public void aMethod(Set<String> names) {}
aMethodIdentical(Set<String> names)818     public void aMethodIdentical(Set<String> names) {}
819 }
820 
821 class GenericArrayTypeTest<T> {
aMethod(T[] names)822     public void aMethod(T[] names) {}
aMethodIdentical(T[] names)823     public void aMethodIdentical(T[] names) {}
824 }
825