Catch UnsupportedOperationException and handle it properly.

This will also need to be merged up -> gradle-2.0.