changeset 14438:bad3f8a33db2 jdk-9+119

8156931: java.nio.Buffer tests cleanup Reviewed-by: alanb
author prappo
date Mon, 16 May 2016 09:54:01 +0100
parents 2e8edc311532
children 4352ddb02f68 f8a3c1510f95
files test/java/nio/Buffer/Basic-X.java.template test/java/nio/Buffer/BasicByte.java test/java/nio/Buffer/BasicChar.java test/java/nio/Buffer/BasicDouble.java test/java/nio/Buffer/BasicFloat.java test/java/nio/Buffer/BasicInt.java test/java/nio/Buffer/BasicLong.java test/java/nio/Buffer/BasicShort.java test/java/nio/Buffer/LimitDirectMemory.java test/java/nio/Buffer/Order.java test/java/nio/Buffer/SwapMicroBenchmark.java
diffstat 11 files changed, 717 insertions(+), 1805 deletions(-) [+]
line wrap: on
line diff
--- a/test/java/nio/Buffer/Basic-X.java.template	Mon May 16 07:01:26 2016 +0200
+++ b/test/java/nio/Buffer/Basic-X.java.template	Mon May 16 09:54:01 2016 +0100
@@ -31,7 +31,6 @@
 #warn This file is preprocessed before being compiled
 
 import java.nio.*;
-import java.lang.reflect.Method;
 
 
 public class Basic$Type$
@@ -60,7 +59,6 @@
 
     private static void relGet($Type$Buffer b) {
         int n = b.capacity();
-        $type$ v;
         for (int i = 0; i < n; i++)
             ck(b, (long)b.get(), (long)(($type$)ic(i)));
         b.rewind();
@@ -68,7 +66,6 @@
 
     private static void relGet($Type$Buffer b, int start) {
         int n = b.remaining();
-        $type$ v;
         for (int i = start; i < n; i++)
             ck(b, (long)b.get(), (long)(($type$)ic(i)));
         b.rewind();
@@ -76,7 +73,6 @@
 
     private static void absGet($Type$Buffer b) {
         int n = b.capacity();
-        $type$ v;
         for (int i = 0; i < n; i++)
             ck(b, (long)b.get(), (long)(($type$)ic(i)));
         b.rewind();
@@ -86,8 +82,9 @@
         int n = b.capacity();
         $type$[] a = new $type$[n + 7];
         b.get(a, 7, n);
-        for (int i = 0; i < n; i++)
+        for (int i = 0; i < n; i++) {
             ck(b, (long)a[i + 7], (long)(($type$)ic(i)));
+        }
     }
 
     private static void relPut($Type$Buffer b) {
@@ -178,7 +175,7 @@
     private static void bulkPutString($Type$Buffer b) {
         int n = b.capacity();
         b.clear();
-        StringBuffer sb = new StringBuffer(n + 7);
+        StringBuilder sb = new StringBuilder(n + 7);
         sb.append("1234567");
         for (int i = 0; i < n; i++)
             sb.append((char)ic(i));
@@ -203,13 +200,14 @@
     private static void checkBytes(ByteBuffer b, byte[] bs) {
         int n = bs.length;
         int p = b.position();
-        byte v;
         if (b.order() == ByteOrder.BIG_ENDIAN) {
-            for (int i = 0; i < n; i++)
+            for (int i = 0; i < n; i++) {
                 ck(b, b.get(), bs[i]);
+            }
         } else {
-            for (int i = n - 1; i >= 0; i--)
+            for (int i = n - 1; i >= 0; i--) {
                 ck(b, b.get(), bs[i]);
+            }
         }
         b.position(p);
     }
@@ -217,7 +215,7 @@
     private static void compact(Buffer b) {
         try {
             Class<?> cl = b.getClass();
-            Method m = cl.getDeclaredMethod("compact");
+            java.lang.reflect.Method m = cl.getDeclaredMethod("compact");
             m.setAccessible(true);
             m.invoke(b);
         } catch (Exception e) {
@@ -226,12 +224,11 @@
     }
 
     private static void checkInvalidMarkException(final Buffer b) {
-        tryCatch(b, InvalidMarkException.class, new Runnable() {
-            public void run() {
+        tryCatch(b, InvalidMarkException.class, () -> {
                 b.mark();
                 compact(b);
                 b.reset();
-            }});
+            });
     }
 
     private static void testViews(int level, ByteBuffer b, boolean direct) {
@@ -338,41 +335,50 @@
 
     private static void testAlign(final ByteBuffer b, boolean direct) {
         // index out-of bounds
-        tryCatch(b, IllegalArgumentException.class, () -> b.alignmentOffset(-1, (short) 1));
+        catchIllegalArgument(b, () -> b.alignmentOffset(-1, (short) 1));
 
         // unit size values
-        tryCatch(b, IllegalArgumentException.class, () -> b.alignmentOffset(0, (short) 0));
+        catchIllegalArgument(b, () -> b.alignmentOffset(0, (short) 0));
         for (int us = 1; us < 65; us++) {
             int _us = us;
             if ((us & (us - 1)) != 0) {
                 // unit size not a power of two
-                tryCatch(b, IllegalArgumentException.class, () -> b.alignmentOffset(0, _us));
+                catchIllegalArgument(b, () -> b.alignmentOffset(0, _us));
             } else {
                 if (direct || us <= 8) {
                     b.alignmentOffset(0, us);
                 } else {
                     // unit size > 8 with non-direct buffer
-                    tryCatch(b, UnsupportedOperationException.class, () -> b.alignmentOffset(0, _us));
+                    tryCatch(b, UnsupportedOperationException.class,
+                            () -> b.alignmentOffset(0, _us));
                 }
             }
         }
 
         // Probe for long misalignment at index zero for a newly created buffer
-        ByteBuffer empty = direct ? ByteBuffer.allocateDirect(0) : ByteBuffer.allocate(0);
+        ByteBuffer empty =
+                direct ? ByteBuffer.allocateDirect(0) : ByteBuffer.allocate(0);
         int longMisalignmentAtZero = empty.alignmentOffset(0, 8);
 
         if (direct) {
             // Freshly created direct byte buffers should be aligned at index 0
             // for ref and primitive values (see Unsafe.allocateMemory)
-            if (longMisalignmentAtZero != 0)
-                fail("Direct byte buffer misalligned at index 0 for ref and primitive values " + longMisalignmentAtZero);
+            if (longMisalignmentAtZero != 0) {
+                fail("Direct byte buffer misaligned at index 0"
+                        + " for ref and primitive values "
+                        + longMisalignmentAtZero);
+            }
         } else {
             // For heap byte buffers misalignment may occur on 32-bit systems
             // where Unsafe.ARRAY_BYTE_BASE_OFFSET % 8 == 4 and not 0
             // Note the GC will preserve alignment of the base address of the
             // array
-            if (jdk.internal.misc.Unsafe.ARRAY_BYTE_BASE_OFFSET % 8 != longMisalignmentAtZero)
-                fail("Heap byte buffer misalligned at index 0 for ref and primitive values " + longMisalignmentAtZero);
+            if (jdk.internal.misc.Unsafe.ARRAY_BYTE_BASE_OFFSET % 8
+                    != longMisalignmentAtZero) {
+                fail("Heap byte buffer misaligned at index 0"
+                        + " for ref and primitive values "
+                        + longMisalignmentAtZero);
+            }
         }
 
         // Ensure test buffer is correctly aligned at index 0
@@ -385,8 +391,10 @@
                 int am = b.alignmentOffset(i, us);
                 int expectedAm = (longMisalignmentAtZero + i) % us;
 
-                if (am != expectedAm)
-                    fail(String.format("b.alignmentOffset(%d, %d) == %d incorrect, expected %d", i, us, am, expectedAm));
+                if (am != expectedAm) {
+                    String f = "b.alignmentOffset(%d, %d) == %d incorrect, expected %d";
+                    fail(String.format(f, i, us, am, expectedAm));
+                }
             }
         }
 
@@ -395,8 +403,10 @@
         int al = b.limit() - b.alignmentOffset(b.limit(), 8);
         ByteBuffer ab = b.position(ap).limit(al).
                 slice();
-        if (ab.limit() == 0)
-            fail("Test input buffer not sufficiently sized to cover an aligned region for all values", b);
+        if (ab.limit() == 0) {
+            fail("Test input buffer not sufficiently sized to cover" +
+                    " an aligned region for all values", b);
+        }
         if (ab.alignmentOffset(0, 8) != 0)
             fail("Aligned test input buffer not correctly aligned at index 0", ab);
 
@@ -428,8 +438,9 @@
                 l = l - l_mod;
 
                 int ec = l - p;
-                if (as.limit() != ec)
+                if (as.limit() != ec) {
                     fail("Buffer capacity incorrect, expected: " + ec, as);
+                }
             }
         }
     }
@@ -441,6 +452,22 @@
         fail(problem + String.format(": x=%s y=%s", x, y), xb, yb);
     }
 
+    private static void catchIllegalArgument(Buffer b, Runnable thunk) {
+        tryCatch(b, IllegalArgumentException.class, thunk);
+    }
+
+    private static void catchReadOnlyBuffer(Buffer b, Runnable thunk) {
+        tryCatch(b, ReadOnlyBufferException.class, thunk);
+    }
+
+    private static void catchIndexOutOfBounds(Buffer b, Runnable thunk) {
+        tryCatch(b, IndexOutOfBoundsException.class, thunk);
+    }
+
+    private static void catchIndexOutOfBounds($type$[] t, Runnable thunk) {
+        tryCatch(t, IndexOutOfBoundsException.class, thunk);
+    }
+
     private static void tryCatch(Buffer b, Class<?> ex, Runnable thunk) {
         boolean caught = false;
         try {
@@ -452,11 +479,12 @@
                 fail(x.getMessage() + " not expected");
             }
         }
-        if (!caught)
+        if (!caught) {
             fail(ex.getName() + " not thrown", b);
+        }
     }
 
-    private static void tryCatch($type$ [] t, Class<?> ex, Runnable thunk) {
+    private static void tryCatch($type$[] t, Class<?> ex, Runnable thunk) {
         tryCatch($Type$Buffer.wrap(t), ex, thunk);
     }
 
@@ -513,11 +541,9 @@
         // 7190219
         b.clear();
         int pos = b.position();
-        tryCatch(b, BufferOverflowException.class, new Runnable() {
-            public void run() {
-                b.put(String.valueOf(new char[b.capacity() + 1]), 0,
-                        b.capacity() + 1);
-            }});
+        tryCatch(b, BufferOverflowException.class, () ->
+                b.put(String.valueOf(new char[b.capacity() + 1]), 0, b.capacity() + 1)
+            );
         ck(b, b.position(), pos);
         relGet(b);
 
@@ -537,38 +563,14 @@
         b.limit(b.capacity() / 2);
         b.position(b.limit());
 
-        tryCatch(b, BufferUnderflowException.class, new Runnable() {
-                public void run() {
-                    b.get();
-                }});
-
-        tryCatch(b, BufferOverflowException.class, new Runnable() {
-                public void run() {
-                    b.put(($type$)42);
-                }});
-
-        // The index must be non-negative and lesss than the buffer's limit.
-        tryCatch(b, IndexOutOfBoundsException.class, new Runnable() {
-                public void run() {
-                    b.get(b.limit());
-                }});
-        tryCatch(b, IndexOutOfBoundsException.class, new Runnable() {
-                public void run() {
-                    b.get(-1);
-                }});
-
-        tryCatch(b, IndexOutOfBoundsException.class, new Runnable() {
-                public void run() {
-                    b.put(b.limit(), ($type$)42);
-                }});
-
-        tryCatch(b, InvalidMarkException.class, new Runnable() {
-                public void run() {
-                    b.position(0);
-                    b.mark();
-                    b.compact();
-                    b.reset();
-                }});
+        tryCatch(b, BufferUnderflowException.class, () -> b.get());
+        tryCatch(b, BufferOverflowException.class, () -> b.put(($type$)42));
+        // The index must be non-negative and less than the buffer's limit.
+        catchIndexOutOfBounds(b, () -> b.get(b.limit()));
+        catchIndexOutOfBounds(b, () -> b.get(-1));
+        catchIndexOutOfBounds(b, () -> b.put(b.limit(), ($type$)42));
+        tryCatch(b, InvalidMarkException.class,
+                () -> b.position(0).mark().compact().reset());
 
         try {
             b.position(b.limit() + 1);
@@ -635,7 +637,6 @@
         b.put(0.5121609353879392);      // Changes value if incorrectly swapped
 #end[double]
 
-        $type$ v;
         b.flip();
         ck(b, b.get(), 0);
         ck(b, b.get(), ($type$)-1);
@@ -644,23 +645,27 @@
         ck(b, b.get(), $Fulltype$.MIN_VALUE);
 
 #if[float]
+        $type$ v;
         ck(b, b.get(), -Float.MAX_VALUE);
         ck(b, b.get(), -Float.MIN_VALUE);
         ck(b, b.get(), Float.NEGATIVE_INFINITY);
         ck(b, b.get(), Float.POSITIVE_INFINITY);
         if (Float.floatToRawIntBits(v = b.get()) !=
-            Float.floatToRawIntBits(Float.NaN))
+            Float.floatToRawIntBits(Float.NaN)) {
             fail(b, (long)Float.NaN, (long)v);
+        }
         ck(b, b.get(), 0.91697687f);
 #end[float]
 #if[double]
+        $type$ v;
         ck(b, b.get(), -Double.MAX_VALUE);
         ck(b, b.get(), -Double.MIN_VALUE);
         ck(b, b.get(), Double.NEGATIVE_INFINITY);
         ck(b, b.get(), Double.POSITIVE_INFINITY);
         if (Double.doubleToRawLongBits(v = b.get())
-            != Double.doubleToRawLongBits(Double.NaN))
+            != Double.doubleToRawLongBits(Double.NaN)) {
             fail(b, (long)Double.NaN, (long)v);
+        }
         ck(b, b.get(), 0.5121609353879392);
 #end[double]
 
@@ -683,14 +688,15 @@
 #if[float]
                     || Float.compare(x, y) != 0
 #end[float]
-                    )
+                    ) {
                     out.println("[" + i + "] " + x + " != " + y);
+                }
             }
             fail("Identical buffers not equal", b, b2);
         }
-        if (b.compareTo(b2) != 0)
+        if (b.compareTo(b2) != 0) {
             fail("Comparison to identical buffer != 0", b, b2);
-
+        }
         b.limit(b.limit() + 1);
         b.position(b.limit() - 1);
         b.put(($type$)99);
@@ -714,7 +720,7 @@
             if (xb.compareTo(xb) != 0) {
                 fail("compareTo not reflexive", xb, xb, x, x);
             }
