Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

android gradle 2.1.2环境下,解析匿名内部类的时候,会卡死 #778

Closed
voiddog opened this issue Aug 15, 2016 · 6 comments
Closed

Comments

@voiddog
Copy link

voiddog commented Aug 15, 2016

2.1.2 编译出来的内部类的 this$0public final,所以使用 getFields会返回。
这样会导致 JSON.toJSONBytes(obj) 的时候,去解析了 this$0
我测试项目中的this$0是一个 MainActivity,里面有个getAction的方法,但是没有相应action, _action, 'm_action'的成员变量。
这样ParseConfig去计算getField的时候会遍历所有的父类,MainActivty有11层父类,每一层都会去找 fieldName,_fieldName, m_fieldName这三个属性值,所以找到最后一层Context的时候会有100*3^12 的计算量,在这边就卡死了。
我认为对于 getAction(),计算所有的组合是没必要的,方便起见计算action, _action, 'm_action'就可以了,如果_m_action, m__m_action, _m_m_action... 等所有的情况都计算的话,层数一多很耗时。

@wenshao wenshao added this to the 1.1.54.android milestone Aug 18, 2016
@wenshao
Copy link
Member

wenshao commented Aug 25, 2016

能提供一下类信息么,方便我重现

@voiddog
Copy link
Author

voiddog commented Aug 25, 2016

public class JsonParseTest extends AppCompatActivity{
    public void runTest(){
        long now = System.currentTimeMillis();
        JSON.toJSON(new RequestData(){});
        Log.i("PARSE TIME", " cost time: " + (System.currentTimeMillis() - now) + "ms");
    }
}

abstract class RequestData{
}

然后运行runTest就会卡主,RequestData(){} 匿名内部类中的 this$0public final

wenshao added a commit that referenced this issue Aug 28, 2016
wenshao added a commit that referenced this issue Aug 28, 2016
@wenshao wenshao modified the milestones: 1.2.18, 1.1.54.android, 1.2.17 Aug 28, 2016
@wenshao
Copy link
Member

wenshao commented Aug 28, 2016

提交的代码,注释写错了issue,应该是#779,请忽略

wenshao added a commit that referenced this issue Aug 28, 2016
@wenshao wenshao closed this as completed Aug 28, 2016
@wenshao
Copy link
Member

wenshao commented Aug 28, 2016

问题已经修复,我会在今天发布一个版本

@wenshao wenshao reopened this Aug 28, 2016
@wenshao
Copy link
Member

wenshao commented Aug 28, 2016

问题没有完全解决,悲剧了。。。

@wenshao
Copy link
Member

wenshao commented Nov 20, 2016

请使用最新版本1.1.55.android

@wenshao wenshao closed this as completed Nov 20, 2016
wenshao added a commit that referenced this issue Jul 17, 2019
wenshao added a commit that referenced this issue Jul 17, 2019
asa1997 pushed a commit to Be-Secure/fastjson that referenced this issue Feb 8, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants