From a48852f21a873b142c18f46b3f4086e8f76cd935 Mon Sep 17 00:00:00 2001 From: Ivan Furnadjiev Date: Wed, 19 Aug 2015 11:32:59 +0300 Subject: [PATCH] Don't create empty file-mapping entries in .cproject file When file language mapping is reset back to inherit, empty (without configuration, language and path attributes) file-mapping element is created in .cproject file. This leads to project corruption. Add a check for empty entry value in LanguageMappingStore#addFileMappings. 475344: Broken .cproject file after file language mapping is reset to inherit https://bugs.eclipse.org/bugs/show_bug.cgi?id=475344 Change-Id: I6e7d0b8d1199501e087ce42b75f0d8e83fca77cd Signed-off-by: Ivan Furnadjiev --- .../core/language/LanguageMappingStore.java | 20 ++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/language/LanguageMappingStore.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/language/LanguageMappingStore.java index 29f72e6ab35..2f33d993b82 100644 --- a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/language/LanguageMappingStore.java +++ b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/language/LanguageMappingStore.java @@ -270,15 +270,17 @@ public class LanguageMappingStore { private void addFileMappings(Map> mappings, ICStorageElement rootElement) { for (Map.Entry> entry : mappings.entrySet()) { - ICStorageElement mapping = rootElement.createChild(FILE_MAPPING); - String path = entry.getKey(); - for (Entry configurationEntry : entry.getValue().entrySet()) { - String configuration = configurationEntry.getKey(); - String language = configurationEntry.getValue(); - - mapping.setAttribute(ATTRIBUTE_PATH, path); - mapping.setAttribute(ATTRIBUTE_CONFIGURATION, configuration); - mapping.setAttribute(ATTRIBUTE_LANGUAGE, language); + if (!entry.getValue().isEmpty()) { + ICStorageElement mapping = rootElement.createChild(FILE_MAPPING); + String path = entry.getKey(); + for (Entry configurationEntry : entry.getValue().entrySet()) { + String configuration = configurationEntry.getKey(); + String language = configurationEntry.getValue(); + + mapping.setAttribute(ATTRIBUTE_PATH, path); + mapping.setAttribute(ATTRIBUTE_CONFIGURATION, configuration); + mapping.setAttribute(ATTRIBUTE_LANGUAGE, language); + } } } }