Reimplement try with resources patch after merge conflict