Slight reordering of generation code for #1125
Commenting lines that need to stay commented
Fixed try-with-resource test because of changes in the generated code (#1125)
Made a minor change in the generation in the try-with-resource to make it almost the same as how Java does it (#1125)