java - ProGuard:ClassCastException

标签 java gson proguard obfuscation

当我混淆我的 Java 代码时(在我使用 ProGuard 混淆之前工作正常),我遇到了这个恼人的 ClassCastException

   java.lang.ClassCastException: com.google.gson.internal.StringMap cannot be cast to net.minecraft.launcher.profile.Profile
        at java.lang.ClassCastException: com.google.gson.internal.StringMap cannot be cast to net.minecraft.launcher.profile.Profile
at net.minecraft.launcher.profile.ProfileManager.getSelectedProfile(SourceFile:117)
at net.minecraft.launcher.g.run(SourceFile:184)
at java.util.concurrent.Executors$RunnableAdapter.call(Unknown Source)
at java.util.concurrent.FutureTask.run(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)

ClastCastException 错误指向这段代码,在这里(粗体行是确切的行):

public Profile getSelectedProfile()
{
    if ((this.selectedProfile == null) || (!this.profiles.containsKey(this.selectedProfile))) {
        if (this.profiles.get("Default") != null)
        {
            this.selectedProfile = "Default";
        }
        else if (this.profiles.size() > 0)
        {
            this.selectedProfile = ((Profile)this.profiles.values().iterator().next()).getName();
        }
        else
        {
            this.selectedProfile = "Default";
            this.profiles.put("Default", new Profile(this.selectedProfile));
        }
    }
    *Profile profile = this.profiles.get(this.selectedProfile);*
    return profile;
}

整个类文件(未混淆):http://pastebin.com/Jgh4x1SS RawProfileList 类文件(未混淆):http://pastebin.com/vPxFpYfC ProGuard 版本:5.2.1

配置文件声明:

private final Map<String, Profile> profiles = new HashMap<String, Profile>();

最佳答案

您的类(class)看起来不错。 ClassCastException 意味着 Gson 不知道一个字段应该被序列化为 Profile

确保您的 proguard.cfg 包含所有 these rules .

关于java - ProGuard:ClassCastException,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30121642/

相关文章:

android - 带有改造 API 的 MalformedJsonException?

Android Proguard,删除所有Log语句并合并包

java - Spring Boot 中的 DispatcherServlet 和 web.xml

java - 本地文件对象的绝对路径

java - 如何在android 10中获取图像的方向信息?

java - Struts2 如何返回 JSON 响应

java - 如何使用 JDBC 在文本文件中写入大量数据而不耗尽内存

java - java中如何获取泛型类的类型?

java - SignalR 调用已取消

android - Proguard 破坏 Assets 或原始音频文件