java.lang.IllegalStateException bug fix

Post with proposed solution:
http://stackoverflow.com/questions/7469082/getting-exception-illegalstateexception-can-not-perform-this-action-after-onsa/10261438#10261438