diff --git a/plugins/ant/src/com/intellij/lang/ant/config/impl/AntBuildFileImpl.java b/plugins/ant/src/com/intellij/lang/ant/config/impl/AntBuildFileImpl.java index 7c6a7e2c0615..4b84398bac56 100644 --- a/plugins/ant/src/com/intellij/lang/ant/config/impl/AntBuildFileImpl.java +++ b/plugins/ant/src/com/intellij/lang/ant/config/impl/AntBuildFileImpl.java @@ -50,6 +50,7 @@ public class AntBuildFileImpl implements AntBuildFileBase { @NonNls private static final String USER_HOME = "user.home"; @NonNls private static final String ANT_LIB = "/.ant/lib"; private volatile Map myCachedExternalProperties; + private final Object myOptionsLock = new Object(); public static final AbstractProperty ANT_INSTALLATION = new AbstractProperty() { public String getName() { @@ -273,15 +274,16 @@ public class AntBuildFileImpl implements AntBuildFileBase { } public void updateProperties() { - synchronized (this) { + final Map targetByName = + ContainerUtil.assignKeys(Arrays.asList(getModel().getTargets()).iterator(), new Convertor() { + public String convert(AntBuildTarget target) { + return target.getName(); + } + }); + targetByName.remove(null); // ensure there are no targets with 'null' name + + synchronized (myOptionsLock) { myCachedExternalProperties = null; - final Map targetByName = - ContainerUtil.assignKeys(Arrays.asList(getModel().getTargets()).iterator(), new Convertor() { - public String convert(AntBuildTarget target) { - return target.getName(); - } - }); - targetByName.remove(null); // ensure there are no targets with 'null' name final ArrayList filters = TARGET_FILTERS.getModifiableList(myAllOptions); for (Iterator iterator = filters.iterator(); iterator.hasNext();) { final TargetFilter filter = iterator.next(); @@ -325,7 +327,7 @@ public class AntBuildFileImpl implements AntBuildFileBase { } public void readWorkspaceProperties(final Element parentNode) throws InvalidDataException { - synchronized (this) { + synchronized (myOptionsLock) { myWorkspaceOptions.readExternal(parentNode); final Element expanded = parentNode.getChild("expanded"); if (expanded != null) { @@ -335,7 +337,7 @@ public class AntBuildFileImpl implements AntBuildFileBase { } public void writeWorkspaceProperties(final Element parentNode) throws WriteExternalException { - synchronized (this) { + synchronized (myOptionsLock) { myWorkspaceOptions.writeExternal(parentNode); final Element expandedElem = new Element("expanded"); expandedElem.setAttribute("value", Boolean.toString(myShouldExpand)); @@ -344,7 +346,7 @@ public class AntBuildFileImpl implements AntBuildFileBase { } public void readProperties(final Element parentNode) throws InvalidDataException { - synchronized (this) { + synchronized (myOptionsLock) { myProjectOptions.readExternal(parentNode); basicUpdateConfig(); readWorkspaceProperties(parentNode); // Compatibility with old Idea @@ -352,7 +354,7 @@ public class AntBuildFileImpl implements AntBuildFileBase { } public void writeProperties(final Element parentNode) throws WriteExternalException { - synchronized (this) { + synchronized (myOptionsLock) { myProjectOptions.writeExternal(parentNode); } } @@ -369,8 +371,9 @@ public class AntBuildFileImpl implements AntBuildFileBase { public Map getExternalProperties() { Map result = myCachedExternalProperties; if (result == null) { - synchronized (this) { - if (myCachedExternalProperties == null) { + synchronized (myOptionsLock) { + result = myCachedExternalProperties; + if (result == null) { result = new HashMap(); final DataContext context = SimpleDataContext.getProjectContext(myProject); @@ -390,9 +393,6 @@ public class AntBuildFileImpl implements AntBuildFileBase { } myCachedExternalProperties = result; } - else { - result = myCachedExternalProperties; - } } } return result; @@ -405,7 +405,7 @@ public class AntBuildFileImpl implements AntBuildFileBase { @Nullable private TargetFilter findFilter(final String targetName) { final List filters; - synchronized (this) { + synchronized (myOptionsLock) { filters = TARGET_FILTERS.get(myAllOptions); } for (TargetFilter targetFilter : filters) {