ProGuard: ClassCastException

寵の児 提交于 2019-12-11 04:04:48

问题


I'm getting this annoying ClassCastException when I obfuscate my Java code (which works fine before I obfuscate using ProGuard).

   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)

That ClastCastException error points to this bit of code, here (the bolded line being the exact line):

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;
}

Whole Class File (Un obfuscated) : http://pastebin.com/Jgh4x1SS RawProfileList Class File (Un obfuscated) : http://pastebin.com/vPxFpYfC ProGuard version : 5.2.1

Declaration of Profiles field:

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

回答1:


Your classes look fine. ClassCastException means that Gson didn't know that a field should have been serialized as Profile.

Make sure your proguard.cfg contains all of these rules.



来源:https://stackoverflow.com/questions/30121642/proguard-classcastexception

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!