-            if (! xb.equals(xb)) {
+            if (!xb.equals(xb)) {
                 fail("equals not reflexive", xb, xb, x, x);
             }
             for ($type$ y : VALUES) {
@@ -765,9 +771,10 @@
 
         if (!sb.equals(sb2))
             fail("Sliced slices do not match", sb, sb2);
-        if ((sb.hasArray()) && (sb.arrayOffset() != sb2.arrayOffset()))
+        if ((sb.hasArray()) && (sb.arrayOffset() != sb2.arrayOffset())) {
             fail("Array offsets do not match: "
                  + sb.arrayOffset() + " != " + sb2.arrayOffset(), sb, sb2);
+        }
 
 #if[byte]
 
@@ -808,129 +815,49 @@
             fail("Buffer not equal to read-only view", b, rb);
         show(level + 1, rb);
 
-        tryCatch(b, ReadOnlyBufferException.class, new Runnable() {
-                public void run() {
-                    relPut(rb);
-                }});
-
-        tryCatch(b, ReadOnlyBufferException.class, new Runnable() {
-                public void run() {
-                    absPut(rb);
-                }});
-
-        tryCatch(b, ReadOnlyBufferException.class, new Runnable() {
-                public void run() {
-                    bulkPutArray(rb);
-                }});
-
-        tryCatch(b, ReadOnlyBufferException.class, new Runnable() {
-                public void run() {
-                    bulkPutBuffer(rb);
-                }});
+        catchReadOnlyBuffer(b, () -> relPut(rb));
+        catchReadOnlyBuffer(b, () -> absPut(rb));
+        catchReadOnlyBuffer(b, () -> bulkPutArray(rb));
+        catchReadOnlyBuffer(b, () -> bulkPutBuffer(rb));
 
         // put($Type$Buffer) should not change source position
         final $Type$Buffer src = $Type$Buffer.allocate(1);
-        tryCatch(b, ReadOnlyBufferException.class, new Runnable() {
-                public void run() {
-                    rb.put(src);
-                 }});
+        catchReadOnlyBuffer(b, () -> rb.put(src));
         ck(src, src.position(), 0);
 
-        tryCatch(b, ReadOnlyBufferException.class, new Runnable() {
-                public void run() {
-                    rb.compact();
-                }});
+        catchReadOnlyBuffer(b, () -> rb.compact());
 
 #if[byte]
 
-        tryCatch(b, ReadOnlyBufferException.class, new Runnable() {
-                public void run() {
-                    rb.putChar((char)1);
-                }});
-        tryCatch(b, ReadOnlyBufferException.class, new Runnable() {
-                public void run() {
-                    rb.putChar(0, (char)1);
-                }});
-
-        tryCatch(b, ReadOnlyBufferException.class, new Runnable() {
-                public void run() {
-                    rb.putShort((short)1);
-                }});
-        tryCatch(b, ReadOnlyBufferException.class, new Runnable() {
-                public void run() {
-                    rb.putShort(0, (short)1);
-                }});
-
-        tryCatch(b, ReadOnlyBufferException.class, new Runnable() {
-                public void run() {
-                    rb.putInt(1);
-                }});
-        tryCatch(b, ReadOnlyBufferException.class, new Runnable() {
-                public void run() {
-                    rb.putInt(0, 1);
-                }});
-
-        tryCatch(b, ReadOnlyBufferException.class, new Runnable() {
-                public void run() {
-                    rb.putLong((long)1);
-                }});
-        tryCatch(b, ReadOnlyBufferException.class, new Runnable() {
-                public void run() {
-                    rb.putLong(0, (long)1);
-                }});
-
-        tryCatch(b, ReadOnlyBufferException.class, new Runnable() {
-                public void run() {
-                    rb.putFloat((float)1);
-                }});
-        tryCatch(b, ReadOnlyBufferException.class, new Runnable() {
-                public void run() {
-                    rb.putFloat(0, (float)1);
-                }});
-
-        tryCatch(b, ReadOnlyBufferException.class, new Runnable() {
-                public void run() {
-                    rb.putDouble((double)1);
-                }});
-        tryCatch(b, ReadOnlyBufferException.class, new Runnable() {
-                public void run() {
-                    rb.putDouble(0, (double)1);
-                }});
+        catchReadOnlyBuffer(b, () -> rb.putChar((char)1));
+        catchReadOnlyBuffer(b, () -> rb.putChar(0, (char)1));
+        catchReadOnlyBuffer(b, () -> rb.putShort((short)1));
+        catchReadOnlyBuffer(b, () -> rb.putShort(0, (short)1));
+        catchReadOnlyBuffer(b, () -> rb.putInt(1));
+        catchReadOnlyBuffer(b, () -> rb.putInt(0, 1));
+        catchReadOnlyBuffer(b, () -> rb.putLong((long)1));
+        catchReadOnlyBuffer(b, () -> rb.putLong(0, (long)1));
+        catchReadOnlyBuffer(b, () -> rb.putFloat((float)1));
+        catchReadOnlyBuffer(b, () -> rb.putFloat(0, (float)1));
+        catchReadOnlyBuffer(b, () -> rb.putDouble((double)1));
+        catchReadOnlyBuffer(b, () -> rb.putDouble(0, (double)1));
 
 #end[byte]
 
 #if[char]
 
         // 7199551
-        tryCatch(b, ReadOnlyBufferException.class, new Runnable() {
-            public void run() {
-                String s = new String(new char[rb.remaining() + 1]);
-                rb.put(s);
-            }});
-        tryCatch(b, ReadOnlyBufferException.class, new Runnable() {
-            public void run() {
-                String s = new String(new char[rb.remaining() + 1]);
-                rb.append(s);
-            }});
+        catchReadOnlyBuffer(b, () -> rb.put(new String(new char[rb.remaining() + 1])));
+        catchReadOnlyBuffer(b, () -> rb.append(new String(new char[rb.remaining() + 1])));
 
 #end[char]
 
         if (rb.getClass().getName().startsWith("java.nio.Heap")) {
-
-            tryCatch(b, ReadOnlyBufferException.class, new Runnable() {
-                    public void run() {
-                        rb.array();
-                    }});
-
-            tryCatch(b, ReadOnlyBufferException.class, new Runnable() {
-                    public void run() {
-                        rb.arrayOffset();
-                    }});
-
-            if (rb.hasArray())
-                fail("Read-only heap buffer's backing array is accessible",
-                     rb);
-
+            catchReadOnlyBuffer(b, () -> rb.array());
+            catchReadOnlyBuffer(b, () -> rb.arrayOffset());
+            if (rb.hasArray()) {
+                fail("Read-only heap buffer's backing array is accessible", rb);
+            }
         }
 
         // Bulk puts from read-only buffers
@@ -969,10 +896,7 @@
         ck(b, b.toString().equals(s.substring(start, end)));
         ck(b, b.toString().equals("defghi"));
         ck(b, b.isReadOnly());
-        tryCatch(b, ReadOnlyBufferException.class, new Runnable() {
-                public void run() {
-                    b.put('x');
-                }});
+        catchReadOnlyBuffer(b, () -> b.put('x'));
         ck(b, start, b.position());
         ck(b, end, b.limit());
         ck(b, s.length(), b.capacity());
@@ -981,63 +905,25 @@
 
         // The index, relative to the position, must be non-negative and
         // smaller than remaining().
-        tryCatch(b, IndexOutOfBoundsException.class, new Runnable() {
-                public void run() {
-                    b.charAt(-1);
-                }});
-        tryCatch(b, IndexOutOfBoundsException.class, new Runnable() {
-                public void run() {
-                    b.charAt(b.remaining());
-                }});
-
+        catchIndexOutOfBounds(b, () -> b.charAt(-1));
+        catchIndexOutOfBounds(b, () -> b.charAt(b.remaining()));
         // The index must be non-negative and less than the buffer's limit.
-        tryCatch(b, IndexOutOfBoundsException.class, new Runnable() {
-                public void run() {
-                    b.get(b.limit());
-                }});
-        tryCatch(b, IndexOutOfBoundsException.class, new Runnable() {
-                public void run() {
-                    b.get(-1);
-                }});
-
+        catchIndexOutOfBounds(b, () -> b.get(b.limit()));
+        catchIndexOutOfBounds(b, () -> b.get(-1));
         // The start must be non-negative and no larger than remaining().
-        tryCatch(b, IndexOutOfBoundsException.class, new Runnable() {
-                public void run() {
-                    b.subSequence(-1, b.remaining());
-                }});
-        tryCatch(b, IndexOutOfBoundsException.class, new Runnable() {
-                public void run() {
-                    b.subSequence(b.remaining() + 1, b.remaining());
-                }});
+        catchIndexOutOfBounds(b, () -> b.subSequence(-1, b.remaining()));
+        catchIndexOutOfBounds(b, () -> b.subSequence(b.remaining() + 1, b.remaining()));
 
         // The end must be no smaller than start and no larger than
         // remaining().
-        tryCatch(b, IndexOutOfBoundsException.class, new Runnable() {
-                public void run() {
-                    b.subSequence(2, 1);
-                }});
-        tryCatch(b, IndexOutOfBoundsException.class, new Runnable() {
-                public void run() {
-                    b.subSequence(0, b.remaining() + 1);
-                }});
+        catchIndexOutOfBounds(b, () -> b.subSequence(2, 1));
+        catchIndexOutOfBounds(b, () -> b.subSequence(0, b.remaining() + 1));
 
         // The offset must be non-negative and no larger than <array.length>.
-        tryCatch(b, IndexOutOfBoundsException.class, new Runnable() {
-                public void run() {
-                    $Type$Buffer.wrap(s, -1, s.length());
-                }});
-        tryCatch(b, IndexOutOfBoundsException.class, new Runnable() {
-                public void run() {
-                    $Type$Buffer.wrap(s, s.length() + 1, s.length());
-                }});
-        tryCatch(b, IndexOutOfBoundsException.class, new Runnable() {
-                public void run() {
-                    $Type$Buffer.wrap(s, 1, 0);
-                }});
-        tryCatch(b, IndexOutOfBoundsException.class, new Runnable() {
-                public void run() {
-                    $Type$Buffer.wrap(s, 0, s.length() + 1);
-                }});
+        catchIndexOutOfBounds(b, () -> $Type$Buffer.wrap(s, -1, s.length()));
+        catchIndexOutOfBounds(b, () -> $Type$Buffer.wrap(s, s.length() + 1, s.length()));
+        catchIndexOutOfBounds(b, () -> $Type$Buffer.wrap(s, 1, 0));
+        catchIndexOutOfBounds(b, () -> $Type$Buffer.wrap(s, 0, s.length() + 1));
     }
 
 #end[char]
@@ -1052,40 +938,21 @@
         ck(b, b.limit(), offset + length);
 
         // The offset must be non-negative and no larger than <array.length>.
-        tryCatch(ba, IndexOutOfBoundsException.class, new Runnable() {
-                public void run() {
-                    $Type$Buffer.wrap(ba, -1, ba.length);
-                }});
-        tryCatch(ba, IndexOutOfBoundsException.class, new Runnable() {
-                public void run() {
-                    $Type$Buffer.wrap(ba, ba.length + 1, ba.length);
-                }});
-        tryCatch(ba, IndexOutOfBoundsException.class, new Runnable() {
-                public void run() {
-                    $Type$Buffer.wrap(ba, 0, -1);
-                }});
-        tryCatch(ba, IndexOutOfBoundsException.class, new Runnable() {
-                public void run() {
-                    $Type$Buffer.wrap(ba, 0, ba.length + 1);
-                }});
+        catchIndexOutOfBounds(ba, () -> $Type$Buffer.wrap(ba, -1, ba.length));
+        catchIndexOutOfBounds(ba, () -> $Type$Buffer.wrap(ba, ba.length + 1, ba.length));
+        catchIndexOutOfBounds(ba, () -> $Type$Buffer.wrap(ba, 0, -1));
+        catchIndexOutOfBounds(ba, () -> $Type$Buffer.wrap(ba, 0, ba.length + 1));
 
         // A NullPointerException will be thrown if the array is null.
-        tryCatch(ba, NullPointerException.class, new Runnable() {
-                public void run() {
-                    $Type$Buffer.wrap(($type$ []) null, 0, 5);
-                }});
-        tryCatch(ba, NullPointerException.class, new Runnable() {
-                public void run() {
-                    $Type$Buffer.wrap(($type$ []) null);
-                }});
+        tryCatch(ba, NullPointerException.class,
+                () -> $Type$Buffer.wrap(($type$ []) null, 0, 5));
+        tryCatch(ba, NullPointerException.class,
+                () -> $Type$Buffer.wrap(($type$ []) null));
     }
 
     private static void testAllocate() {
         // An IllegalArgumentException will be thrown for negative capacities.
-        tryCatch((Buffer) null, IllegalArgumentException.class, new Runnable() {
-                public void run() {
-                    $Type$Buffer.allocate(-1);
-                }});
+        catchIllegalArgument((Buffer) null, () -> $Type$Buffer.allocate(-1));
         try {
             $Type$Buffer.allocate(-1);
         } catch (IllegalArgumentException e) {
@@ -1095,10 +962,7 @@
             }
         }
 #if[byte]
