JavaIO flushing error and regression test email attachments

Mirroring changes from master branch hotfix.

I'm not sure why the diff is showing the large blocks of changes - those were merged with a prior pull request.