--- openjdk.orig/jdk/test/java/nio/MappedByteBuffer/Basic.java	2011-06-16 00:15:19.000000000 +0200
+++ openjdk/jdk/test/java/nio/MappedByteBuffer/Basic.java	2011-06-16 16:13:50.000000000 +0200
@@ -35,45 +35,56 @@
         byte[] srcData = new byte[20];
         for (int i=0; i<20; i++)
             srcData[i] = 3;
-        File blah = File.createTempFile("blah", null);
-        blah.deleteOnExit();
-        FileOutputStream fos = new FileOutputStream(blah);
-        FileChannel fc = fos.getChannel();
-        fc.write(ByteBuffer.wrap(srcData));
-        fc.close();
-        fos.close();
+        File blah = null;
+        try {
+            blah = File.createTempFile("blah", null);
+            blah.deleteOnExit();
+            FileOutputStream fos = new FileOutputStream(blah);
+            FileChannel fc = fos.getChannel();
+            fc.write(ByteBuffer.wrap(srcData));
+            fc.close();
+            fos.close();
 
-        FileInputStream fis = new FileInputStream(blah);
-        fc = fis.getChannel();
-        MappedByteBuffer mbb = fc.map(FileChannel.MapMode.READ_ONLY, 0, 10);
-        mbb.load();
-        mbb.isLoaded();
-        mbb.force();
-        if (!mbb.isReadOnly())
-            throw new RuntimeException("Incorrect isReadOnly");
+            FileInputStream fis = new FileInputStream(blah);
+            fc = fis.getChannel();
+            MappedByteBuffer mbb = fc.map(FileChannel.MapMode.READ_ONLY, 0, 10);
+            mbb.load();
+            mbb.isLoaded();
+            mbb.force();
+            if (!mbb.isReadOnly()) {
+                throw new RuntimeException("Incorrect isReadOnly");
+            }
 
-        // repeat with unaligned position in file
-        mbb = fc.map(FileChannel.MapMode.READ_ONLY, 1, 10);
-        mbb.load();
-        mbb.isLoaded();
-        mbb.force();
-        fc.close();
-        fis.close();
+            // repeat with unaligned position in file
+            mbb = fc.map(FileChannel.MapMode.READ_ONLY, 1, 10);
+            mbb.load();
+            mbb.isLoaded();
+            mbb.force();
+            fc.close();
+            fis.close();
 
-        RandomAccessFile raf = new RandomAccessFile(blah, "r");
-        fc = raf.getChannel();
-        mbb = fc.map(FileChannel.MapMode.READ_ONLY, 0, 10);
-        if (!mbb.isReadOnly())
-            throw new RuntimeException("Incorrect isReadOnly");
-        fc.close();
-        raf.close();
+            RandomAccessFile raf = new RandomAccessFile(blah, "r");
+            fc = raf.getChannel();
+            mbb = fc.map(FileChannel.MapMode.READ_ONLY, 0, 10);
+            if (!mbb.isReadOnly()) {
+                throw new RuntimeException("Incorrect isReadOnly");
+            }
+            fc.close();
+            raf.close();
 
-        raf = new RandomAccessFile(blah, "rw");
-        fc = raf.getChannel();
-        mbb = fc.map(FileChannel.MapMode.READ_WRITE, 0, 10);
-        if (mbb.isReadOnly())
-            throw new RuntimeException("Incorrect isReadOnly");
-        fc.close();
-        raf.close();
+            raf = new RandomAccessFile(blah, "rw");
+            fc = raf.getChannel();
+            mbb = fc.map(FileChannel.MapMode.READ_WRITE, 0, 10);
+            if (mbb.isReadOnly()) {
+                throw new RuntimeException("Incorrect isReadOnly");
+            }
+            fc.close();
+            raf.close();
+        }
+        finally {
+            if (blah != null) {
+                blah.delete();
+            }
+        }
     }
 }