-        tryCatch((Buffer) null, IllegalArgumentException.class, new Runnable() {
-                public void run() {
-                    $Type$Buffer.allocateDirect(-1);
-                }});
+        catchIllegalArgument((Buffer) null, () -> $Type$Buffer.allocateDirect(-1));
         try {
             $Type$Buffer.allocateDirect(-1);
         } catch (IllegalArgumentException e) {
--- a/test/java/nio/Buffer/BasicByte.java	Mon May 16 07:01:26 2016 +0200
+++ b/test/java/nio/Buffer/BasicByte.java	Mon May 16 09:54:01 2016 +0100
@@ -31,7 +31,6 @@
 // -- This file was mechanically generated: Do not edit! -- //
 
 import java.nio.*;
-import java.lang.reflect.Method;
 
 
 public class BasicByte
@@ -60,7 +59,6 @@
 
     private static void relGet(ByteBuffer b) {
         int n = b.capacity();
-        byte v;
         for (int i = 0; i < n; i++)
             ck(b, (long)b.get(), (long)((byte)ic(i)));
         b.rewind();
@@ -68,7 +66,6 @@
 
     private static void relGet(ByteBuffer b, int start) {
         int n = b.remaining();
-        byte v;
         for (int i = start; i < n; i++)
             ck(b, (long)b.get(), (long)((byte)ic(i)));
         b.rewind();
@@ -76,7 +73,6 @@
 
     private static void absGet(ByteBuffer b) {
         int n = b.capacity();
-        byte v;
         for (int i = 0; i < n; i++)
             ck(b, (long)b.get(), (long)((byte)ic(i)));
         b.rewind();
@@ -86,8 +82,9 @@
         int n = b.capacity();
         byte[] a = new byte[n + 7];
         b.get(a, 7, n);
-        for (int i = 0; i < n; i++)
+        for (int i = 0; i < n; i++) {
             ck(b, (long)a[i + 7], (long)((byte)ic(i)));
+        }
     }
 
     private static void relPut(ByteBuffer b) {
@@ -203,13 +200,14 @@
     private static void checkBytes(ByteBuffer b, byte[] bs) {
         int n = bs.length;
         int p = b.position();
-        byte v;
         if (b.order() == ByteOrder.BIG_ENDIAN) {
-            for (int i = 0; i < n; i++)
+            for (int i = 0; i < n; i++) {
                 ck(b, b.get(), bs[i]);
+            }
         } else {
-            for (int i = n - 1; i >= 0; i--)
+            for (int i = n - 1; i >= 0; i--) {
                 ck(b, b.get(), bs[i]);
+            }
         }
         b.position(p);
     }
@@ -217,7 +215,7 @@
     private static void compact(Buffer b) {
         try {
             Class<?> cl = b.getClass();
-            Method m = cl.getDeclaredMethod("compact");
+            java.lang.reflect.Method m = cl.getDeclaredMethod("compact");
             m.setAccessible(true);
             m.invoke(b);
         } catch (Exception e) {
@@ -226,12 +224,11 @@
     }
 
     private static void checkInvalidMarkException(final Buffer b) {
-        tryCatch(b, InvalidMarkException.class, new Runnable() {
-            public void run() {
+        tryCatch(b, InvalidMarkException.class, () -> {
                 b.mark();
                 compact(b);
                 b.reset();
-            }});
+            });
     }
 
     private static void testViews(int level, ByteBuffer b, boolean direct) {
@@ -338,41 +335,50 @@
 
     private static void testAlign(final ByteBuffer b, boolean direct) {
         // index out-of bounds
-        tryCatch(b, IllegalArgumentException.class, () -> b.alignmentOffset(-1, (short) 1));
+        catchIllegalArgument(b, () -> b.alignmentOffset(-1, (short) 1));
 
         // unit size values
-        tryCatch(b, IllegalArgumentException.class, () -> b.alignmentOffset(0, (short) 0));
+        catchIllegalArgument(b, () -> b.alignmentOffset(0, (short) 0));
         for (int us = 1; us < 65; us++) {
             int _us = us;
             if ((us & (us - 1)) != 0) {
                 // unit size not a power of two
-                tryCatch(b, IllegalArgumentException.class, () -> b.alignmentOffset(0, _us));
+                catchIllegalArgument(b, () -> b.alignmentOffset(0, _us));
             } else {
                 if (direct || us <= 8) {
                     b.alignmentOffset(0, us);
                 } else {
                     // unit size > 8 with non-direct buffer
-                    tryCatch(b, UnsupportedOperationException.class, () -> b.alignmentOffset(0, _us));
+                    tryCatch(b, UnsupportedOperationException.class,
+                            () -> b.alignmentOffset(0, _us));
                 }
             }
         }
 
         // Probe for long misalignment at index zero for a newly created buffer
-        ByteBuffer empty = direct ? ByteBuffer.allocateDirect(0) : ByteBuffer.allocate(0);
+        ByteBuffer empty =
+                direct ? ByteBuffer.allocateDirect(0) : ByteBuffer.allocate(0);
         int longMisalignmentAtZero = empty.alignmentOffset(0, 8);
 
         if (direct) {
             // Freshly created direct byte buffers should be aligned at index 0
             // for ref and primitive values (see Unsafe.allocateMemory)
-            if (longMisalignmentAtZero != 0)
-                fail("Direct byte buffer misalligned at index 0 for ref and primitive values " + longMisalignmentAtZero);
+            if (longMisalignmentAtZero != 0) {
+                fail("Direct byte buffer misaligned at index 0"
+                        + " for ref and primitive values "
+                        + longMisalignmentAtZero);
+            }
         } else {
             // For heap byte buffers misalignment may occur on 32-bit systems
             // where Unsafe.ARRAY_BYTE_BASE_OFFSET % 8 == 4 and not 0
             // Note the GC will preserve alignment of the base address of the
             // array
-            if (jdk.internal.misc.Unsafe.ARRAY_BYTE_BASE_OFFSET % 8 != longMisalignmentAtZero)
-                fail("Heap byte buffer misalligned at index 0 for ref and primitive values " + longMisalignmentAtZero);
+            if (jdk.internal.misc.Unsafe.ARRAY_BYTE_BASE_OFFSET % 8
+                    != longMisalignmentAtZero) {
+                fail("Heap byte buffer misaligned at index 0"
+                        + " for ref and primitive values "
+                        + longMisalignmentAtZero);
+            }
         }
 
         // Ensure test buffer is correctly aligned at index 0
@@ -385,8 +391,10 @@
                 int am = b.alignmentOffset(i, us);
                 int expectedAm = (longMisalignmentAtZero + i) % us;
 
-                if (am != expectedAm)
-                    fail(String.format("b.alignmentOffset(%d, %d) == %d incorrect, expected %d", i, us, am, expectedAm));
+                if (am != expectedAm) {
+                    String f = "b.alignmentOffset(%d, %d) == %d incorrect, expected %d";
+                    fail(String.format(f, i, us, am, expectedAm));
+                }
             }
         }
 
@@ -395,8 +403,10 @@
         int al = b.limit() - b.alignmentOffset(b.limit(), 8);
         ByteBuffer ab = b.position(ap).limit(al).
                 slice();
-        if (ab.limit() == 0)
-            fail("Test input buffer not sufficiently sized to cover an aligned region for all values", b);
+        if (ab.limit() == 0) {
+            fail("Test input buffer not sufficiently sized to cover" +
+                    " an aligned region for all values", b);
+        }
         if (ab.alignmentOffset(0, 8) != 0)
             fail("Aligned test input buffer not correctly aligned at index 0", ab);
 
@@ -428,8 +438,9 @@
                 l = l - l_mod;
 
                 int ec = l - p;
-                if (as.limit() != ec)
+                if (as.limit() != ec) {
                     fail("Buffer capacity incorrect, expected: " + ec, as);
+                }
             }
         }
     }
@@ -441,6 +452,22 @@
         fail(problem + String.format(": x=%s y=%s", x, y), xb, yb);
     }
 
+    private static void catchIllegalArgument(Buffer b, Runnable thunk) {
+        tryCatch(b, IllegalArgumentException.class, thunk);
+    }
+
+    private static void catchReadOnlyBuffer(Buffer b, Runnable thunk) {
+        tryCatch(b, ReadOnlyBufferException.class, thunk);
+    }
+
+    private static void catchIndexOutOfBounds(Buffer b, Runnable thunk) {
+        tryCatch(b, IndexOutOfBoundsException.class, thunk);
+    }
+
+    private static void catchIndexOutOfBounds(byte[] t, Runnable thunk) {
+        tryCatch(t, IndexOutOfBoundsException.class, thunk);
+    }
+
     private static void tryCatch(Buffer b, Class<?> ex, Runnable thunk) {
         boolean caught = false;
         try {
@@ -452,11 +479,12 @@
                 fail(x.getMessage() + " not expected");
             }
         }
-        if (!caught)
+        if (!caught) {
             fail(ex.getName() + " not thrown", b);
+        }
     }
 
-    private static void tryCatch(byte [] t, Class<?> ex, Runnable thunk) {
+    private static void tryCatch(byte[] t, Class<?> ex, Runnable thunk) {
         tryCatch(ByteBuffer.wrap(t), ex, thunk);
     }
 
@@ -521,8 +549,6 @@
 
 
 
-
-
         // Compact
 
         relPut(b);
@@ -537,38 +563,14 @@
         b.limit(b.capacity() / 2);
         b.position(b.limit());
 
-        tryCatch(b, BufferUnderflowException.class, new Runnable() {
-                public void run() {
-                    b.get();
-                }});
-
-        tryCatch(b, BufferOverflowException.class, new Runnable() {
-                public void run() {
-                    b.put((byte)42);
-                }});
-
-        // The index must be non-negative and lesss than the buffer's limit.
-        tryCatch(b, IndexOutOfBoundsException.class, new Runnable() {
-                public void run() {
-                    b.get(b.limit());
-                }});
-        tryCatch(b, IndexOutOfBoundsException.class, new Runnable() {
-                public void run() {
-                    b.get(-1);
-                }});
-
-        tryCatch(b, IndexOutOfBoundsException.class, new Runnable() {
-                public void run() {
-                    b.put(b.limit(), (byte)42);
-                }});
-
-        tryCatch(b, InvalidMarkException.class, new Runnable() {
-                public void run() {
-                    b.position(0);
-                    b.mark();
-                    b.compact();
-                    b.reset();
-                }});
+        tryCatch(b, BufferUnderflowException.class, () -> b.get());
+        tryCatch(b, BufferOverflowException.class, () -> b.put((byte)42));
+        // The index must be non-negative and less than the buffer's limit.
+        catchIndexOutOfBounds(b, () -> b.get(b.limit()));
+        catchIndexOutOfBounds(b, () -> b.get(-1));
+        catchIndexOutOfBounds(b, () -> b.put(b.limit(), (byte)42));
+        tryCatch(b, InvalidMarkException.class,
+                () -> b.position(0).mark().compact().reset());
 
         try {
             b.position(b.limit() + 1);
@@ -635,7 +637,6 @@
 
 
 
-        byte v;
         b.flip();
         ck(b, b.get(), 0);
         ck(b, b.get(), (byte)-1);
@@ -665,6 +666,10 @@
 
 
 
+
+
+
+
         // Comparison
         b.rewind();
         ByteBuffer b2 = ByteBuffer.allocate(b.capacity());
@@ -683,14 +688,15 @@
 
 
 
-                    )
+                    ) {
                     out.println("[" + i + "] " + x + " != " + y);
+                }
             }
             fail("Identical buffers not equal", b, b2);
         }
-        if (b.compareTo(b2) != 0)
+        if (b.compareTo(b2) != 0) {
             fail("Comparison to identical buffer != 0", b, b2);
-
+        }
         b.limit(b.limit() + 1);
         b.position(b.limit() - 1);
         b.put((byte)99);
@@ -714,7 +720,7 @@
             if (xb.compareTo(xb) != 0) {
                 fail("compareTo not reflexive", xb, xb, x, x);
             }
