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

当前正在使用的环境地址发生变化时,获取环境时会发生NPE #8

Closed
CodeXiaoMai opened this issue Nov 8, 2018 · 0 comments

Comments

@CodeXiaoMai
Copy link
Owner

开始 Music 环境配置如下,并且已切换当前环境为测试环境:

/**
 * 特殊模块 Music 的环境
 */
@Module(alias = "音乐")
private class Music {
    @Environment(url = "https://www.codexiaomai.top/api/", isRelease = true, alias = "正式")
    private String online;
    @Environment(url = "http://test.codexiaomai.top/api/", alias = "测试")
    private String test;
}

当修改 Music 模块的配置后(修改地址)

/**
 * 特殊模块 Music 的环境
 */
@Module(alias = "音乐")
private class Music {
    @Environment(url = "https://www.1222", isRelease = true, alias = "正式")
    private String online;
    @Environment(url = "http://test.2323", alias = "测试")
    private String test;
}

重新运行项目后,获取当前模块环境时会发生 NPE。

  • bug 原因:
    获取当前模块环境时,只有在 SharedPrefrences 中当前模块的地址和配置中的某个地址匹配时,才会给当前模块环境赋值,如果地址修改了,导致配置中没有地址和 SharedPreferences 中的地址匹配,所以当前模块为 NULL。

  • 解决方案:
    当配置中没有地址和 SharedPreferences 中的地址匹配时,当前模块指定为 DEFAULT(isRelease = true) 环境。

CodeXiaoMai pushed a commit that referenced this issue Nov 8, 2018
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

1 participant