Meituan-Dianping / Meituan-Dianping/Robust
Modify 方法嵌套 Add 方法,导致反射调用 Add 方法失败
Nobody has claimed this yet.
- Dominant language
- Java
- Stars
- 4.5k
- Forks
- 806
- PR merge metrics
- No merged PRs in 30d
Description
异常类型:app运行时异常,反射Add方法调用失败
手机型号:OnePlus3
手机系统版本:如:Android 8.0
Robust版本:0.4.78
Gradle版本:3.3
系统:Mac
堆栈/日志:
04-11 10:13:34.965 11645-11645/com.zhangdan.app W/System.err: java.lang.NullPointerException: Attempt to invoke virtual method 'java.lang.Object java.lang.reflect.Method.invoke(java.lang.Object, java.lang.Object[])' on a null object reference
04-11 10:13:34.968 11645-11645/com.zhangdan.app W/System.err: at com.meituan.robust.utils.EnhancedRobustUtils.invokeReflectMethod(EnhancedRobustUtils.java:34)
04-11 10:13:34.969 11645-11645/com.zhangdan.app W/System.err: at com.meituan.robust.patch.MeFragmentPatch.initView(MeFragmentPatch.java:115)
04-11 10:13:34.971 11645-11645/com.zhangdan.app W/System.err: at com.meituan.robust.patch.MeFragmentPatch.RobustPublicinitView(Unknown Source:0)
04-11 10:13:34.972 11645-11645/com.zhangdan.app W/System.err: at com.meituan.robust.patch.MeFragmentPatchControl.accessDispatch(Unknown Source:141)
04-11 10:13:34.974 11645-11645/com.zhangdan.app W/System.err: at com.meituan.robust.PatchProxy.accessDispatch(PatchProxy.java:94)
04-11 10:13:34.975 11645-11645/com.zhangdan.app W/System.err: at com.meituan.robust.PatchProxy.proxy(PatchProxy.java:44)
04-11 10:13:34.977 11645-11645/com.zhangdan.app W/System.err: at com.zhangdan.app.me.ui.MeFragment.initView(Unknown Source:12)
04-11 10:13:34.978 11645-11645/com.zhangdan.app W/System.err: at com.zhangdan.app.me.ui.MeFragment.onViewCreated(MeFragment.java:101)
修改方法如下:
@Modify
private void initView() {
Log.d("MeFragment initView", "MeFragment 修复非static方法");
initRefreshView();
initConfigItemsView();
initHeadView();
Log.d(AddFixCls.getInstance().getRobustTag(), getFixString());
}
@Add
private String getFixString() {
return "在类中新增非static方法";
}
其中 AddFixCls 是新增类,调用是没问题的,可以正常调用到,最终问题出在调用 getFixString() 方法上。
反编译patch如下:
patch.class
private void initView() {
...
obj = (AddFixCls) EnhancedRobustUtils.invokeReflectStaticMethod("getInstance", AddFixCls.class, getRealParameter(new Object[0]), null);
if (obj == this) {
obj = ((MeFragmentPatch) obj).originClass;
}
String str = (String) EnhancedRobustUtils.invokeReflectMethod("getRobustTag", obj, new Object[0], null, AddFixCls.class);
Log.d("robust", "invoke method is No: 162 getRobustTag");
if (this == this) {
obj2 = this.originClass;
} else {
MeFragmentPatch meFragmentPatch2 = this;
}
//问题出在这里,obj2 实际上应该是 patch 类,但是被转成了originClass,去调用新增的 add 方法当然是调用不到的。
String str2 = (String) EnhancedRobustUtils.invokeReflectMethod("getFixString", obj2, new Object[0], null, MeFragment.class);
Log.d("robust", "invoke method is No: 163 getFixString");
((Integer) EnhancedRobustUtils.invokeReflectStaticMethod("d", Log.class, getRealParameter(new Object[]{str, str2}), new Class[]{String.class, String.class})).intValue();
}
private String getFixString() {
return "在类中新增非static方法";
}
问题出在这里,obj2 实际上应该是 patch 类,但是被转成了originClass,去调用新增的 add 方法当然是调用不到的。
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by tracing the generated patch for the nested @Modify and @Add methods, especially initView and EnhancedRobustUtils.invokeReflectMethod at EnhancedRobustUtils.java:34. Reproduce the case and inspect why getFixString is invoked with the origin object; done means the added method is invoked on the correct patch object without the reported null-method failure.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- android, java
- Domain
- mobile-dev
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100