try fix ConcurrentModificationException

This commit is contained in:
huangyuhui 2018-02-25 10:48:07 +08:00
parent 3ff466462c
commit 139e2ee78d
2 changed files with 8 additions and 5 deletions

View File

@ -193,8 +193,7 @@ public final class MainPage extends StackPane implements DecoratorPage {
private void loadVersions(Profile profile) {
this.profile = profile;
List<Node> children = new LinkedList<>();
List<Version> versions = new LinkedList<>(profile.getRepository().getVersions());
for (Version version : versions) {
for (Version version : profile.getRepository().getVersions()) {
children.add(buildNode(profile, version.getId(), GameVersion.minecraftVersion(profile.getRepository().getVersionJar(version.getId())).orElse("Unknown")));
}
FXUtils.resetChildren(masonryPane, children);

View File

@ -38,7 +38,7 @@ import java.util.logging.Level;
public class DefaultGameRepository implements GameRepository {
private File baseDirectory;
protected final Map<String, Version> versions = new TreeMap<>();
protected Map<String, Version> versions;
protected boolean loaded = false;
public DefaultGameRepository(File baseDirectory) {
@ -151,7 +151,7 @@ public class DefaultGameRepository implements GameRepository {
}
protected void refreshVersionsImpl() {
versions.clear();
Map<String, Version> versions = new TreeMap<>();
if (ClassicVersion.hasClassicVersion(getBaseDirectory())) {
Version version = new ClassicVersion();
@ -172,7 +172,10 @@ public class DefaultGameRepository implements GameRepository {
if (!json.exists()) {
List<File> jsons = FileUtils.listFilesByExtension(dir, "json");
if (jsons.size() == 1)
jsons.get(0).renameTo(json);
if (!jsons.get(0).renameTo(json)) {
Logging.LOG.warning("Cannot rename json file " + jsons.get(0) + " to " + json + ", ignoring version " + id);
continue;
}
}
Version version;
@ -216,6 +219,7 @@ public class DefaultGameRepository implements GameRepository {
}
}
this.versions = versions;
loaded = true;
}