/* * @test /nodynamiccopyright/ * @bug 6911256 6964740 6965277 * @author Maurizio Cimadamore * @summary Check that lowered arm block does not end up creating resource twice */ import java.util.ArrayList; public class DuplicateResource { static class TestResource implements AutoCloseable { TestResource() { resources.add(this); } boolean isClosed = false; public void close() throws Exception { isClosed = true; } } static ArrayList resources = new ArrayList(); public static void main(String[] args) { try(new TestResource()) { //do something } catch (Exception e) { throw new AssertionError("Shouldn't reach here", e); } check(); } public static void check() { if (resources.size() != 1) { throw new AssertionError("Expected one resource, found: " + resources.size()); } TestResource resource = resources.get(0); if (!resource.isClosed) { throw new AssertionError("Resource used in ARM block has not been automatically closed"); } } }