Error handling update, SitemapSubscriptionService problem, Sitemap not updating

Hi, I am having an issue with sitemap files, I edit sitemap from rules file because I need a dynamic editing of a sitemap for syncing data with the server and I need to correct sitemap every now and then, therefore I started editing file from rules with FileWriter. The sitemap is all correctly writen and the FileWriter is closed at the end and everything should work fine if I edit it maunally but when I edit it with the FileWriter I get this error:

`09:59:09.620 [INFO ] [el.core.internal.ModelRepositoryImpl] - Refreshing model 'default.sitemap'
09:59:09.638 [WARN ] [el.core.internal.ModelRepositoryImpl] - Configuration model 'default.sitemap' is either empty or cannot be parsed correctly!
09:59:09.643 [ERROR] [.core.internal.folder.FolderObserver] - Error handling update of file '/etc/openhab2/sitemaps/default.sitemap': null.
	at org.eclipse.smarthome.model.core.internal.ModelRepositoryImpl.notifyListeners([122:org.eclipse.smarthome.model.core:0.9.0.b5]
	at org.eclipse.smarthome.model.core.internal.ModelRepositoryImpl.addOrRefreshModel([122:org.eclipse.smarthome.model.core:0.9.0.b5]
	at org.eclipse.smarthome.model.core.internal.folder.FolderObserver.checkFile([122:org.eclipse.smarthome.model.core:0.9.0.b5]
	at org.eclipse.smarthome.model.core.internal.folder.FolderObserver.processWatchEvent([122:org.eclipse.smarthome.model.core:0.9.0.b5]

If I open the sitemap manually and just save it maunally the sitemap works fine but If I do it from rules file, the sitemap kind of stops and then it is buggy and doesn’t refresh data. Is there any solution for this?

I found this post, it might offer a solution but I don’t understand it perfectly.

Any help would be appreciated.

Please clarify. Are you using a self-written program to modify the sitemap? If not, what program are you using?

It edits the .sitemap file perfectly I triple checked, but somewhere in the process I think the file is open a bit too long and SitemapSubscriptionService finds it half empty therefore it ignores it I think?

Probably it would be a better idea to write a temp file and then copy it over top of the existing sitemap.

Thank you, this worked.