Only flush the app if it exists
Merge pull request #6251 from GrahamCampbell/5.0-testcase

[5.0] Only Flush The App If It Exists