1

NPE - http://pastebin.com/gzuf3x1k (This comes up when I execute the obfuscated file). (StackTrace with LineNumbers: http://pastebin.com/ddY3Ei9G)

(The obfuscated stacktrace: http://pastebin.com/svipdakN)

addRefreshedVersionsListener(VersionManager.java):

public void addRefreshedVersionsListener(RefreshedVersionsListener listener){
    this.refreshedVersionsListeners.add(listener);
}

getResourceFiles(VersionManager.java):

private Set<Downloadable> getResourceFiles(Proxy proxy, File baseDirectory, CompleteVersion version)
    {
        Set result = new HashSet();
        InputStream inputStream = null;
        File assets = new File(baseDirectory, "assets");
        File objectsFolder = new File(assets, "objects");
        File indexesFolder = new File(assets, "indexes");
        String indexName = version.getAssets();
        long start = System.nanoTime();
        if (indexName == null) {
            indexName = "legacy";
        }
        File indexFile = new File(indexesFolder, indexName + ".json");
        try
        {
            URL indexUrl = new URL("https://s3.amazonaws.com/Minecraft.Download/indexes/" + indexName + ".json");
            inputStream = indexUrl.openConnection(proxy).getInputStream();
            String json = IOUtils.toString(inputStream);
            FileUtils.writeStringToFile(indexFile, json);
            AssetIndex index = (AssetIndex)this.gson.fromJson(json, AssetIndex.class);
            for (AssetIndex.AssetObject object : index.getUniqueObjects())
            {
                String filename = object.getHash().substring(0, 2) + "/" + object.getHash();
                File file = new File(objectsFolder, filename);
                if ((!file.isFile()) || (FileUtils.sizeOf(file) != object.getSize()))
                {
                    Downloadable downloadable = new AssetDownloadable(proxy, new URL("http://resources.download.minecraft.net/" + filename), file, false, object.getHash(), object.getSize());
                    downloadable.setExpectedSize(object.getSize());
                    result.add(downloadable);
                }
            }
            long end = System.nanoTime();
            long delta = end - start;
            Launcher.getInstance().println("Delta time to compare resources: " + delta / 1000000L + " ms ");
        }
        catch (IOException|JsonSyntaxException ex)
        {
            Launcher.getInstance().println("Couldn't download resources", ex);
        }
        finally
        {
            IOUtils.closeQuietly(inputStream);
        }
        return result;
    }

& The first cause [at net.minecraft.launcher.updater.VersionManager.refreshVersions(VersionManager.java)]

   public void refreshVersions() throws IOException {
      this.clearCache();
      File[] files = this.baseVersionsDir.listFiles();
      if(files != null) {
         File[] i$ = files;
         int version = files.length;

         for(int type = 0; type < version; ++type) {
            File directory = i$[type];
            String id = directory.getName();
            File jsonFile = new File(directory, id + ".json");
            if(directory.isDirectory() && jsonFile.exists()) {
               try {
                  String ex = "versions/" + id + "/" + id + ".json";
                  CompleteVersion version1 = (CompleteVersion)this.gson.fromJson(this.getContent(ex), CompleteVersion.class);
                  if(version1.getId().equals(id)) {
                     this.addVersion(version1);
                  } else if(Launcher.getInstance() != null) {
                     Launcher.getInstance().println("Ignoring: " + ex + "; it contains id: \'" + version1.getId() + "\' expected \'" + id + "\'");
                  }
               } catch (RuntimeException var10) {
                  if(Launcher.getInstance() == null) {
                     throw new JsonSyntaxException("Loading file: " + jsonFile.toString(), var10);
                  }
                  Launcher.getInstance().println("Couldn\'t load local version " + jsonFile.getAbsolutePath(), var10);
               }
            }
         }

Location of the cause on stacktrace:

CompleteVersion version1 = (CompleteVersion)this.gson.fromJson(this.getContent(ex), CompleteVersion.class);
                  if(version1.getId().equals(id)) {
                     this.addVersion(version1);
                  } else if(Launcher.getInstance() != null) {
                     Launcher.getInstance().println("Ignoring: " + ex + "; it contains id: \'" + version1.getId() + "\' expected \'" + id + "\'");
                  }

For some odd reason, this ALWAYS occurs with the fromJson method from GSON API (when executed after obfuscation).

CompleteVersion Class : http://pastebin.com/dF6aXCjS

Neil Souza
  • 115
  • 1
  • 12
  • What line in the source code is the exception occuring at? – Stephen C May 03 '15 at 05:03
  • Read this: https://coderwall.com/p/fazk4g/configure-proguard-to-retain-line-numbers-in-stack-traces – Stephen C May 03 '15 at 05:29
  • So ... what line >>is<< the exception occurring on? Line ... not line number. – Stephen C May 03 '15 at 05:56
  • if(version1.getId().equals(id)) { is the line – Neil Souza May 03 '15 at 05:58
  • It seems to be because version1 is perhaps null. As version1 = (CompleteVersion)this.gson.fromJson(this.getContent(ex), CompleteVersion.class); Which makes no sense, because it works when it's not obfuscated, but it doesn't work when it gets obfuscated. – Neil Souza May 03 '15 at 06:15
  • Can you post the CompleteVersion class? It may be because when the names in that class are mangled, GSON can no longer properly parse the JSON. – gengkev May 03 '15 at 06:28

1 Answers1

2

I'm guessing that this is because when GSON tries to parse the JSON, it uses the property names in the CompleteVersion class. If those names are mangled, GSON won't find the property names in the JSON, so the properties will simply be null.

Another StackOverflow question appears to have several solutions to this problem. I've never used ProGuard personally, but it looks like you can try adding something like -keep class net.minecraft.launcher.versions.CompleteVersion { *; } to proguard.cfg so that the CompleteVersion class won't be touched by ProGuard.

gengkev
  • 1,890
  • 2
  • 20
  • 31
  • If you'd like, you can confirm whether this is true by logging `version1.toString()` – gengkev May 03 '15 at 06:38
  • Yup. Thanks for the answer, I've applied your answer to attempt to fix another problem,. though it doesn't work in this case: (StackTrace) http://pastebin.com/iUE0KzMT – Neil Souza May 03 '15 at 07:49
  • That points to at net.minecraft.launcher.profile.ProfileManager.loadProfiles(ProfileManager.java:128) Which points to this line: final RawProfileList rawProfileList = gson.fromJson(fileData, type); – Neil Souza May 03 '15 at 07:50
  • I've used -keep class net.minecraft.launcher.profile.RawProfileList { *; } though I've been getting that error, it doesn't fix it @gengkev – Neil Souza May 03 '15 at 08:00
  • Perhaps you could do the same for the Profile class? See the linked SO question for more guidance; like I said, I've never actually used Proguard ;) – gengkev May 04 '15 at 01:40