IntelliJ IDEA plugin persistence state xml has duplicate lines

I have the following Component:\[code\]@State( name = "SessionConfiguration", storages = { @Storage(id = "default", file = StoragePathMacros.PROJECT_FILE), @Storage(id = "dir", file = StoragePathMacros.PROJECT_CONFIG_DIR + "/tabsession.xml", scheme = StorageScheme.DIRECTORY_BASED) })public class SessionComponent implements ProjectComponent, PersistentStateComponent<Element> {... @Nullable @Override public Element getState() { LOG.debug("Saving state"); final Element element = new Element("tabsession"); // meta configuration information final Element stateElement = new Element("state"); stateElement.setAttribute("version", Integer.toString(STATE_VERSION)); element.addContent(stateElement); // session data final Element sessionsElement = new Element("sessions"); for(SessionState.Session session : sessionState.sessions) { final Element sessionElement = new Element("session"); sessionElement.setAttribute("name", session.name); final Element filesElement = new Element("files"); for(String path : session.files) { final Element fileElement = new Element("file"); fileElement.setAttribute("path", path); filesElement.addContent(fileElement); } filesElement.setAttribute("focusedFile", session.focusedFile); sessionElement.addContent(filesElement); sessionsElement.addContent(sessionElement); } element.addContent(sessionsElement); return element; }...}\[/code\]That's working just fine and generates the target file \[code\]tabsession.xml\[/code\]:\[code\]<?xml version="1.0" encoding="UTF-8"?><project version="4"> <component name="SessionConfiguration"> <state version="1" /> <sessions> <session name="first"> <files focusedFile="$PROJECT_DIR$/src/First.java"> <file path="$PROJECT_DIR$/src/First.java" /> <file path="$PROJECT_DIR$/src/Second.java" /> </files> </session> </sessions> </component></project>\[/code\]But if the state gets saved again with different data, old lines are not removed. For example, if i open another file and the state gets saved the xml looks like this:\[code\]<?xml version="1.0" encoding="UTF-8"?><project version="4"> <component name="SessionConfiguration"> <state version="1" /> <sessions> <session name="first"> <files focusedFile="$PROJECT_DIR$/src/First.java"> <file path="$PROJECT_DIR$/src/First.java" /> <file path="$PROJECT_DIR$/src/Second.java" /> <file path="$PROJECT_DIR$/src/First.java" /> <file path="$PROJECT_DIR$/src/Second.java" /> <file path="$PROJECT_DIR$/src/Third.java" /> </files> </session> </sessions> </component></project>\[/code\]Which is clearly wrong. Any ideas how i can save only the current state while removing old lines?
 
Back
Top