Skip to content

Commit

Permalink
Fix race condition loading core/destroyable modes (#1012)
Browse files Browse the repository at this point in the history
Signed-off-by: BT (calcastor/mame) <[email protected]>
  • Loading branch information
calcastor authored Jun 9, 2022
1 parent 05536ee commit 225f125
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 9 deletions.
7 changes: 3 additions & 4 deletions core/src/main/java/tc/oc/pgm/core/CoreModule.java
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,6 @@ public Collection<MapTag> getTags() {
}

public static class Factory implements MapModuleFactory<CoreModule> {
private MapFactory factory;

@Override
public Collection<Class<? extends MapModule>> getWeakDependencies() {
Expand All @@ -85,7 +84,6 @@ public Collection<Class<? extends MapModule>> getSoftDependencies() {
@Override
public CoreModule parse(MapFactory context, Logger logger, Document doc)
throws InvalidXMLException {
this.factory = context;
List<CoreFactory> coreFactories = Lists.newArrayList();
HashMap<TeamFactory, Integer> serialNumbers = new HashMap<>();

Expand Down Expand Up @@ -133,7 +131,7 @@ public CoreModule parse(MapFactory context, Logger logger, Document doc)
if (coreEl.getAttribute("mode-changes") != null) {
throw new InvalidXMLException("Cannot combine modes and mode-changes", coreEl);
}
modeSet = parseModeSet(modes); // Specific set of modes
modeSet = parseModeSet(context, modes); // Specific set of modes
} else if (XMLUtils.parseBoolean(coreEl.getAttribute("mode-changes"), false)) {
modeSet = null; // All modes
} else {
Expand Down Expand Up @@ -172,7 +170,8 @@ public CoreModule parse(MapFactory context, Logger logger, Document doc)
}
}

public ImmutableSet<Mode> parseModeSet(Node node) throws InvalidXMLException {
public ImmutableSet<Mode> parseModeSet(MapFactory factory, Node node)
throws InvalidXMLException {
ImmutableSet.Builder<Mode> modes = ImmutableSet.builder();
for (String modeId : node.getValue().split("\\s")) {
Mode mode = factory.getFeatures().get(modeId, Mode.class);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,6 @@ public Collection<MapTag> getTags() {
}

public static class Factory implements MapModuleFactory<DestroyableModule> {
private MapFactory factory;

@Override
public Collection<Class<? extends MapModule>> getWeakDependencies() {
Expand All @@ -82,9 +81,7 @@ public Collection<Class<? extends MapModule>> getSoftDependencies() {
@Override
public DestroyableModule parse(MapFactory context, Logger logger, Document doc)
throws InvalidXMLException {
this.factory = context;
List<DestroyableFactory> destroyables = Lists.newArrayList();
TeamModule teamModule = context.getModule(TeamModule.class);
RegionParser regionParser = context.getRegions();

for (Element destroyableEl :
Expand Down Expand Up @@ -124,7 +121,7 @@ public DestroyableModule parse(MapFactory context, Logger logger, Document doc)
if (destroyableEl.getAttribute("mode-changes") != null) {
throw new InvalidXMLException("Cannot combine modes and mode-changes", destroyableEl);
}
modeSet = parseModeSet(modes); // Specific set of modes
modeSet = parseModeSet(context, modes); // Specific set of modes
} else if (XMLUtils.parseBoolean(destroyableEl.getAttribute("mode-changes"), false)) {
modeSet = null; // All modes
} else {
Expand Down Expand Up @@ -168,7 +165,8 @@ public DestroyableModule parse(MapFactory context, Logger logger, Document doc)
}
}

public ImmutableSet<Mode> parseModeSet(Node node) throws InvalidXMLException {
public ImmutableSet<Mode> parseModeSet(MapFactory factory, Node node)
throws InvalidXMLException {
ImmutableSet.Builder<Mode> modes = ImmutableSet.builder();
for (String modeId : node.getValue().split("\\s")) {
Mode mode = factory.getFeatures().get(modeId, Mode.class);
Expand Down

0 comments on commit 225f125

Please sign in to comment.