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.
java.lang.NullPointerException
	at org.eclipse.smarthome.io.rest.sitemap.internal.PageChangeListener.getAllItems(PageChangeListener.java:125)[117:org.eclipse.smarthome.io.rest.sitemap:0.9.0.b5]
	at org.eclipse.smarthome.io.rest.sitemap.internal.PageChangeListener.updateItemsAndWidgets(PageChangeListener.java:75)[117:org.eclipse.smarthome.io.rest.sitemap:0.9.0.b5]
	at org.eclipse.smarthome.io.rest.sitemap.internal.PageChangeListener.sitemapContentChanged(PageChangeListener.java:217)[117:org.eclipse.smarthome.io.rest.sitemap:0.9.0.b5]
	at org.eclipse.smarthome.io.rest.sitemap.SitemapSubscriptionService.modelChanged(SitemapSubscriptionService.java:277)[117:org.eclipse.smarthome.io.rest.sitemap:0.9.0.b5]
	at org.eclipse.smarthome.model.core.internal.ModelRepositoryImpl.notifyListeners(ModelRepositoryImpl.java:286)[122:org.eclipse.smarthome.model.core:0.9.0.b5]
	at org.eclipse.smarthome.model.core.internal.ModelRepositoryImpl.addOrRefreshModel(ModelRepositoryImpl.java:136)[122:org.eclipse.smarthome.model.core:0.9.0.b5]
	at org.eclipse.smarthome.model.core.internal.folder.FolderObserver.checkFile(FolderObserver.java:234)[122:org.eclipse.smarthome.model.core:0.9.0.b5]
	at org.eclipse.smarthome.model.core.internal.folder.FolderObserver.processWatchEvent(FolderObserver.java:297)[122:org.eclipse.smarthome.model.core:0.9.0.b5]
	at org.eclipse.smarthome.core.service.WatchQueueReader.run(WatchQueueReader.java:206)[98:org.eclipse.smarthome.core:0.9.0.b5]
	at java.lang.Thread.run(Thread.java:748)[:1.8.0_144]
`

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.