-            if (! xb.equals(xb)) {
+            if (!xb.equals(xb)) {
                 fail("equals not reflexive", xb, xb, x, x);
             }
             for (byte y : VALUES) {
@@ -765,9 +771,10 @@
 
         if (!sb.equals(sb2))
             fail("Sliced slices do not match", sb, sb2);
-        if ((sb.hasArray()) && (sb.arrayOffset() != sb2.arrayOffset()))
+        if ((sb.hasArray()) && (sb.arrayOffset() != sb2.arrayOffset())) {
             fail("Array offsets do not match: "
                  + sb.arrayOffset() + " != " + sb2.arrayOffset(), sb, sb2);
+        }
 
 
 
@@ -808,102 +815,32 @@
             fail("Buffer not equal to read-only view", b, rb);
         show(level + 1, rb);
 
-        tryCatch(b, ReadOnlyBufferException.class, new Runnable() {
-                public void run() {
-                    relPut(rb);
-                }});
-
-        tryCatch(b, ReadOnlyBufferException.class, new Runnable() {
-                public void run() {
-                    absPut(rb);
-                }});
-
-        tryCatch(b, ReadOnlyBufferException.class, new Runnable() {
-                public void run() {
-                    bulkPutArray(rb);
-                }});
-
-        tryCatch(b, ReadOnlyBufferException.class, new Runnable() {
-                public void run() {
-                    bulkPutBuffer(rb);
-                }});
+        catchReadOnlyBuffer(b, () -> relPut(rb));
+        catchReadOnlyBuffer(b, () -> absPut(rb));
+        catchReadOnlyBuffer(b, () -> bulkPutArray(rb));
+        catchReadOnlyBuffer(b, () -> bulkPutBuffer(rb));
 
         // put(ByteBuffer) should not change source position
         final ByteBuffer src = ByteBuffer.allocate(1);
-        tryCatch(b, ReadOnlyBufferException.class, new Runnable() {
-                public void run() {
-                    rb.put(src);
-                 }});
+        catchReadOnlyBuffer(b, () -> rb.put(src));
         ck(src, src.position(), 0);
 
-        tryCatch(b, ReadOnlyBufferException.class, new Runnable() {
-                public void run() {
-                    rb.compact();
-                }});
+        catchReadOnlyBuffer(b, () -> rb.compact());
 
 
 
-        tryCatch(b, ReadOnlyBufferException.class, new Runnable() {
-                public void run() {
-                    rb.putChar((char)1);
-                }});
-        tryCatch(b, ReadOnlyBufferException.class, new Runnable() {
-                public void run() {
-                    rb.putChar(0, (char)1);
-                }});
-
-        tryCatch(b, ReadOnlyBufferException.class, new Runnable() {
-                public void run() {
-                    rb.putShort((short)1);
-                }});
-        tryCatch(b, ReadOnlyBufferException.class, new Runnable() {
-                public void run() {
-                    rb.putShort(0, (short)1);
-                }});
-
-        tryCatch(b, ReadOnlyBufferException.class, new Runnable() {
-                public void run() {
-                    rb.putInt(1);
-                }});
-        tryCatch(b, ReadOnlyBufferException.class, new Runnable() {
-                public void run() {
-                    rb.putInt(0, 1);
-                }});
-
-        tryCatch(b, ReadOnlyBufferException.class, new Runnable() {
-                public void run() {
-                    rb.putLong((long)1);
-                }});
-        tryCatch(b, ReadOnlyBufferException.class, new Runnable() {
-                public void run() {
-                    rb.putLong(0, (long)1);
-                }});
-
-        tryCatch(b, ReadOnlyBufferException.class, new Runnable() {
-                public void run() {
-                    rb.putFloat((float)1);
-                }});
-        tryCatch(b, ReadOnlyBufferException.class, new Runnable() {
-                public void run() {
-                    rb.putFloat(0, (float)1);
-                }});
-
-        tryCatch(b, ReadOnlyBufferException.class, new Runnable() {
-                public void run() {
-                    rb.putDouble((double)1);
-                }});
-        tryCatch(b, ReadOnlyBufferException.class, new Runnable() {
-                public void run() {
-                    rb.putDouble(0, (double)1);
-                }});
-
-
-
-
-
-
-
-
+        catchReadOnlyBuffer(b, () -> rb.putChar((char)1));
+        catchReadOnlyBuffer(b, () -> rb.putChar(0, (char)1));
+        catchReadOnlyBuffer(b, () -> rb.putShort((short)1));
+        catchReadOnlyBuffer(b, () -> rb.putShort(0, (short)1));
+        catchReadOnlyBuffer(b, () -> rb.putInt(1));
+        catchReadOnlyBuffer(b, () -> rb.putInt(0, 1));
+        catchReadOnlyBuffer(b, () -> rb.putLong((long)1));
+        catchReadOnlyBuffer(b, () -> rb.putLong(0, (long)1));
+        catchReadOnlyBuffer(b, () -> rb.putFloat((float)1));
+        catchReadOnlyBuffer(b, () -> rb.putFloat(0, (float)1));
+        catchReadOnlyBuffer(b, () -> rb.putDouble((double)1));
+        catchReadOnlyBuffer(b, () -> rb.putDouble(0, (double)1));
 
 
 
@@ -916,21 +853,11 @@
 
 
         if (rb.getClass().getName().startsWith("java.nio.Heap")) {
-
-            tryCatch(b, ReadOnlyBufferException.class, new Runnable() {
-                    public void run() {
-                        rb.array();
-                    }});
-
-            tryCatch(b, ReadOnlyBufferException.class, new Runnable() {
-                    public void run() {
-                        rb.arrayOffset();
-                    }});
-
-            if (rb.hasArray())
-                fail("Read-only heap buffer's backing array is accessible",
-                     rb);
-
+            catchReadOnlyBuffer(b, () -> rb.array());
+            catchReadOnlyBuffer(b, () -> rb.arrayOffset());
+            if (rb.hasArray()) {
+                fail("Read-only heap buffer's backing array is accessible", rb);
+            }
         }
 
         // Bulk puts from read-only buffers
@@ -1001,47 +928,6 @@
 
 
 
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
     public static void test(final byte [] ba) {
         int offset = 47;
         int length = 900;
@@ -1052,40 +938,21 @@
         ck(b, b.limit(), offset + length);
 
         // The offset must be non-negative and no larger than <array.length>.
-        tryCatch(ba, IndexOutOfBoundsException.class, new Runnable() {
-                public void run() {
-                    ByteBuffer.wrap(ba, -1, ba.length);
-                }});
-        tryCatch(ba, IndexOutOfBoundsException.class, new Runnable() {
-                public void run() {
-                    ByteBuffer.wrap(ba, ba.length + 1, ba.length);
-                }});
-        tryCatch(ba, IndexOutOfBoundsException.class, new Runnable() {
-                public void run() {
-                    ByteBuffer.wrap(ba, 0, -1);
-                }});
-        tryCatch(ba, IndexOutOfBoundsException.class, new Runnable() {
-                public void run() {
-                    ByteBuffer.wrap(ba, 0, ba.length + 1);
-                }});
+        catchIndexOutOfBounds(ba, () -> ByteBuffer.wrap(ba, -1, ba.length));
+        catchIndexOutOfBounds(ba, () -> ByteBuffer.wrap(ba, ba.length + 1, ba.length));
+        catchIndexOutOfBounds(ba, () -> ByteBuffer.wrap(ba, 0, -1));
+        catchIndexOutOfBounds(ba, () -> ByteBuffer.wrap(ba, 0, ba.length + 1));
 
         // A NullPointerException will be thrown if the array is null.
-        tryCatch(ba, NullPointerException.class, new Runnable() {
-                public void run() {
-                    ByteBuffer.wrap((byte []) null, 0, 5);
-                }});
-        tryCatch(ba, NullPointerException.class, new Runnable() {
-                public void run() {
-                    ByteBuffer.wrap((byte []) null);
-                }});
+        tryCatch(ba, NullPointerException.class,
+                () -> ByteBuffer.wrap((byte []) null, 0, 5));
+        tryCatch(ba, NullPointerException.class,
+                () -> ByteBuffer.wrap((byte []) null));
     }
 
     private static void testAllocate() {
         // An IllegalArgumentException will be thrown for negative capacities.
-        tryCatch((Buffer) null, IllegalArgumentException.class, new Runnable() {
-                public void run() {
-                    ByteBuffer.allocate(-1);
-                }});
+        catchIllegalArgument((Buffer) null, () -> ByteBuffer.allocate(-1));
         try {
             ByteBuffer.allocate(-1);
         } catch (IllegalArgumentException e) {
@@ -1095,10 +962,7 @@
             }
         }
 
-        tryCatch((Buffer) null, IllegalArgumentException.class, new Runnable() {
-                public void run() {
-                    ByteBuffer.allocateDirect(-1);
-                }});
+        catchIllegalArgument((Buffer) null, () -> ByteBuffer.allocateDirect(-1));
         try {
             ByteBuffer.allocateDirect(-1);
         } catch (IllegalArgumentException e) {
--- a/test/java/nio/Buffer/BasicChar.java	Mon May 16 07:01:26 2016 +0200
+++ b/test/java/nio/Buffer/BasicChar.java	Mon May 16 09:54:01 2016 +0100
@@ -31,7 +31,6 @@
 // -- This file was mechanically generated: Do not edit! -- //
 
 import java.nio.*;
-import java.lang.reflect.Method;
 
 
 public class BasicChar
@@ -60,7 +59,6 @@
 
     private static void relGet(CharBuffer b) {
         int n = b.capacity();
-        char v;
         for (int i = 0; i < n; i++)
             ck(b, (long)b.get(), (long)((char)ic(i)));
         b.rewind();
@@ -68,7 +66,6 @@
 
     private static void relGet(CharBuffer b, int start) {
         int n = b.remaining();
-        char v;
         for (int i = start; i < n; i++)
             ck(b, (long)b.get(), (long)((char)ic(i)));
         b.rewind();
@@ -76,7 +73,6 @@
 
     private static void absGet(CharBuffer b) {
         int n = b.capacity();
-        char v;
         for (int i = 0; i < n; i++)
             ck(b, (long)b.get(), (long)((char)ic(i)));
         b.rewind();
@@ -86,8 +82,9 @@
         int n = b.capacity();
         char[] a = new char[n + 7];
         b.get(a, 7, n);
-        for (int i = 0; i < n; i++)
+        for (int i = 0; i < n; i++) {
             ck(b, (long)a[i + 7], (long)((char)ic(i)));
+        }
     }
 
     private static void relPut(CharBuffer b) {
@@ -178,7 +175,7 @@
     private static void bulkPutString(CharBuffer b) {
         int n = b.capacity();
         b.clear();
-        StringBuffer sb = new StringBuffer(n + 7);
+        StringBuilder sb = new StringBuilder(n + 7);
         sb.append("1234567");
         for (int i = 0; i < n; i++)
             sb.append((char)ic(i));
@@ -435,12 +432,42 @@
 
 
 
+
+
+
+
+
+
+
+
+
+
+
+
+
+
     private static void fail(String problem,
                              CharBuffer xb, CharBuffer yb,
                              char x, char y) {
         fail(problem + String.format(": x=%s y=%s", x, y), xb, yb);
     }
 
+    private static void catchIllegalArgument(Buffer b, Runnable thunk) {
+        tryCatch(b, IllegalArgumentException.class, thunk);
+    }
+
+    private static void catchReadOnlyBuffer(Buffer b, Runnable thunk) {
+        tryCatch(b, ReadOnlyBufferException.class, thunk);
+    }
+
+    private static void catchIndexOutOfBounds(Buffer b, Runnable thunk) {
+        tryCatch(b, IndexOutOfBoundsException.class, thunk);
+    }
+
+    private static void catchIndexOutOfBounds(char[] t, Runnable thunk) {
+        tryCatch(t, IndexOutOfBoundsException.class, thunk);
+    }
+
     private static void tryCatch(Buffer b, Class<?> ex, Runnable thunk) {
         boolean caught = false;
         try {
@@ -452,11 +479,12 @@
                 fail(x.getMessage() + " not expected");
             }
         }
-        if (!caught)
+        if (!caught) {
             fail(ex.getName() + " not thrown", b);
+        }
     }
 
-    private static void tryCatch(char [] t, Class<?> ex, Runnable thunk) {
+    private static void tryCatch(char[] t, Class<?> ex, Runnable thunk) {
         tryCatch(CharBuffer.wrap(t), ex, thunk);
     }
 
@@ -513,11 +541,9 @@
         // 7190219
         b.clear();
         int pos = b.position();
-        tryCatch(b, BufferOverflowException.class, new Runnable() {
-            public void run() {
-                b.put(String.valueOf(new char[b.capacity() + 1]), 0,
-                        b.capacity() + 1);
-            }});
+        tryCatch(b, BufferOverflowException.class, () ->
+                b.put(String.valueOf(new char[b.capacity() + 1]), 0, b.capacity() + 1)
+            );
         ck(b, b.position(), pos);
         relGet(b);
 
@@ -537,38 +563,14 @@
         b.limit(b.capacity() / 2);
         b.position(b.limit());
 
-        tryCatch(b, BufferUnderflowException.class, new Runnable() {
-                public void run() {
-                    b.get();
-                }});
-
-        tryCatch(b, BufferOverflowException.class, new Runnable() {
-                public void run() {
-                    b.put((char)42);
-                }});
-
-        // The index must be non-negative and lesss than the buffer's limit.
-        tryCatch(b, IndexOutOfBoundsException.class, new Runnable() {
-                public void run() {
-                    b.get(b.limit());
-                }});
-        tryCatch(b, IndexOutOfBoundsException.class, new Runnable() {
-                public void run() {
-                    b.get(-1);
-                }});
-
-        tryCatch(b, IndexOutOfBoundsException.class, new Runnable() {
-                public void run() {
-                    b.put(b.limit(), (char)42);
-                }});
-
-        tryCatch(b, InvalidMarkException.class, new Runnable() {
-                public void run() {
-                    b.position(0);
-                    b.mark();
-                    b.compact();
-                    b.reset();
-                }});
+        tryCatch(b, BufferUnderflowException.class, () -> b.get());
+        tryCatch(b, BufferOverflowException.class, () -> b.put((char)42));
+        // The index must be non-negative and less than the buffer's limit.
+        catchIndexOutOfBounds(b, () -> b.get(b.limit()));
+        catchIndexOutOfBounds(b, () -> b.get(-1));
+        catchIndexOutOfBounds(b, () -> b.put(b.limit(), (char)42));
+        tryCatch(b, InvalidMarkException.class,
+                () -> b.position(0).mark().compact().reset());
 
         try {
             b.position(b.limit() + 1);
@@ -635,7 +637,6 @@
 
 
 
-        char v;
         b.flip();
         ck(b, b.get(), 0);
         ck(b, b.get(), (char)-1);
@@ -665,6 +666,10 @@
 
 
 
+
+
+
+
         // Comparison
         b.rewind();
         CharBuffer b2 = CharBuffer.allocate(b.capacity());
@@ -683,14 +688,15 @@
 
 
 
-                    )
+                    ) {
                     out.println("[" + i + "] " + x + " != " + y);
+                }
             }
             fail("Identical buffers not equal", b, b2);
         }
-        if (b.compareTo(b2) != 0)
+        if (b.compareTo(b2) != 0) {
             fail("Comparison to identical buffer != 0", b, b2);
-
+        }
         b.limit(b.limit() + 1);
         b.position(b.limit() - 1);
         b.put((char)99);
@@ -714,7 +720,7 @@
             if (xb.compareTo(xb) != 0) {
                 fail("compareTo not reflexive", xb, xb, x, x);
             }
-            if (! xb.equals(xb)) {
+            if (!xb.equals(xb)) {
                 fail("equals not reflexive", xb, xb, x, x);
             }
             for (char y : VALUES) {
@@ -765,9 +771,10 @@
 
         if (!sb.equals(sb2))
             fail("Sliced slices do not match", sb, sb2);
-        if ((sb.hasArray()) && (sb.arrayOffset() != sb2.arrayOffset()))
+        if ((sb.hasArray()) && (sb.arrayOffset() != sb2.arrayOffset())) {
             fail("Array offsets do not match: "
                  + sb.arrayOffset() + " != " + sb2.arrayOffset(), sb, sb2);
+        }
 
 
 
@@ -808,79 +815,17 @@
             fail("Buffer not equal to read-only view", b, rb);
         show(level + 1, rb);
 
-        tryCatch(b, ReadOnlyBufferException.class, new Runnable() {
-                public void run() {
-                    relPut(rb);
-                }});
-
-        tryCatch(b, ReadOnlyBufferException.class, new Runnable() {
-                public void run() {
-                    absPut(rb);
-                }});
-
-        tryCatch(b, ReadOnlyBufferException.class, new Runnable() {
-                public void run() {
-                    bulkPutArray(rb);
-                }});
-
-        tryCatch(b, ReadOnlyBufferException.class, new Runnable() {
-                public void run() {
-                    bulkPutBuffer(rb);
-                }});
+        catchReadOnlyBuffer(b, () -> relPut(rb));
+        catchReadOnlyBuffer(b, () -> absPut(rb));
+        catchReadOnlyBuffer(b, () -> bulkPutArray(rb));
+        catchReadOnlyBuffer(b, () -> bulkPutBuffer(rb));
 
         // put(CharBuffer) should not change source position
         final CharBuffer src = CharBuffer.allocate(1);
-        tryCatch(b, ReadOnlyBufferException.class, new Runnable() {
-                public void run() {
-                    rb.put(src);
-                 }});
+        catchReadOnlyBuffer(b, () -> rb.put(src));
         ck(src, src.position(), 0);
 
-        tryCatch(b, ReadOnlyBufferException.class, new Runnable() {
-                public void run() {
-                    rb.compact();
-                }});
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+        catchReadOnlyBuffer(b, () -> rb.compact());
 
 
 
@@ -902,35 +847,17 @@
 
 
         // 7199551
-        tryCatch(b, ReadOnlyBufferException.class, new Runnable() {
-            public void run() {
-                String s = new String(new char[rb.remaining() + 1]);
-                rb.put(s);
-            }});
-        tryCatch(b, ReadOnlyBufferException.class, new Runnable() {
-            public void run() {
-                String s = new String(new char[rb.remaining() + 1]);
-                rb.append(s);
-            }});
+        catchReadOnlyBuffer(b, () -> rb.put(new String(new char[rb.remaining() + 1])));
+        catchReadOnlyBuffer(b, () -> rb.append(new String(new char[rb.remaining() + 1])));
 
 
 
         if (rb.getClass().getName().startsWith("java.nio.Heap")) {
-
-            tryCatch(b, ReadOnlyBufferException.class, new Runnable() {
-                    public void run() {
-                        rb.array();
-                    }});
-
-            tryCatch(b, ReadOnlyBufferException.class, new Runnable() {
-                    public void run() {
-                        rb.arrayOffset();
-                    }});
-
-            if (rb.hasArray())
-                fail("Read-only heap buffer's backing array is accessible",
-                     rb);
-
+            catchReadOnlyBuffer(b, () -> rb.array());
+            catchReadOnlyBuffer(b, () -> rb.arrayOffset());
+            if (rb.hasArray()) {
+                fail("Read-only heap buffer's backing array is accessible", rb);
+            }
         }
 
         // Bulk puts from read-only buffers
@@ -969,10 +896,7 @@
         ck(b, b.toString().equals(s.substring(start, end)));
         ck(b, b.toString().equals("defghi"));
         ck(b, b.isReadOnly());
-        tryCatch(b, ReadOnlyBufferException.class, new Runnable() {
-                public void run() {
-                    b.put('x');
-                }});
+        catchReadOnlyBuffer(b, () -> b.put('x'));
         ck(b, start, b.position());
         ck(b, end, b.limit());
         ck(b, s.length(), b.capacity());
@@ -981,63 +905,25 @@
 
         // The index, relative to the position, must be non-negative and
         // smaller than remaining().
-        tryCatch(b, IndexOutOfBoundsException.class, new Runnable() {
-                public void run() {
-                    b.charAt(-1);
-                }});
-        tryCatch(b, IndexOutOfBoundsException.class, new Runnable() {
-                public void run() {
-                    b.charAt(b.remaining());
-                }});
-
+        catchIndexOutOfBounds(b, () -> b.charAt(-1));
+        catchIndexOutOfBounds(b, () -> b.charAt(b.remaining()));
         // The index must be non-negative and less than the buffer's limit.
-        tryCatch(b, IndexOutOfBoundsException.class, new Runnable() {
-                public void run() {
-                    b.get(b.limit());
-                }});
-        tryCatch(b, IndexOutOfBoundsException.class, new Runnable() {
-                public void run() {
-                    b.get(-1);
-                }});
-
+        catchIndexOutOfBounds(b, () -> b.get(b.limit()));
+        catchIndexOutOfBounds(b, () -> b.get(-1));
         // The start must be non-negative and no larger than remaining().
-        tryCatch(b, IndexOutOfBoundsException.class, new Runnable() {
-                public void run() {
-                    b.subSequence(-1, b.remaining());
-                }});
-        tryCatch(b, IndexOutOfBoundsException.class, new Runnable() {
-                public void run() {
-                    b.subSequence(b.remaining() + 1, b.remaining());
-                }});
+        catchIndexOutOfBounds(b, () -> b.subSequence(-1, b.remaining()));
+        catchIndexOutOfBounds(b, () -> b.subSequence(b.remaining() + 1, b.remaining()));
 
         // The end must be no smaller than start and no larger than
         // remaining().
-        tryCatch(b, IndexOutOfBoundsException.class, new Runnable() {
-                public void run() {
-                    b.subSequence(2, 1);
-                }});
-        tryCatch(b, IndexOutOfBoundsException.class, new Runnable() {
-                public void run() {
-                    b.subSequence(0, b.remaining() + 1);
-                }});
+        catchIndexOutOfBounds(b, () -> b.subSequence(2, 1));
+        catchIndexOutOfBounds(b, () -> b.subSequence(0, b.remaining() + 1));
 
         // The offset must be non-negative and no larger than <array.length>.
-        tryCatch(b, IndexOutOfBoundsException.class, new Runnable() {
-                public void run() {
-                    CharBuffer.wrap(s, -1, s.length());
-                }});
-        tryCatch(b, IndexOutOfBoundsException.class, new Runnable() {
-                public void run() {
-                    CharBuffer.wrap(s, s.length() + 1, s.length());
-                }});
-        tryCatch(b, IndexOutOfBoundsException.class, new Runnable() {
-                public void run() {
-                    CharBuffer.wrap(s, 1, 0);
-                }});
-        tryCatch(b, IndexOutOfBoundsException.class, new Runnable() {
-                public void run() {
-                    CharBuffer.wrap(s, 0, s.length() + 1);
-                }});
+        catchIndexOutOfBounds(b, () -> CharBuffer.wrap(s, -1, s.length()));
+        catchIndexOutOfBounds(b, () -> CharBuffer.wrap(s, s.length() + 1, s.length()));
+        catchIndexOutOfBounds(b, () -> CharBuffer.wrap(s, 1, 0));
+        catchIndexOutOfBounds(b, () -> CharBuffer.wrap(s, 0, s.length() + 1));
     }
 
 
@@ -1052,40 +938,21 @@
         ck(b, b.limit(), offset + length);
 
         // The offset must be non-negative and no larger than <array.length>.
-        tryCatch(ba, IndexOutOfBoundsException.class, new Runnable() {
-                public void run() {
-                    CharBuffer.wrap(ba, -1, ba.length);
-                }});
-        tryCatch(ba, IndexOutOfBoundsException.class, new Runnable() {
-                public void run() {
-                    CharBuffer.wrap(ba, ba.length + 1, ba.length);
-                }});
-        tryCatch(ba, IndexOutOfBoundsException.class, new Runnable() {
-                public void run() {
-                    CharBuffer.wrap(ba, 0, -1);
-                }});
-        tryCatch(ba, IndexOutOfBoundsException.class, new Runnable() {
-                public void run() {
-                    CharBuffer.wrap(ba, 0, ba.length + 1);
-                }});
+        catchIndexOutOfBounds(ba, () -> CharBuffer.wrap(ba, -1, ba.length));
+        catchIndexOutOfBounds(ba, () -> CharBuffer.wrap(ba, ba.length + 1, ba.length));
+        catchIndexOutOfBounds(ba, () -> CharBuffer.wrap(ba, 0, -1));
+        catchIndexOutOfBounds(ba, () -> CharBuffer.wrap(ba, 0, ba.length + 1));
 
         // A NullPointerException will be thrown if the array is null.
-        tryCatch(ba, NullPointerException.class, new Runnable() {
-                public void run() {
-                    CharBuffer.wrap((char []) null, 0, 5);
-                }});
-        tryCatch(ba, NullPointerException.class, new Runnable() {
-                public void run() {
-                    CharBuffer.wrap((char []) null);
-                }});
+        tryCatch(ba, NullPointerException.class,
+                () -> CharBuffer.wrap((char []) null, 0, 5));
+        tryCatch(ba, NullPointerException.class,
+                () -> CharBuffer.wrap((char []) null));
     }
 
     private static void testAllocate() {
         // An IllegalArgumentException will be thrown for negative capacities.
-        tryCatch((Buffer) null, IllegalArgumentException.class, new Runnable() {
-                public void run() {
-                    CharBuffer.allocate(-1);
-                }});
+        catchIllegalArgument((Buffer) null, () -> CharBuffer.allocate(-1));
         try {
             CharBuffer.allocate(-1);
         } catch (IllegalArgumentException e) {
@@ -1105,9 +972,6 @@
 
 
 
-
-
-
     }
 
     public static void test() {
--- a/test/java/nio/Buffer/BasicDouble.java	Mon May 16 07:01:26 2016 +0200
+++ b/test/java/nio/Buffer/BasicDouble.java	Mon May 16 09:54:01 2016 +0100
@@ -31,7 +31,6 @@
 // -- This file was mechanically generated: Do not edit! -- //
 
 import java.nio.*;
-import java.lang.reflect.Method;
 
 
 public class BasicDouble
@@ -60,7 +59,6 @@
 
     private static void relGet(DoubleBuffer b) {
         int n = b.capacity();
-        double v;
         for (int i = 0; i < n; i++)
             ck(b, (long)b.get(), (long)((double)ic(i)));
         b.rewind();
@@ -68,7 +66,6 @@
 
     private static void relGet(DoubleBuffer b, int start) {
         int n = b.remaining();
-        double v;
         for (int i = start; i < n; i++)
             ck(b, (long)b.get(), (long)((double)ic(i)));
         b.rewind();
@@ -76,7 +73,6 @@
 
     private static void absGet(DoubleBuffer b) {
         int n = b.capacity();
-        double v;
         for (int i = 0; i < n; i++)
             ck(b, (long)b.get(), (long)((double)ic(i)));
         b.rewind();
@@ -86,8 +82,9 @@
         int n = b.capacity();
         double[] a = new double[n + 7];
         b.get(a, 7, n);
-        for (int i = 0; i < n; i++)
+        for (int i = 0; i < n; i++) {
             ck(b, (long)a[i + 7], (long)((double)ic(i)));
+        }
     }
 
     private static void relPut(DoubleBuffer b) {
@@ -435,12 +432,42 @@
 
 
 
+
+
+
+
+
+
+
+
+
+
+
+
+
+
     private static void fail(String problem,
                              DoubleBuffer xb, DoubleBuffer yb,
                              double x, double y) {
         fail(problem + String.format(": x=%s y=%s", x, y), xb, yb);
     }
 
+    private static void catchIllegalArgument(Buffer b, Runnable thunk) {
+        tryCatch(b, IllegalArgumentException.class, thunk);
+    }
+
+    private static void catchReadOnlyBuffer(Buffer b, Runnable thunk) {
+        tryCatch(b, ReadOnlyBufferException.class, thunk);
+    }
+
+    private static void catchIndexOutOfBounds(Buffer b, Runnable thunk) {
+        tryCatch(b, IndexOutOfBoundsException.class, thunk);
+    }
+
+    private static void catchIndexOutOfBounds(double[] t, Runnable thunk) {
+        tryCatch(t, IndexOutOfBoundsException.class, thunk);
+    }
+
     private static void tryCatch(Buffer b, Class<?> ex, Runnable thunk) {
         boolean caught = false;
         try {
@@ -452,11 +479,12 @@
                 fail(x.getMessage() + " not expected");
             }
         }
-        if (!caught)
+        if (!caught) {
             fail(ex.getName() + " not thrown", b);
+        }
     }
 
-    private static void tryCatch(double [] t, Class<?> ex, Runnable thunk) {
+    private static void tryCatch(double[] t, Class<?> ex, Runnable thunk) {
         tryCatch(DoubleBuffer.wrap(t), ex, thunk);
     }
 
@@ -521,8 +549,6 @@
 
 
 
-
-
         // Compact
 
         relPut(b);
@@ -537,38 +563,14 @@
         b.limit(b.capacity() / 2);
         b.position(b.limit());
 
-        tryCatch(b, BufferUnderflowException.class, new Runnable() {
-                public void run() {
-                    b.get();
-                }});
-
-        tryCatch(b, BufferOverflowException.class, new Runnable() {
-                public void run() {
-                    b.put((double)42);
-                }});
-
-        // The index must be non-negative and lesss than the buffer's limit.
-        tryCatch(b, IndexOutOfBoundsException.class, new Runnable() {
-                public void run() {
-                    b.get(b.limit());
-                }});
-        tryCatch(b, IndexOutOfBoundsException.class, new Runnable() {
-                public void run() {
-                    b.get(-1);
-                }});
-
-        tryCatch(b, IndexOutOfBoundsException.class, new Runnable() {
-                public void run() {
-                    b.put(b.limit(), (double)42);
-                }});
-
-        tryCatch(b, InvalidMarkException.class, new Runnable() {
-                public void run() {
-                    b.position(0);
-                    b.mark();
-                    b.compact();
-                    b.reset();
-                }});
+        tryCatch(b, BufferUnderflowException.class, () -> b.get());
+        tryCatch(b, BufferOverflowException.class, () -> b.put((double)42));
+        // The index must be non-negative and less than the buffer's limit.
+        catchIndexOutOfBounds(b, () -> b.get(b.limit()));
+        catchIndexOutOfBounds(b, () -> b.get(-1));
+        catchIndexOutOfBounds(b, () -> b.put(b.limit(), (double)42));
+        tryCatch(b, InvalidMarkException.class,
+                () -> b.position(0).mark().compact().reset());
 
         try {
             b.position(b.limit() + 1);
@@ -635,7 +637,6 @@
         b.put(0.5121609353879392);      // Changes value if incorrectly swapped
 
 
-        double v;
         b.flip();
         ck(b, b.get(), 0);
         ck(b, b.get(), (double)-1);
@@ -654,13 +655,17 @@
 
 
 
+
+
+        double v;
         ck(b, b.get(), -Double.MAX_VALUE);
         ck(b, b.get(), -Double.MIN_VALUE);
         ck(b, b.get(), Double.NEGATIVE_INFINITY);
         ck(b, b.get(), Double.POSITIVE_INFINITY);
         if (Double.doubleToRawLongBits(v = b.get())
-            != Double.doubleToRawLongBits(Double.NaN))
+            != Double.doubleToRawLongBits(Double.NaN)) {
             fail(b, (long)Double.NaN, (long)v);
+        }
         ck(b, b.get(), 0.5121609353879392);
 
 
@@ -683,14 +688,15 @@
 
 
 
-                    )
+                    ) {
                     out.println("[" + i + "] " + x + " != " + y);
+                }
             }
             fail("Identical buffers not equal", b, b2);
         }
-        if (b.compareTo(b2) != 0)
+        if (b.compareTo(b2) != 0) {
             fail("Comparison to identical buffer != 0", b, b2);
-
+        }
         b.limit(b.limit() + 1);
         b.position(b.limit() - 1);
         b.put((double)99);
@@ -714,7 +720,7 @@
             if (xb.compareTo(xb) != 0) {
                 fail("compareTo not reflexive", xb, xb, x, x);
             }
-            if (! xb.equals(xb)) {
+            if (!xb.equals(xb)) {
                 fail("equals not reflexive", xb, xb, x, x);
             }
             for (double y : VALUES) {
@@ -765,9 +771,10 @@
 
         if (!sb.equals(sb2))
             fail("Sliced slices do not match", sb, sb2);
-        if ((sb.hasArray()) && (sb.arrayOffset() != sb2.arrayOffset()))
+        if ((sb.hasArray()) && (sb.arrayOffset() != sb2.arrayOffset())) {
             fail("Array offsets do not match: "
                  + sb.arrayOffset() + " != " + sb2.arrayOffset(), sb, sb2);
+        }
 
 
 
@@ -808,87 +815,17 @@
             fail("Buffer not equal to read-only view", b, rb);
         show(level + 1, rb);
 
-        tryCatch(b, ReadOnlyBufferException.class, new Runnable() {
-                public void run() {
-                    relPut(rb);
-                }});
-
-        tryCatch(b, ReadOnlyBufferException.class, new Runnable() {
-                public void run() {
-                    absPut(rb);
-                }});
-
-        tryCatch(b, ReadOnlyBufferException.class, new Runnable() {
-                public void run() {
-                    bulkPutArray(rb);
-                }});
-
-        tryCatch(b, ReadOnlyBufferException.class, new Runnable() {
-                public void run() {
-                    bulkPutBuffer(rb);
-                }});
+        catchReadOnlyBuffer(b, () -> relPut(rb));
+        catchReadOnlyBuffer(b, () -> absPut(rb));
+        catchReadOnlyBuffer(b, () -> bulkPutArray(rb));
+        catchReadOnlyBuffer(b, () -> bulkPutBuffer(rb));
 
         // put(DoubleBuffer) should not change source position
         final DoubleBuffer src = DoubleBuffer.allocate(1);
-        tryCatch(b, ReadOnlyBufferException.class, new Runnable() {
-                public void run() {
-                    rb.put(src);
-                 }});
+        catchReadOnlyBuffer(b, () -> rb.put(src));
         ck(src, src.position(), 0);
 
-        tryCatch(b, ReadOnlyBufferException.class, new Runnable() {
-                public void run() {
-                    rb.compact();
-                }});
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+        catchReadOnlyBuffer(b, () -> rb.compact());
 
 
 
@@ -916,21 +853,11 @@
 
 
         if (rb.getClass().getName().startsWith("java.nio.Heap")) {
-
-            tryCatch(b, ReadOnlyBufferException.class, new Runnable() {
-                    public void run() {
-                        rb.array();
-                    }});
-
-            tryCatch(b, ReadOnlyBufferException.class, new Runnable() {
-                    public void run() {
-                        rb.arrayOffset();
-                    }});
-
-            if (rb.hasArray())
-                fail("Read-only heap buffer's backing array is accessible",
-                     rb);
-
+            catchReadOnlyBuffer(b, () -> rb.array());
+            catchReadOnlyBuffer(b, () -> rb.arrayOffset());
+            if (rb.hasArray()) {
+                fail("Read-only heap buffer's backing array is accessible", rb);
+            }
         }
 
         // Bulk puts from read-only buffers
@@ -1001,47 +928,6 @@
 
 
 
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
     public static void test(final double [] ba) {
         int offset = 47;
         int length = 900;
@@ -1052,40 +938,21 @@
         ck(b, b.limit(), offset + length);
 
         // The offset must be non-negative and no larger than <array.length>.
-        tryCatch(ba, IndexOutOfBoundsException.class, new Runnable() {
-                public void run() {
-                    DoubleBuffer.wrap(ba, -1, ba.length);
-                }});
-        tryCatch(ba, IndexOutOfBoundsException.class, new Runnable() {
-                public void run() {
-                    DoubleBuffer.wrap(ba, ba.length + 1, ba.length);
-                }});
-        tryCatch(ba, IndexOutOfBoundsException.class, new Runnable() {
-                public void run() {
-                    DoubleBuffer.wrap(ba, 0, -1);
-                }});
-        tryCatch(ba, IndexOutOfBoundsException.class, new Runnable() {
-                public void run() {
-                    DoubleBuffer.wrap(ba, 0, ba.length + 1);
-                }});
+        catchIndexOutOfBounds(ba, () -> DoubleBuffer.wrap(ba, -1, ba.length));
+        catchIndexOutOfBounds(ba, () -> DoubleBuffer.wrap(ba, ba.length + 1, ba.length));
+        catchIndexOutOfBounds(ba, () -> DoubleBuffer.wrap(ba, 0, -1));
+        catchIndexOutOfBounds(ba, () -> DoubleBuffer.wrap(ba, 0, ba.length + 1));
 
         // A NullPointerException will be thrown if the array is null.
-        tryCatch(ba, NullPointerException.class, new Runnable() {
-                public void run() {
-                    DoubleBuffer.wrap((double []) null, 0, 5);
-                }});
-        tryCatch(ba, NullPointerException.class, new Runnable() {
-                public void run() {
-                    DoubleBuffer.wrap((double []) null);
-                }});
+        tryCatch(ba, NullPointerException.class,
+                () -> DoubleBuffer.wrap((double []) null, 0, 5));
+        tryCatch(ba, NullPointerException.class,
+                () -> DoubleBuffer.wrap((double []) null));
     }
 
     private static void testAllocate() {
         // An IllegalArgumentException will be thrown for negative capacities.
-        tryCatch((Buffer) null, IllegalArgumentException.class, new Runnable() {
-                public void run() {
-                    DoubleBuffer.allocate(-1);
-                }});
+        catchIllegalArgument((Buffer) null, () -> DoubleBuffer.allocate(-1));
         try {
             DoubleBuffer.allocate(-1);
         } catch (IllegalArgumentException e) {
@@ -1105,9 +972,6 @@
 
 
 
-
-
-
     }
 
     public static void test() {
--- a/test/java/nio/Buffer/BasicFloat.java	Mon May 16 07:01:26 2016 +0200
+++ b/test/java/nio/Buffer/BasicFloat.java	Mon May 16 09:54:01 2016 +0100
@@ -31,7 +31,6 @@
 // -- This file was mechanically generated: Do not edit! -- //
 
 import java.nio.*;
-import java.lang.reflect.Method;
 
 
 public class BasicFloat
@@ -60,7 +59,6 @@
 
     private static void relGet(FloatBuffer b) {
         int n = b.capacity();
-        float v;
         for (int i = 0; i < n; i++)
             ck(b, (long)b.get(), (long)((float)ic(i)));
         b.rewind();
@@ -68,7 +66,6 @@
 
     private static void relGet(FloatBuffer b, int start) {
         int n = b.remaining();
-        float v;
         for (int i = start; i < n; i++)
             ck(b, (long)b.get(), (long)((float)ic(i)));
         b.rewind();
@@ -76,7 +73,6 @@
 
     private static void absGet(FloatBuffer b) {
         int n = b.capacity();
-        float v;
         for (int i = 0; i < n; i++)
             ck(b, (long)b.get(), (long)((float)ic(i)));
         b.rewind();
@@ -86,8 +82,9 @@
         int n = b.capacity();
         float[] a = new float[n + 7];
         b.get(a, 7, n);
-        for (int i = 0; i < n; i++)
+        for (int i = 0; i < n; i++) {
             ck(b, (long)a[i + 7], (long)((float)ic(i)));
+        }
     }
 
     private static void relPut(FloatBuffer b) {
@@ -435,12 +432,42 @@
 
 
 
+
+
+
+
+
+
+
+
+
+
+
+
+
+
     private static void fail(String problem,
                              FloatBuffer xb, FloatBuffer yb,
                              float x, float y) {
         fail(problem + String.format(": x=%s y=%s", x, y), xb, yb);
     }
 
+    private static void catchIllegalArgument(Buffer b, Runnable thunk) {
+        tryCatch(b, IllegalArgumentException.class, thunk);
+    }
+
+    private static void catchReadOnlyBuffer(Buffer b, Runnable thunk) {
+        tryCatch(b, ReadOnlyBufferException.class, thunk);
+    }
+
+    private static void catchIndexOutOfBounds(Buffer b, Runnable thunk) {
+        tryCatch(b, IndexOutOfBoundsException.class, thunk);
+    }
+
+    private static void catchIndexOutOfBounds(float[] t, Runnable thunk) {
+        tryCatch(t, IndexOutOfBoundsException.class, thunk);
+    }
+
     private static void tryCatch(Buffer b, Class<?> ex, Runnable thunk) {
         boolean caught = false;
         try {
@@ -452,11 +479,12 @@
                 fail(x.getMessage() + " not expected");
             }
         }
-        if (!caught)
+        if (!caught) {
             fail(ex.getName() + " not thrown", b);
+        }
     }
 
-    private static void tryCatch(float [] t, Class<?> ex, Runnable thunk) {
+    private static void tryCatch(float[] t, Class<?> ex, Runnable thunk) {
         tryCatch(FloatBuffer.wrap(t), ex, thunk);
     }
 
@@ -521,8 +549,6 @@
 
 
 
-
-
         // Compact
 
         relPut(b);
@@ -537,38 +563,14 @@
         b.limit(b.capacity() / 2);
         b.position(b.limit());
 
-        tryCatch(b, BufferUnderflowException.class, new Runnable() {
-                public void run() {
-                    b.get();
-                }});
-
-        tryCatch(b, BufferOverflowException.class, new Runnable() {
-                public void run() {
-                    b.put((float)42);
-                }});
-
-        // The index must be non-negative and lesss than the buffer's limit.
-        tryCatch(b, IndexOutOfBoundsException.class, new Runnable() {
-                public void run() {
-                    b.get(b.limit());
-                }});
-        tryCatch(b, IndexOutOfBoundsException.class, new Runnable() {
-                public void run() {
-                    b.get(-1);
-                }});
-
-        tryCatch(b, IndexOutOfBoundsException.class, new Runnable() {
-                public void run() {
-                    b.put(b.limit(), (float)42);
-                }});
-
-        tryCatch(b, InvalidMarkException.class, new Runnable() {
-                public void run() {
-                    b.position(0);
-                    b.mark();
-                    b.compact();
-                    b.reset();
-                }});
+        tryCatch(b, BufferUnderflowException.class, () -> b.get());
+        tryCatch(b, BufferOverflowException.class, () -> b.put((float)42));
+        // The index must be non-negative and less than the buffer's limit.
+        catchIndexOutOfBounds(b, () -> b.get(b.limit()));
+        catchIndexOutOfBounds(b, () -> b.get(-1));
+        catchIndexOutOfBounds(b, () -> b.put(b.limit(), (float)42));
+        tryCatch(b, InvalidMarkException.class,
+                () -> b.position(0).mark().compact().reset());
 
         try {
             b.position(b.limit() + 1);
@@ -635,7 +637,6 @@
 
 
 
-        float v;
         b.flip();
         ck(b, b.get(), 0);
         ck(b, b.get(), (float)-1);
@@ -644,13 +645,15 @@
         ck(b, b.get(), Float.MIN_VALUE);
 
 
+        float v;
         ck(b, b.get(), -Float.MAX_VALUE);
         ck(b, b.get(), -Float.MIN_VALUE);
         ck(b, b.get(), Float.NEGATIVE_INFINITY);
         ck(b, b.get(), Float.POSITIVE_INFINITY);
         if (Float.floatToRawIntBits(v = b.get()) !=
-            Float.floatToRawIntBits(Float.NaN))
+            Float.floatToRawIntBits(Float.NaN)) {
             fail(b, (long)Float.NaN, (long)v);
+        }
         ck(b, b.get(), 0.91697687f);
 
 
@@ -665,6 +668,8 @@
 
 
 
+
+
         // Comparison
         b.rewind();
         FloatBuffer b2 = FloatBuffer.allocate(b.capacity());
@@ -683,14 +688,15 @@
 
                     || Float.compare(x, y) != 0
 
-                    )
+                    ) {
                     out.println("[" + i + "] " + x + " != " + y);
+                }
             }
             fail("Identical buffers not equal", b, b2);
         }
-        if (b.compareTo(b2) != 0)
+        if (b.compareTo(b2) != 0) {
             fail("Comparison to identical buffer != 0", b, b2);
-
+        }
         b.limit(b.limit() + 1);
         b.position(b.limit() - 1);
         b.put((float)99);
@@ -714,7 +720,7 @@
             if (xb.compareTo(xb) != 0) {
                 fail("compareTo not reflexive", xb, xb, x, x);
             }
-            if (! xb.equals(xb)) {
+            if (!xb.equals(xb)) {
                 fail("equals not reflexive", xb, xb, x, x);
             }
             for (float y : VALUES) {
@@ -765,9 +771,10 @@
 
         if (!sb.equals(sb2))
             fail("Sliced slices do not match", sb, sb2);
-        if ((sb.hasArray()) && (sb.arrayOffset() != sb2.arrayOffset()))
+        if ((sb.hasArray()) && (sb.arrayOffset() != sb2.arrayOffset())) {
             fail("Array offsets do not match: "
                  + sb.arrayOffset() + " != " + sb2.arrayOffset(), sb, sb2);
+        }
 
 
 
@@ -808,87 +815,17 @@
             fail("Buffer not equal to read-only view", b, rb);
         show(level + 1, rb);
 
-        tryCatch(b, ReadOnlyBufferException.class, new Runnable() {
-                public void run() {
-                    relPut(rb);
-                }});
-
-        tryCatch(b, ReadOnlyBufferException.class, new Runnable() {
-                public void run() {
-                    absPut(rb);
-                }});
-
-        tryCatch(b, ReadOnlyBufferException.class, new Runnable() {
-                public void run() {
-                    bulkPutArray(rb);
-                }});
-
-        tryCatch(b, ReadOnlyBufferException.class, new Runnable() {
-                public void run() {
-                    bulkPutBuffer(rb);
-                }});
+        catchReadOnlyBuffer(b, () -> relPut(rb));
+        catchReadOnlyBuffer(b, () -> absPut(rb));
+        catchReadOnlyBuffer(b, () -> bulkPutArray(rb));
+        catchReadOnlyBuffer(b, () -> bulkPutBuffer(rb));
 
         // put(FloatBuffer) should not change source position
         final FloatBuffer src = FloatBuffer.allocate(1);
-        tryCatch(b, ReadOnlyBufferException.class, new Runnable() {
-                public void run() {
-                    rb.put(src);
-                 }});
+        catchReadOnlyBuffer(b, () -> rb.put(src));
         ck(src, src.position(), 0);
 
-        tryCatch(b, ReadOnlyBufferException.class, new Runnable() {
-                public void run() {
-                    rb.compact();
-                }});
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+        catchReadOnlyBuffer(b, () -> rb.compact());
 
 
 
@@ -916,21 +853,11 @@
 
 
         if (rb.getClass().getName().startsWith("java.nio.Heap")) {
-
-            tryCatch(b, ReadOnlyBufferException.class, new Runnable() {
-                    public void run() {
-                        rb.array();
-                    }});
-
-            tryCatch(b, ReadOnlyBufferException.class, new Runnable() {
-                    public void run() {
-                        rb.arrayOffset();
-                    }});
-
-            if (rb.hasArray())
-                fail("Read-only heap buffer's backing array is accessible",
-                     rb);
-
+            catchReadOnlyBuffer(b, () -> rb.array());
+            catchReadOnlyBuffer(b, () -> rb.arrayOffset());
+            if (rb.hasArray()) {
+                fail("Read-only heap buffer's backing array is accessible", rb);
+            }
         }
 
         // Bulk puts from read-only buffers
@@ -1001,47 +928,6 @@
 
 
 
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
     public static void test(final float [] ba) {
         int offset = 47;
         int length = 900;
@@ -1052,40 +938,21 @@
         ck(b, b.limit(), offset + length);
 
         // The offset must be non-negative and no larger than <array.length>.
-        tryCatch(ba, IndexOutOfBoundsException.class, new Runnable() {
-                public void run() {
-                    FloatBuffer.wrap(ba, -1, ba.length);
-                }});
-        tryCatch(ba, IndexOutOfBoundsException.class, new Runnable() {
-                public void run() {
-                    FloatBuffer.wrap(ba, ba.length + 1, ba.length);
-                }});
-        tryCatch(ba, IndexOutOfBoundsException.class, new Runnable() {
-                public void run() {
-                    FloatBuffer.wrap(ba, 0, -1);
-                }});
-        tryCatch(ba, IndexOutOfBoundsException.class, new Runnable() {
-                public void run() {
-                    FloatBuffer.wrap(ba, 0, ba.length + 1);
-                }});
+        catchIndexOutOfBounds(ba, () -> FloatBuffer.wrap(ba, -1, ba.length));
+        catchIndexOutOfBounds(ba, () -> FloatBuffer.wrap(ba, ba.length + 1, ba.length));
+        catchIndexOutOfBounds(ba, () -> FloatBuffer.wrap(ba, 0, -1));
+        catchIndexOutOfBounds(ba, () -> FloatBuffer.wrap(ba, 0, ba.length + 1));
 
         // A NullPointerException will be thrown if the array is null.
-        tryCatch(ba, NullPointerException.class, new Runnable() {
-                public void run() {
-                    FloatBuffer.wrap((float []) null, 0, 5);
-                }});
-        tryCatch(ba, NullPointerException.class, new Runnable() {
-                public void run() {
-                    FloatBuffer.wrap((float []) null);
-                }});
+        tryCatch(ba, NullPointerException.class,
+                () -> FloatBuffer.wrap((float []) null, 0, 5));
+        tryCatch(ba, NullPointerException.class,
+                () -> FloatBuffer.wrap((float []) null));
     }
 
     private static void testAllocate() {
         // An IllegalArgumentException will be thrown for negative capacities.
-        tryCatch((Buffer) null, IllegalArgumentException.class, new Runnable() {
-                public void run() {
-                    FloatBuffer.allocate(-1);
-                }});
+        catchIllegalArgument((Buffer) null, () -> FloatBuffer.allocate(-1));
         try {
             FloatBuffer.allocate(-1);
         } catch (IllegalArgumentException e) {
@@ -1105,9 +972,6 @@
 
 
 
-
-
-
     }
 
     public static void test() {
--- a/test/java/nio/Buffer/BasicInt.java	Mon May 16 07:01:26 2016 +0200
+++ b/test/java/nio/Buffer/BasicInt.java	Mon May 16 09:54:01 2016 +0100
@@ -31,7 +31,6 @@
 // -- This file was mechanically generated: Do not edit! -- //
 
 import java.nio.*;
-import java.lang.reflect.Method;
 
 
 public class BasicInt
@@ -60,7 +59,6 @@
 
     private static void relGet(IntBuffer b) {
         int n = b.capacity();
-        int v;
         for (int i = 0; i < n; i++)
             ck(b, (long)b.get(), (long)((int)ic(i)));
         b.rewind();
@@ -68,7 +66,6 @@
 
     private static void relGet(IntBuffer b, int start) {
         int n = b.remaining();
-        int v;
         for (int i = start; i < n; i++)
             ck(b, (long)b.get(), (long)((int)ic(i)));
         b.rewind();
@@ -76,7 +73,6 @@
 
     private static void absGet(IntBuffer b) {
         int n = b.capacity();
-        int v;
         for (int i = 0; i < n; i++)
             ck(b, (long)b.get(), (long)((int)ic(i)));
         b.rewind();
@@ -86,8 +82,9 @@
         int n = b.capacity();
         int[] a = new int[n + 7];
         b.get(a, 7, n);
-        for (int i = 0; i < n; i++)
+        for (int i = 0; i < n; i++) {
             ck(b, (long)a[i + 7], (long)((int)ic(i)));
+        }
     }
 
     private static void relPut(IntBuffer b) {
@@ -435,12 +432,42 @@
 
 
 
+
+
+
+
+
+
+
+
+
+
+
+
+
+
     private static void fail(String problem,
                              IntBuffer xb, IntBuffer yb,
                              int x, int y) {
         fail(problem + String.format(": x=%s y=%s", x, y), xb, yb);
     }
 
+    private static void catchIllegalArgument(Buffer b, Runnable thunk) {
+        tryCatch(b, IllegalArgumentException.class, thunk);
+    }
+
+    private static void catchReadOnlyBuffer(Buffer b, Runnable thunk) {
+        tryCatch(b, ReadOnlyBufferException.class, thunk);
+    }
+
+    private static void catchIndexOutOfBounds(Buffer b, Runnable thunk) {
+        tryCatch(b, IndexOutOfBoundsException.class, thunk);
+    }
+
+    private static void catchIndexOutOfBounds(int[] t, Runnable thunk) {
+        tryCatch(t, IndexOutOfBoundsException.class, thunk);
+    }
+
     private static void tryCatch(Buffer b, Class<?> ex, Runnable thunk) {
         boolean caught = false;
         try {
@@ -452,11 +479,12 @@
                 fail(x.getMessage() + " not expected");
             }
         }
-        if (!caught)
+        if (!caught) {
             fail(ex.getName() + " not thrown", b);
+        }
     }
 
-    private static void tryCatch(int [] t, Class<?> ex, Runnable thunk) {
+    private static void tryCatch(int[] t, Class<?> ex, Runnable thunk) {
         tryCatch(IntBuffer.wrap(t), ex, thunk);
     }
 
@@ -521,8 +549,6 @@
 
 
 
-
-
         // Compact
 
         relPut(b);
@@ -537,38 +563,14 @@
         b.limit(b.capacity() / 2);
         b.position(b.limit());
 
-        tryCatch(b, BufferUnderflowException.class, new Runnable() {
-                public void run() {
-                    b.get();
-                }});
-
-        tryCatch(b, BufferOverflowException.class, new Runnable() {
-                public void run() {
-                    b.put((int)42);
-                }});
-
-        // The index must be non-negative and lesss than the buffer's limit.
-        tryCatch(b, IndexOutOfBoundsException.class, new Runnable() {
-                public void run() {
-                    b.get(b.limit());
-                }});
-        tryCatch(b, IndexOutOfBoundsException.class, new Runnable() {
-                public void run() {
-                    b.get(-1);
-                }});
-
-        tryCatch(b, IndexOutOfBoundsException.class, new Runnable() {
-                public void run() {
-                    b.put(b.limit(), (int)42);
-                }});
-
-        tryCatch(b, InvalidMarkException.class, new Runnable() {
-                public void run() {
-                    b.position(0);
-                    b.mark();
-                    b.compact();
-                    b.reset();
-                }});
+        tryCatch(b, BufferUnderflowException.class, () -> b.get());
+        tryCatch(b, BufferOverflowException.class, () -> b.put((int)42));
+        // The index must be non-negative and less than the buffer's limit.
+        catchIndexOutOfBounds(b, () -> b.get(b.limit()));
+        catchIndexOutOfBounds(b, () -> b.get(-1));
+        catchIndexOutOfBounds(b, () -> b.put(b.limit(), (int)42));
+        tryCatch(b, InvalidMarkException.class,
+                () -> b.position(0).mark().compact().reset());
 
         try {
             b.position(b.limit() + 1);
@@ -635,7 +637,6 @@
 
 
 
-        int v;
         b.flip();
         ck(b, b.get(), 0);
         ck(b, b.get(), (int)-1);
@@ -665,6 +666,10 @@
 
 
 
+
+
+
+
         // Comparison
         b.rewind();
         IntBuffer b2 = IntBuffer.allocate(b.capacity());
@@ -683,14 +688,15 @@
 
 
 
-                    )
+                    ) {
                     out.println("[" + i + "] " + x + " != " + y);
+                }
             }
             fail("Identical buffers not equal", b, b2);
         }
-        if (b.compareTo(b2) != 0)
+        if (b.compareTo(b2) != 0) {
             fail("Comparison to identical buffer != 0", b, b2);
-
+        }
         b.limit(b.limit() + 1);
         b.position(b.limit() - 1);
         b.put((int)99);
@@ -714,7 +720,7 @@
             if (xb.compareTo(xb) != 0) {
                 fail("compareTo not reflexive", xb, xb, x, x);
             }
-            if (! xb.equals(xb)) {
+            if (!xb.equals(xb)) {
                 fail("equals not reflexive", xb, xb, x, x);
             }
             for (int y : VALUES) {
@@ -765,9 +771,10 @@
 
         if (!sb.equals(sb2))
             fail("Sliced slices do not match", sb, sb2);
-        if ((sb.hasArray()) && (sb.arrayOffset() != sb2.arrayOffset()))
+        if ((sb.hasArray()) && (sb.arrayOffset() != sb2.arrayOffset())) {
             fail("Array offsets do not match: "
                  + sb.arrayOffset() + " != " + sb2.arrayOffset(), sb, sb2);
+        }
 
 
 
@@ -808,87 +815,17 @@
             fail("Buffer not equal to read-only view", b, rb);
         show(level + 1, rb);
 
-        tryCatch(b, ReadOnlyBufferException.class, new Runnable() {
-                public void run() {
-                    relPut(rb);
-                }});
-
-        tryCatch(b, ReadOnlyBufferException.class, new Runnable() {
-                public void run() {
-                    absPut(rb);
-                }});
-
-        tryCatch(b, ReadOnlyBufferException.class, new Runnable() {
-                public void run() {
-                    bulkPutArray(rb);
-                }});
-
-        tryCatch(b, ReadOnlyBufferException.class, new Runnable() {
-                public void run() {
-                    bulkPutBuffer(rb);
-                }});
+        catchReadOnlyBuffer(b, () -> relPut(rb));
+        catchReadOnlyBuffer(b, () -> absPut(rb));
+        catchReadOnlyBuffer(b, () -> bulkPutArray(rb));
+        catchReadOnlyBuffer(b, () -> bulkPutBuffer(rb));
 
         // put(IntBuffer) should not change source position
         final IntBuffer src = IntBuffer.allocate(1);
-        tryCatch(b, ReadOnlyBufferException.class, new Runnable() {
-                public void run() {
-                    rb.put(src);
-                 }});
+        catchReadOnlyBuffer(b, () -> rb.put(src));
         ck(src, src.position(), 0);
 
-        tryCatch(b, ReadOnlyBufferException.class, new Runnable() {
-                public void run() {
-                    rb.compact();
-                }});
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+        catchReadOnlyBuffer(b, () -> rb.compact());
 
 
 
@@ -916,21 +853,11 @@
 
 
         if (rb.getClass().getName().startsWith("java.nio.Heap")) {
-
-            tryCatch(b, ReadOnlyBufferException.class, new Runnable() {
-                    public void run() {
-                        rb.array();
-                    }});
-
-            tryCatch(b, ReadOnlyBufferException.class, new Runnable() {
-                    public void run() {
-                        rb.arrayOffset();
-                    }});
-
-            if (rb.hasArray())
-                fail("Read-only heap buffer's backing array is accessible",
-                     rb);
-
+            catchReadOnlyBuffer(b, () -> rb.array());
+            catchReadOnlyBuffer(b, () -> rb.arrayOffset());
+            if (rb.hasArray()) {
+                fail("Read-only heap buffer's backing array is accessible", rb);
+            }
         }
 
         // Bulk puts from read-only buffers
@@ -1001,47 +928,6 @@
 
 
 
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
     public static void test(final int [] ba) {
         int offset = 47;
         int length = 900;
@@ -1052,40 +938,21 @@
         ck(b, b.limit(), offset + length);
 
         // The offset must be non-negative and no larger than <array.length>.
-        tryCatch(ba, IndexOutOfBoundsException.class, new Runnable() {
-                public void run() {
-                    IntBuffer.wrap(ba, -1, ba.length);
-                }});
-        tryCatch(ba, IndexOutOfBoundsException.class, new Runnable() {
-                public void run() {
-                    IntBuffer.wrap(ba, ba.length + 1, ba.length);
-                }});
-        tryCatch(ba, IndexOutOfBoundsException.class, new Runnable() {
-                public void run() {
-                    IntBuffer.wrap(ba, 0, -1);
-                }});
-        tryCatch(ba, IndexOutOfBoundsException.class, new Runnable() {
-                public void run() {
-                    IntBuffer.wrap(ba, 0, ba.length + 1);
-                }});
+        catchIndexOutOfBounds(ba, () -> IntBuffer.wrap(ba, -1, ba.length));
+        catchIndexOutOfBounds(ba, () -> IntBuffer.wrap(ba, ba.length + 1, ba.length));
+        catchIndexOutOfBounds(ba, () -> IntBuffer.wrap(ba, 0, -1));
+        catchIndexOutOfBounds(ba, () -> IntBuffer.wrap(ba, 0, ba.length + 1));
 
         // A NullPointerException will be thrown if the array is null.
-        tryCatch(ba, NullPointerException.class, new Runnable() {
-                public void run() {
-                    IntBuffer.wrap((int []) null, 0, 5);
-                }});
-        tryCatch(ba, NullPointerException.class, new Runnable() {
-                public void run() {
-                    IntBuffer.wrap((int []) null);
-                }});
+        tryCatch(ba, NullPointerException.class,
+                () -> IntBuffer.wrap((int []) null, 0, 5));
+        tryCatch(ba, NullPointerException.class,
+                () -> IntBuffer.wrap((int []) null));
     }
 
     private static void testAllocate() {
         // An IllegalArgumentException will be thrown for negative capacities.
-        tryCatch((Buffer) null, IllegalArgumentException.class, new Runnable() {
-                public void run() {
-                    IntBuffer.allocate(-1);
-                }});
+        catchIllegalArgument((Buffer) null, () -> IntBuffer.allocate(-1));
         try {
             IntBuffer.allocate(-1);
         } catch (IllegalArgumentException e) {
@@ -1105,9 +972,6 @@
 
 
 
-
-
-
     }
 
     public static void test() {
--- a/test/java/nio/Buffer/BasicLong.java	Mon May 16 07:01:26 2016 +0200
+++ b/test/java/nio/Buffer/BasicLong.java	Mon May 16 09:54:01 2016 +0100
@@ -31,7 +31,6 @@
 // -- This file was mechanically generated: Do not edit! -- //
 
 import java.nio.*;
-import java.lang.reflect.Method;
 
 
 public class BasicLong
@@ -60,7 +59,6 @@
 
     private static void relGet(LongBuffer b) {
         int n = b.capacity();
-        long v;
         for (int i = 0; i < n; i++)
             ck(b, (long)b.get(), (long)((long)ic(i)));
         b.rewind();
@@ -68,7 +66,6 @@
 
     private static void relGet(LongBuffer b, int start) {
         int n = b.remaining();
-        long v;
         for (int i = start; i < n; i++)
             ck(b, (long)b.get(), (long)((long)ic(i)));
         b.rewind();
@@ -76,7 +73,6 @@
 
     private static void absGet(LongBuffer b) {
         int n = b.capacity();
-        long v;
         for (int i = 0; i < n; i++)
             ck(b, (long)b.get(), (long)((long)ic(i)));
         b.rewind();
@@ -86,8 +82,9 @@
         int n = b.capacity();
         long[] a = new long[n + 7];
         b.get(a, 7, n);
-        for (int i = 0; i < n; i++)
+        for (int i = 0; i < n; i++) {
             ck(b, (long)a[i + 7], (long)((long)ic(i)));
+        }
     }
 
     private static void relPut(LongBuffer b) {
@@ -435,12 +432,42 @@
 
 
 
+
+
+
+
+
+
+
+
+
+
+
+
+
+
     private static void fail(String problem,
                              LongBuffer xb, LongBuffer yb,
                              long x, long y) {
         fail(problem + String.format(": x=%s y=%s", x, y), xb, yb);
     }
 
+    private static void catchIllegalArgument(Buffer b, Runnable thunk) {
+        tryCatch(b, IllegalArgumentException.class, thunk);
+    }
+
+    private static void catchReadOnlyBuffer(Buffer b, Runnable thunk) {
+        tryCatch(b, ReadOnlyBufferException.class, thunk);
+    }
+
+    private static void catchIndexOutOfBounds(Buffer b, Runnable thunk) {
+        tryCatch(b, IndexOutOfBoundsException.class, thunk);
+    }
+
+    private static void catchIndexOutOfBounds(long[] t, Runnable thunk) {
+        tryCatch(t, IndexOutOfBoundsException.class, thunk);
+    }
+
     private static void tryCatch(Buffer b, Class<?> ex, Runnable thunk) {
         boolean caught = false;
         try {
@@ -452,11 +479,12 @@
                 fail(x.getMessage() + " not expected");
             }
         }
-        if (!caught)
+        if (!caught) {
             fail(ex.getName() + " not thrown", b);
+        }
     }
 
-    private static void tryCatch(long [] t, Class<?> ex, Runnable thunk) {
+    private static void tryCatch(long[] t, Class<?> ex, Runnable thunk) {
         tryCatch(LongBuffer.wrap(t), ex, thunk);
     }
 
@@ -521,8 +549,6 @@
 
 
 
-
-
         // Compact
 
         relPut(b);
@@ -537,38 +563,14 @@
         b.limit(b.capacity() / 2);
         b.position(b.limit());
 
-        tryCatch(b, BufferUnderflowException.class, new Runnable() {
-                public void run() {
-                    b.get();
-                }});
-
-        tryCatch(b, BufferOverflowException.class, new Runnable() {
-                public void run() {
-                    b.put((long)42);
-                }});
-
-        // The index must be non-negative and lesss than the buffer's limit.
-        tryCatch(b, IndexOutOfBoundsException.class, new Runnable() {
-                public void run() {
-                    b.get(b.limit());
-                }});
-        tryCatch(b, IndexOutOfBoundsException.class, new Runnable() {
-                public void run() {
-                    b.get(-1);
-                }});
-
-        tryCatch(b, IndexOutOfBoundsException.class, new Runnable() {
-                public void run() {
-                    b.put(b.limit(), (long)42);
-                }});
-
-        tryCatch(b, InvalidMarkException.class, new Runnable() {
-                public void run() {
-                    b.position(0);
-                    b.mark();
-                    b.compact();
-                    b.reset();
-                }});
+        tryCatch(b, BufferUnderflowException.class, () -> b.get());
+        tryCatch(b, BufferOverflowException.class, () -> b.put((long)42));
+        // The index must be non-negative and less than the buffer's limit.
+        catchIndexOutOfBounds(b, () -> b.get(b.limit()));
+        catchIndexOutOfBounds(b, () -> b.get(-1));
+        catchIndexOutOfBounds(b, () -> b.put(b.limit(), (long)42));
+        tryCatch(b, InvalidMarkException.class,
+                () -> b.position(0).mark().compact().reset());
 
         try {
             b.position(b.limit() + 1);
@@ -635,7 +637,6 @@
 
 
 
-        long v;
         b.flip();
         ck(b, b.get(), 0);
         ck(b, b.get(), (long)-1);
@@ -665,6 +666,10 @@
 
 
 
+
+
+
+
         // Comparison
         b.rewind();
         LongBuffer b2 = LongBuffer.allocate(b.capacity());
@@ -683,14 +688,15 @@
 
 
 
-                    )
+                    ) {
                     out.println("[" + i + "] " + x + " != " + y);
+                }
             }
             fail("Identical buffers not equal", b, b2);
         }
-        if (b.compareTo(b2) != 0)
+        if (b.compareTo(b2) != 0) {
             fail("Comparison to identical buffer != 0", b, b2);
-
+        }
         b.limit(b.limit() + 1);
         b.position(b.limit() - 1);
         b.put((long)99);
@@ -714,7 +720,7 @@
             if (xb.compareTo(xb) != 0) {
                 fail("compareTo not reflexive", xb, xb, x, x);
             }
-            if (! xb.equals(xb)) {
+            if (!xb.equals(xb)) {
                 fail("equals not reflexive", xb, xb, x, x);
             }
             for (long y : VALUES) {
@@ -765,9 +771,10 @@
 
         if (!sb.equals(sb2))
             fail("Sliced slices do not match", sb, sb2);
-        if ((sb.hasArray()) && (sb.arrayOffset() != sb2.arrayOffset()))
+        if ((sb.hasArray()) && (sb.arrayOffset() != sb2.arrayOffset())) {
             fail("Array offsets do not match: "
                  + sb.arrayOffset() + " != " + sb2.arrayOffset(), sb, sb2);
+        }
 
 
 
@@ -808,87 +815,17 @@
             fail("Buffer not equal to read-only view", b, rb);
         show(level + 1, rb);
 
-        tryCatch(b, ReadOnlyBufferException.class, new Runnable() {
-                public void run() {
-                    relPut(rb);
-                }});
-
-        tryCatch(b, ReadOnlyBufferException.class, new Runnable() {
-                public void run() {
-                    absPut(rb);
-                }});
-
-        tryCatch(b, ReadOnlyBufferException.class, new Runnable() {
-                public void run() {
-                    bulkPutArray(rb);
-                }});
-
-        tryCatch(b, ReadOnlyBufferException.class, new Runnable() {
-                public void run() {
-                    bulkPutBuffer(rb);
-                }});
+        catchReadOnlyBuffer(b, () -> relPut(rb));
+        catchReadOnlyBuffer(b, () -> absPut(rb));
+        catchReadOnlyBuffer(b, () -> bulkPutArray(rb));
+        catchReadOnlyBuffer(b, () -> bulkPutBuffer(rb));
 
         // put(LongBuffer) should not change source position
         final LongBuffer src = LongBuffer.allocate(1);
-        tryCatch(b, ReadOnlyBufferException.class, new Runnable() {
-                public void run() {
-                    rb.put(src);
-                 }});
+        catchReadOnlyBuffer(b, () -> rb.put(src));
         ck(src, src.position(), 0);
 
-        tryCatch(b, ReadOnlyBufferException.class, new Runnable() {
-                public void run() {
-                    rb.compact();
-                }});
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+        catchReadOnlyBuffer(b, () -> rb.compact());
 
 
 
@@ -916,21 +853,11 @@
 
 
         if (rb.getClass().getName().startsWith("java.nio.Heap")) {
-
-            tryCatch(b, ReadOnlyBufferException.class, new Runnable() {
-                    public void run() {
-                        rb.array();
-                    }});
-
-            tryCatch(b, ReadOnlyBufferException.class, new Runnable() {
-                    public void run() {
-                        rb.arrayOffset();
-                    }});
-
-            if (rb.hasArray())
-                fail("Read-only heap buffer's backing array is accessible",
-                     rb);
-
+            catchReadOnlyBuffer(b, () -> rb.array());
+            catchReadOnlyBuffer(b, () -> rb.arrayOffset());
+            if (rb.hasArray()) {
+                fail("Read-only heap buffer's backing array is accessible", rb);
+            }
         }
 
         // Bulk puts from read-only buffers
@@ -1001,47 +928,6 @@
 
 
 
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
     public static void test(final long [] ba) {
         int offset = 47;
         int length = 900;
@@ -1052,40 +938,21 @@
         ck(b, b.limit(), offset + length);
 
         // The offset must be non-negative and no larger than <array.length>.
-        tryCatch(ba, IndexOutOfBoundsException.class, new Runnable() {
-                public void run() {
-                    LongBuffer.wrap(ba, -1, ba.length);
-                }});
-        tryCatch(ba, IndexOutOfBoundsException.class, new Runnable() {
-                public void run() {
-                    LongBuffer.wrap(ba, ba.length + 1, ba.length);
-                }});
-        tryCatch(ba, IndexOutOfBoundsException.class, new Runnable() {
-                public void run() {
-                    LongBuffer.wrap(ba, 0, -1);
-                }});
-        tryCatch(ba, IndexOutOfBoundsException.class, new Runnable() {
-                public void run() {
-                    LongBuffer.wrap(ba, 0, ba.length + 1);
-                }});
+        catchIndexOutOfBounds(ba, () -> LongBuffer.wrap(ba, -1, ba.length));
+        catchIndexOutOfBounds(ba, () -> LongBuffer.wrap(ba, ba.length + 1, ba.length));
+        catchIndexOutOfBounds(ba, () -> LongBuffer.wrap(ba, 0, -1));
+        catchIndexOutOfBounds(ba, () -> LongBuffer.wrap(ba, 0, ba.length + 1));
 
         // A NullPointerException will be thrown if the array is null.
-        tryCatch(ba, NullPointerException.class, new Runnable() {
-                public void run() {
-                    LongBuffer.wrap((long []) null, 0, 5);
-                }});
-        tryCatch(ba, NullPointerException.class, new Runnable() {
-                public void run() {
-                    LongBuffer.wrap((long []) null);
-                }});
+        tryCatch(ba, NullPointerException.class,
+                () -> LongBuffer.wrap((long []) null, 0, 5));
+        tryCatch(ba, NullPointerException.class,
+                () -> LongBuffer.wrap((long []) null));
     }
 
     private static void testAllocate() {
         // An IllegalArgumentException will be thrown for negative capacities.
-        tryCatch((Buffer) null, IllegalArgumentException.class, new Runnable() {
-                public void run() {
-                    LongBuffer.allocate(-1);
-                }});
+        catchIllegalArgument((Buffer) null, () -> LongBuffer.allocate(-1));
         try {
             LongBuffer.allocate(-1);
         } catch (IllegalArgumentException e) {
@@ -1105,9 +972,6 @@
 
 
 
-
-
-
     }
 
     public static void test() {
--- a/test/java/nio/Buffer/BasicShort.java	Mon May 16 07:01:26 2016 +0200
+++ b/test/java/nio/Buffer/BasicShort.java	Mon May 16 09:54:01 2016 +0100
@@ -31,7 +31,6 @@
 // -- This file was mechanically generated: Do not edit! -- //
 
 import java.nio.*;
-import java.lang.reflect.Method;
 
 
 public class BasicShort
@@ -60,7 +59,6 @@
 
     private static void relGet(ShortBuffer b) {
         int n = b.capacity();
-        short v;
         for (int i = 0; i < n; i++)
             ck(b, (long)b.get(), (long)((short)ic(i)));
         b.rewind();
@@ -68,7 +66,6 @@
 
     private static void relGet(ShortBuffer b, int start) {
         int n = b.remaining();
-        short v;
         for (int i = start; i < n; i++)
             ck(b, (long)b.get(), (long)((short)ic(i)));
         b.rewind();
@@ -76,7 +73,6 @@
 
     private static void absGet(ShortBuffer b) {
         int n = b.capacity();
-        short v;
         for (int i = 0; i < n; i++)
             ck(b, (long)b.get(), (long)((short)ic(i)));
         b.rewind();
@@ -86,8 +82,9 @@
         int n = b.capacity();
         short[] a = new short[n + 7];
         b.get(a, 7, n);
-        for (int i = 0; i < n; i++)
+        for (int i = 0; i < n; i++) {
             ck(b, (long)a[i + 7], (long)((short)ic(i)));
+        }
     }
 
     private static void relPut(ShortBuffer b) {
@@ -435,12 +432,42 @@
 
 
 
+
+
+
+
+
+
+
+
+
+
+
+
+
+
     private static void fail(String problem,
                              ShortBuffer xb, ShortBuffer yb,
                              short x, short y) {
         fail(problem + String.format(": x=%s y=%s", x, y), xb, yb);
     }
 
+    private static void catchIllegalArgument(Buffer b, Runnable thunk) {
+        tryCatch(b, IllegalArgumentException.class, thunk);
+    }
+
+    private static void catchReadOnlyBuffer(Buffer b, Runnable thunk) {
+        tryCatch(b, ReadOnlyBufferException.class, thunk);
+    }
+
+    private static void catchIndexOutOfBounds(Buffer b, Runnable thunk) {
+        tryCatch(b, IndexOutOfBoundsException.class, thunk);
+    }
+
+    private static void catchIndexOutOfBounds(short[] t, Runnable thunk) {
+        tryCatch(t, IndexOutOfBoundsException.class, thunk);
+    }
+
     private static void tryCatch(Buffer b, Class<?> ex, Runnable thunk) {
         boolean caught = false;
         try {
@@ -452,11 +479,12 @@
                 fail(x.getMessage() + " not expected");
             }
         }
-        if (!caught)
+        if (!caught) {
             fail(ex.getName() + " not thrown", b);
+        }
     }
 
-    private static void tryCatch(short [] t, Class<?> ex, Runnable thunk) {
+    private static void tryCatch(short[] t, Class<?> ex, Runnable thunk) {
         tryCatch(ShortBuffer.wrap(t), ex, thunk);
     }
 
@@ -521,8 +549,6 @@
 
 
 
-
-
         // Compact
 
         relPut(b);
@@ -537,38 +563,14 @@
         b.limit(b.capacity() / 2);
         b.position(b.limit());
 
-        tryCatch(b, BufferUnderflowException.class, new Runnable() {
-                public void run() {
-                    b.get();
-                }});
-
-        tryCatch(b, BufferOverflowException.class, new Runnable() {
-                public void run() {
-                    b.put((short)42);
-                }});
-
-        // The index must be non-negative and lesss than the buffer's limit.
-        tryCatch(b, IndexOutOfBoundsException.class, new Runnable() {
-                public void run() {
-                    b.get(b.limit());
-                }});
-        tryCatch(b, IndexOutOfBoundsException.class, new Runnable() {
-                public void run() {
-                    b.get(-1);
-                }});
-
-        tryCatch(b, IndexOutOfBoundsException.class, new Runnable() {
-                public void run() {
-                    b.put(b.limit(), (short)42);
-                }});
-
-        tryCatch(b, InvalidMarkException.class, new Runnable() {
-                public void run() {
-                    b.position(0);
-                    b.mark();
-                    b.compact();
-                    b.reset();
-                }});
+        tryCatch(b, BufferUnderflowException.class, () -> b.get());
+        tryCatch(b, BufferOverflowException.class, () -> b.put((short)42));
+        // The index must be non-negative and less than the buffer's limit.
+        catchIndexOutOfBounds(b, () -> b.get(b.limit()));
+        catchIndexOutOfBounds(b, () -> b.get(-1));
+        catchIndexOutOfBounds(b, () -> b.put(b.limit(), (short)42));
+        tryCatch(b, InvalidMarkException.class,
+                () -> b.position(0).mark().compact().reset());
 
         try {
             b.position(b.limit() + 1);
@@ -635,7 +637,6 @@
 
 
 
-        short v;
         b.flip();
         ck(b, b.get(), 0);
         ck(b, b.get(), (short)-1);
@@ -665,6 +666,10 @@
 
 
 
+
+
+
+
         // Comparison
         b.rewind();
         ShortBuffer b2 = ShortBuffer.allocate(b.capacity());
@@ -683,14 +688,15 @@
 
 
 
-                    )
+                    ) {
                     out.println("[" + i + "] " + x + " != " + y);
+                }
             }
             fail("Identical buffers not equal", b, b2);
         }
-        if (b.compareTo(b2) != 0)
+        if (b.compareTo(b2) != 0) {
             fail("Comparison to identical buffer != 0", b, b2);
-
+        }
         b.limit(b.limit() + 1);
         b.position(b.limit() - 1);
         b.put((short)99);
@@ -714,7 +720,7 @@
             if (xb.compareTo(xb) != 0) {
                 fail("compareTo not reflexive", xb, xb, x, x);
             }
-            if (! xb.equals(xb)) {
+            if (!xb.equals(xb)) {
                 fail("equals not reflexive", xb, xb, x, x);
             }
             for (short y : VALUES) {
@@ -765,9 +771,10 @@
 
         if (!sb.equals(sb2))
             fail("Sliced slices do not match", sb, sb2);
-        if ((sb.hasArray()) && (sb.arrayOffset() != sb2.arrayOffset()))
+        if ((sb.hasArray()) && (sb.arrayOffset() != sb2.arrayOffset())) {
             fail("Array offsets do not match: "
                  + sb.arrayOffset() + " != " + sb2.arrayOffset(), sb, sb2);
+        }
 
 
 
@@ -808,87 +815,17 @@
             fail("Buffer not equal to read-only view", b, rb);
         show(level + 1, rb);
 
-        tryCatch(b, ReadOnlyBufferException.class, new Runnable() {
-                public void run() {
-                    relPut(rb);
-                }});
-
-        tryCatch(b, ReadOnlyBufferException.class, new Runnable() {
-                public void run() {
-                    absPut(rb);
-                }});
-
-        tryCatch(b, ReadOnlyBufferException.class, new Runnable() {
-                public void run() {
-                    bulkPutArray(rb);
-                }});
-
-        tryCatch(b, ReadOnlyBufferException.class, new Runnable() {
-                public void run() {
-                    bulkPutBuffer(rb);
-                }});
+        catchReadOnlyBuffer(b, () -> relPut(rb));
+        catchReadOnlyBuffer(b, () -> absPut(rb));
+        catchReadOnlyBuffer(b, () -> bulkPutArray(rb));
+        catchReadOnlyBuffer(b, () -> bulkPutBuffer(rb));
 
         // put(ShortBuffer) should not change source position
         final ShortBuffer src = ShortBuffer.allocate(1);
-        tryCatch(b, ReadOnlyBufferException.class, new Runnable() {
-                public void run() {
-                    rb.put(src);
-                 }});
+        catchReadOnlyBuffer(b, () -> rb.put(src));
         ck(src, src.position(), 0);
 
-        tryCatch(b, ReadOnlyBufferException.class, new Runnable() {
-                public void run() {
-                    rb.compact();
-                }});
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+        catchReadOnlyBuffer(b, () -> rb.compact());
 
 
 
@@ -916,21 +853,11 @@
 
 
         if (rb.getClass().getName().startsWith("java.nio.Heap")) {
-
-            tryCatch(b, ReadOnlyBufferException.class, new Runnable() {
-                    public void run() {
-                        rb.array();
-                    }});
-
-            tryCatch(b, ReadOnlyBufferException.class, new Runnable() {
-                    public void run() {
-                        rb.arrayOffset();
-                    }});
-
-            if (rb.hasArray())
-                fail("Read-only heap buffer's backing array is accessible",
-                     rb);
-
+            catchReadOnlyBuffer(b, () -> rb.array());
+            catchReadOnlyBuffer(b, () -> rb.arrayOffset());
+            if (rb.hasArray()) {
+                fail("Read-only heap buffer's backing array is accessible", rb);
+            }
         }
 
         // Bulk puts from read-only buffers
@@ -1001,47 +928,6 @@
 
 
 
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
     public static void test(final short [] ba) {
         int offset = 47;
         int length = 900;
@@ -1052,40 +938,21 @@
         ck(b, b.limit(), offset + length);
 
         // The offset must be non-negative and no larger than <array.length>.
-        tryCatch(ba, IndexOutOfBoundsException.class, new Runnable() {
-                public void run() {
-                    ShortBuffer.wrap(ba, -1, ba.length);
-                }});
-        tryCatch(ba, IndexOutOfBoundsException.class, new Runnable() {
-                public void run() {
-                    ShortBuffer.wrap(ba, ba.length + 1, ba.length);
-                }});
-        tryCatch(ba, IndexOutOfBoundsException.class, new Runnable() {
-                public void run() {
-                    ShortBuffer.wrap(ba, 0, -1);
-                }});
-        tryCatch(ba, IndexOutOfBoundsException.class, new Runnable() {
-                public void run() {
-                    ShortBuffer.wrap(ba, 0, ba.length + 1);
-                }});
+        catchIndexOutOfBounds(ba, () -> ShortBuffer.wrap(ba, -1, ba.length));
+        catchIndexOutOfBounds(ba, () -> ShortBuffer.wrap(ba, ba.length + 1, ba.length));
+        catchIndexOutOfBounds(ba, () -> ShortBuffer.wrap(ba, 0, -1));
+        catchIndexOutOfBounds(ba, () -> ShortBuffer.wrap(ba, 0, ba.length + 1));
 
         // A NullPointerException will be thrown if the array is null.
-        tryCatch(ba, NullPointerException.class, new Runnable() {
-                public void run() {
-                    ShortBuffer.wrap((short []) null, 0, 5);
-                }});
-        tryCatch(ba, NullPointerException.class, new Runnable() {
-                public void run() {
-                    ShortBuffer.wrap((short []) null);
-                }});
+        tryCatch(ba, NullPointerException.class,
+                () -> ShortBuffer.wrap((short []) null, 0, 5));
+        tryCatch(ba, NullPointerException.class,
+                () -> ShortBuffer.wrap((short []) null));
     }
 
     private static void testAllocate() {
         // An IllegalArgumentException will be thrown for negative capacities.
-        tryCatch((Buffer) null, IllegalArgumentException.class, new Runnable() {
-                public void run() {
-                    ShortBuffer.allocate(-1);
-                }});
+        catchIllegalArgument((Buffer) null, () -> ShortBuffer.allocate(-1));
         try {
             ShortBuffer.allocate(-1);
         } catch (IllegalArgumentException e) {
@@ -1105,9 +972,6 @@
 
 
 
-
-
-
     }
 
     public static void test() {
--- a/test/java/nio/Buffer/LimitDirectMemory.java	Mon May 16 07:01:26 2016 +0200
+++ b/test/java/nio/Buffer/LimitDirectMemory.java	Mon May 16 09:54:01 2016 +0100
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2002, 2010, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2002, 2016, 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
@@ -25,7 +25,7 @@
 import java.util.Properties;
 
 public class LimitDirectMemory {
-    private static int K = 1024;
+    private static final int K = 1024;
 
     public static void main(String [] args) throws Exception {
         if (args.length < 2)
@@ -83,7 +83,7 @@
 
         int idx = 0, len = size.length();
 
-        int result = 1;
+
         for (int i = 0; i < len; i++) {
             if (Character.isDigit(size.charAt(i))) idx++;
             else break;
@@ -92,7 +92,7 @@
         if (idx == 0)
             throw new RuntimeException("No digits detected: " + size);
 
-        result = Integer.parseInt(size.substring(0, idx));
+        int result = Integer.parseInt(size.substring(0, idx));
 
         if (idx < len) {
             for (int i = idx; i < len; i++) {
--- a/test/java/nio/Buffer/Order.java	Mon May 16 07:01:26 2016 +0200
+++ b/test/java/nio/Buffer/Order.java	Mon May 16 09:54:01 2016 +0100
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2001, 2015, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2001, 2016, 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
@@ -39,24 +39,24 @@
 
     static void ck(ByteOrder ord, ByteOrder expected) {
         if (ord != expected)
-            throw new RuntimeException("Got " + ord
-                                       + ", expected " + expected);
+            throw new RuntimeException("Got " + ord + ", expected " + expected);
     }
 
-    static void ckViews(ByteBuffer bb, ByteOrder ord) {
+    private static void ckViews(ByteBuffer bb) {
         ck(bb.asCharBuffer().order(), bb.order());
+        ck(bb.asShortBuffer().order(), bb.order());
         ck(bb.asIntBuffer().order(), bb.order());
         ck(bb.asLongBuffer().order(), bb.order());
         ck(bb.asFloatBuffer().order(), bb.order());
         ck(bb.asDoubleBuffer().order(), bb.order());
     }
 
-    static void ckByteBuffer(ByteBuffer bb) {
-        ckViews(bb, bb.order());
+    private static void ckByteBuffer(ByteBuffer bb) {
+        ckViews(bb);
         bb.order(be);
-        ckViews(bb, be);
+        ckViews(bb);
         bb.order(le);
-        ckViews(bb, le);
+        ckViews(bb);
 
         if (bb.hasArray()) {
             byte[] array = bb.array();
@@ -74,6 +74,8 @@
         ck(ByteBuffer.allocateDirect(LENGTH).order(), be);
         ck(ByteBuffer.allocate(LENGTH).order(be).order(), be);
         ck(ByteBuffer.allocate(LENGTH).order(le).order(), le);
+        ck(ByteBuffer.allocateDirect(LENGTH).order(be).order(), be);
+        ck(ByteBuffer.allocateDirect(LENGTH).order(le).order(), le);
 
         ckByteBuffer(ByteBuffer.allocate(LENGTH));
         ckByteBuffer(ByteBuffer.allocateDirect(LENGTH));
@@ -85,5 +87,4 @@
         OrderFloat.ckFloatBuffer();
         OrderDouble.ckDoubleBuffer();
     }
-
 }
--- a/test/java/nio/Buffer/SwapMicroBenchmark.java	Mon May 16 07:01:26 2016 +0200
+++ b/test/java/nio/Buffer/SwapMicroBenchmark.java	Mon May 16 09:54:01 2016 +0100
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2007, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2007, 2016, 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
@@ -35,7 +35,6 @@
 
 import java.util.*;
 import java.nio.*;
-import java.util.concurrent.*;
 import java.util.regex.Pattern;
 
 public class SwapMicroBenchmark {