7013420: Project Coin: remove general expression support from try-with-resources statement
authordarcy
Wed, 26 Jan 2011 12:32:23 -0800
changeset 8157 c5ae3b2ebe74
parent 8156 601a0ec31a79
child 8159 f710beb7e29a
7013420: Project Coin: remove general expression support from try-with-resources statement Reviewed-by: alanb
jdk/test/java/nio/channels/FileChannel/Truncate.java
--- a/jdk/test/java/nio/channels/FileChannel/Truncate.java	Wed Jan 26 18:01:41 2011 +0000
+++ b/jdk/test/java/nio/channels/FileChannel/Truncate.java	Wed Jan 26 12:32:23 2011 -0800
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2000, 2010, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2000, 2011, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -58,30 +58,31 @@
         for(int i=0; i<100; i++) {
             long testSize = generator.nextInt(1000) + 10;
             initTestFile(blah, testSize);
-            FileChannel fc = (i < 50) ?
-                new RandomAccessFile(blah, "rw").getChannel() :
-                FileChannel.open(blah.toPath(), READ, WRITE);
-            try (fc) {
-                if (fc.size() != testSize)
-                    throw new RuntimeException("Size failed");
 
-                long position = generator.nextInt((int)testSize);
-                fc.position(position);
+            try (FileChannel fc = (i < 50) ?
+                 new RandomAccessFile(blah, "rw").getChannel() :
+                 FileChannel.open(blah.toPath(), READ, WRITE))
+                {
+                    if (fc.size() != testSize)
+                        throw new RuntimeException("Size failed");
+
+                    long position = generator.nextInt((int)testSize);
+                    fc.position(position);
 
-                long newSize = generator.nextInt((int)testSize);
-                fc.truncate(newSize);
+                    long newSize = generator.nextInt((int)testSize);
+                    fc.truncate(newSize);
 
-                if (fc.size() != newSize)
-                    throw new RuntimeException("Truncate failed");
+                    if (fc.size() != newSize)
+                        throw new RuntimeException("Truncate failed");
 
-                if (position > newSize) {
-                    if (fc.position() != newSize)
-                        throw new RuntimeException("Position greater than size");
-                } else {
-                    if (fc.position() != position)
-                        throw new RuntimeException("Truncate changed position");
-                };
-            }
+                    if (position > newSize) {
+                        if (fc.position() != newSize)
+                            throw new RuntimeException("Position greater than size");
+                    } else {
+                        if (fc.position() != position)
+                            throw new RuntimeException("Truncate changed position");
+                    };
+                }
         }
     }
 
@@ -92,24 +93,24 @@
         for (int i=0; i<10; i++) {
             long testSize = generator.nextInt(1000) + 10;
             initTestFile(blah, testSize);
-            FileChannel fc = (i < 5) ?
-                new FileOutputStream(blah, true).getChannel() :
-                FileChannel.open(blah.toPath(), APPEND);
-            try (fc) {
-                // truncate file
-                long newSize = generator.nextInt((int)testSize);
-                fc.truncate(newSize);
-                if (fc.size() != newSize)
-                    throw new RuntimeException("Truncate failed");
+            try (FileChannel fc = (i < 5) ?
+                 new FileOutputStream(blah, true).getChannel() :
+                 FileChannel.open(blah.toPath(), APPEND))
+                {
+                    // truncate file
+                    long newSize = generator.nextInt((int)testSize);
+                    fc.truncate(newSize);
+                    if (fc.size() != newSize)
+                        throw new RuntimeException("Truncate failed");
 
-                // write one byte
-                ByteBuffer buf = ByteBuffer.allocate(1);
-                buf.put((byte)'x');
-                buf.flip();
-                fc.write(buf);
-                if (fc.size() != (newSize+1))
-                    throw new RuntimeException("Unexpected size");
-            }
+                    // write one byte
+                    ByteBuffer buf = ByteBuffer.allocate(1);
+                    buf.put((byte)'x');
+                    buf.flip();
+                    fc.write(buf);
+                    if (fc.size() != (newSize+1))
+                        throw new RuntimeException("Unexpected size");
+                }
         }
     }