混淆器:ClassCastException

use*_*168 4 java obfuscation proguard gson

当我混淆我的 Java 代码时,我感到很烦人ClassCastException(在我混淆使用之前它工作得很好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)
Run Code Online (Sandbox Code Playgroud)

该 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;
}
Run Code Online (Sandbox Code Playgroud)

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

配置文件声明字段:

private final Map<String, Profile> profiles = new HashMap<String, Profile>();
Run Code Online (Sandbox Code Playgroud)

Ego*_*uba 5

你的课程看起来不错。ClassCastException意味着Gson不知道字段应该被序列化为Profile.

确保您的proguard.cfg包含所有这些规则。