Meituan-Dianping / Robust

Robust is an Android HotFix solution with high compatibility and high stability. Robust can fix bugs immediately without a reboot.
Apache License 2.0
4.42k stars 807 forks source link

加载补丁报Attempt to invoke virtual method 'java.lang.Object java.lang.reflect.Method.invoke(java.lang.Object, java.lang.Object[])' on a null object reference #195

Closed dropperY closed 6 years ago

dropperY commented 7 years ago

一个简单的修复demo报错

就是简单修改了fuckB方法,并且新加了个fuckC方法替换了fuckD,加载补丁时找不到fuckC 修改内容,

  @Modify
    public  String fuckB() {
        if (!isFuck) {
            return "b";
        } else  {
            return fuckC();
        }
    }

    public String fuckFB() {
        return "FB";
    }

    public String fuckD() {
        return "D";
    }

    @Add
    public String fuckC() {
        return "C";
    }

下面是我用jadx看到的补丁内相关代码

 public String fuckB() {
        if (this instanceof FuckLibararyPatch) {
            Object obj = this.originClass;
        } else {
            FuckLibararyPatch fuckLibararyPatch = this;
        }
        if (!((Boolean) EnhancedRobustUtils.getFieldValue("isFuck", obj, FuckLibarary.class)).booleanValue()) {
            return "b";
        }
        Object obj2;
        if (this == this) {
            obj2 = this.originClass;
        }
        return (String) EnhancedRobustUtils.invokeReflectMethod("fuckC", obj2, new Object[0], null, FuckLibarary.class);
    }

    public String fuckC() {
        return "C";
    }

堆栈/日志:

09-11 15:58:19.174 12282-12294/? 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
09-11 15:58:19.175 12282-12294/? W/System.err:     at com.meituan.robust.utils.EnhancedRobustUtils.invokeReflectMethod(EnhancedRobustUtils.java:34)

异常类型:app运行时异常

手机型号:如:Nexus 5

手机系统版本:如:Android 7.0

Robust版本:如:0.4.7

Gradle版本:如:2.3.3

系统:如:Mac

hedex commented 7 years ago

@dropperY 试试0.4.9版本呢?

BeanChan1987 commented 6 years ago

我也一样的报这个错误,很简单的一个测试。

@Override @Modify protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); version = (TextView) findViewById(R.id.showVersion); version.setText("这是我的第一个版本"); btn = (Button) findViewById(R.id.test); init(); version.setText(getNewStringData()); }

private void init() {
    btn.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            if (isGrantSDCardReadPermission()) {
                loadPath();
            } else {
                requestPermission();
            }

        }
    });
}

@Add
public String getNewStringData(){
    return "HotFix Robust";
}
hedex commented 6 years ago

demo可以发给我们看看吗?

2017年10月23日 14:18,"BeanChan1987" notifications@github.com写道:

@override https://github.com/override @modify https://github.com/modify protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); version = (TextView) findViewById(R.id.showVersion); version.setText("这是我的第一个版本"); btn = (Button) findViewById(R.id.test); init(); version.setText(getNewStringData()); }

private void init() { btn.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { if (isGrantSDCardReadPermission()) { loadPath(); } else { requestPermission(); }

    }
});

}

@Add public String getNewStringData(){ return "HotFix Robust"; }

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/Meituan-Dianping/Robust/issues/195#issuecomment-338557985, or mute the thread https://github.com/notifications/unsubscribe-auth/AHgyAXIkDVHl90H26JF85BVrPhxWgmwaks5svC-WgaJpZM4PSy0m .

wwzlp commented 5 years ago

demo可以发给我们看看吗? 2017年10月23日 14:18,"BeanChan1987" notifications@github.com写道: @override https://github.com/override @modify https://github.com/modify protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); version = (TextView) findViewById(R.id.showVersion); version.setText("这是我的第一个版本"); btn = (Button) findViewById(R.id.test); init(); version.setText(getNewStringData()); } private void init() { btn.setOnClickListener(new View.OnClickListener() { @override public void onClick(View view) { if (isGrantSDCardReadPermission()) { loadPath(); } else { requestPermission(); } } }); } @add public String getNewStringData(){ return "HotFix Robust"; } — You are receiving this because you commented. Reply to this email directly, view it on GitHub <#195 (comment)>, or mute the thread https://github.com/notifications/unsubscribe-auth/AHgyAXIkDVHl90H26JF85BVrPhxWgmwaks5svC-WgaJpZM4PSy0m .

我就不明白了,我现在也是0.4.9,和上面一样的错误,也只是简单修改了,我刚提的issue。根本没解决你close掉?

wwzlp commented 5 years ago

demo可以发给我们看看吗? 2017年10月23日 14:18,"BeanChan1987" notifications@github.com写道: @override https://github.com/override @modify https://github.com/modify protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); version = (TextView) findViewById(R.id.showVersion); version.setText("这是我的第一个版本"); btn = (Button) findViewById(R.id.test); init(); version.setText(getNewStringData()); } private void init() { btn.setOnClickListener(new View.OnClickListener() { @override public void onClick(View view) { if (isGrantSDCardReadPermission()) { loadPath(); } else { requestPermission(); } } }); } @add public String getNewStringData(){ return "HotFix Robust"; } — You are receiving this because you commented. Reply to this email directly, view it on GitHub <#195 (comment)>, or mute the thread https://github.com/notifications/unsubscribe-auth/AHgyAXIkDVHl90H26JF85BVrPhxWgmwaks5svC-WgaJpZM4PSy0m .

我就不明白了,我现在也是0.4.9,和上面一样的错误,也只是简单修改了,我刚提的issue。根本没解决你close掉?

HuRuWo commented 4 years ago

老问题了 我也出现了 0.4.99版本

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