MCPcopy Create free account
hub / github.com/LFYSec/MScan / ReflectiveAction

Class ReflectiveAction

src/test/resources/pta/reflection/ReflectiveAction.java:6–87  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

4import java.lang.reflect.Method;
5
6public class ReflectiveAction {
7 public static void main(String[] args) throws Exception {
8 forname(null);
9 cnew();
10 ctornew();
11 arraynew();
12 invoke();
13 get();
14 set();
15 }
16
17 static void forname(W w) throws Exception {
18 Class<?> uClass = Class.forName("U");
19 Object a = uClass.newInstance();
20 a.hashCode();
21
22 Class<?> vClass = Class.forName("V", true, uClass.getClassLoader());
23 Object b = vClass.newInstance();
24 b.hashCode();
25
26 Class<?> wClass1 = Class.forName("W");
27 use(wClass1);
28
29 Class<?> wClass2 = Class.forName("W", true, uClass.getClassLoader());
30 use(wClass2);
31 }
32
33 static void cnew() throws Exception {
34 Class<U> klass = U.class;
35 U u = klass.newInstance();
36 u.foo();
37 }
38
39 static void ctornew() throws Exception {
40 Class<U> klass = U.class;
41 Constructor<U> ctor = klass.getConstructor(V.class);
42 U u = ctor.newInstance(new V());
43 u.foo(null);
44 }
45
46 static void arraynew() throws Exception {
47 Class<?> uClass = new U().getClass();
48 U[] arr = (U[]) Array.newInstance(uClass, 10);
49 arr[0] = new U();
50 }
51
52 static void invoke() throws Exception {
53 // invoke static method
54 Method staticFoo = U.class.getMethod("staticFoo", Object.class);
55 staticFoo.invoke(null, new Object[]{null});
56
57 // invoke instance method
58 Method baz = V.class.getMethod("baz", V.class, String.class);
59 Object o = baz.invoke(new U(), new V(), "arg");
60 use(o);
61 }
62
63 static void get() throws Exception {

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected