Fixing bug #1724. Adding a check on the file extension before using it.

Change-Id: Idfdbeadcd94b4e25c6255e01e46bec6eb0a06149