|
35 | 35 | import java.io.File; |
36 | 36 | import java.io.FileOutputStream; |
37 | 37 | import java.lang.instrument.ClassFileTransformer; |
38 | | -import java.lang.reflect.Method; |
| 38 | +import java.lang.reflect.Executable; |
39 | 39 | import java.lang.reflect.Parameter; |
40 | 40 | import java.nio.file.Files; |
41 | 41 | import java.nio.file.Paths; |
|
59 | 59 | class MethodParametersTarget { |
60 | 60 | // The class contains the only method, so we don't have issue with method sorting |
61 | 61 | // and ClassFileReconstituter should restore the same bytes as original classbytes. |
62 | | - public void method1( |
| 62 | + // This method should be ctor, otherwise default ctor will be implicitly declared. |
| 63 | + public MethodParametersTarget( |
63 | 64 | int intParam1, String stringParam1 // @1 commentout |
64 | 65 | // @1 uncomment int intParam2, String stringParam2 |
65 | 66 | ) |
@@ -99,8 +100,8 @@ private void log(Object o) { |
99 | 100 |
|
100 | 101 | private Parameter[] getTargetMethodParameters() throws ClassNotFoundException { |
101 | 102 | Class cls = Class.forName(targetClassName); |
102 | | - // the class contains 1 method (method1) |
103 | | - Method method = cls.getDeclaredMethods()[0]; |
| 103 | + // the class contains 1 method (ctor) |
| 104 | + Executable method = cls.getDeclaredConstructors()[0]; |
104 | 105 | Parameter[] params = method.getParameters(); |
105 | 106 | log("Params of " + method.getName() + " method (" + params.length + "):"); |
106 | 107 | for (int i = 0; i < params.length; i++) { |
@@ -174,7 +175,7 @@ private void compareClassBytes(byte[] expected, byte[] actual) throws Exception |
174 | 175 | } |
175 | 176 | log("Class bytes are different."); |
176 | 177 | printDisassembled("expected", expected); |
177 | | - printDisassembled("expected", actual); |
| 178 | + printDisassembled("actual", actual); |
178 | 179 | fail(targetClassName + " did not match .class file"); |
179 | 180 | } |
180 | 181 |
|
|
0 commit comments