This could use try-with-resources if it wasn't special cased.