Prevent IllegalStateException
Fixes #1527