Java auto close3

In the java 'autoclose' work, some errors were introduced by some final refactoring - these were never adequately tested.  This branch fixes those errors so that our java tests pass again.