--- old/test/jdk/java/nio/Buffer/BasicShort.java 2019-02-13 14:12:07.000000000 -0800 +++ new/test/jdk/java/nio/Buffer/BasicShort.java 2019-02-13 14:12:05.000000000 -0800 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2000, 2016, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2000, 2019, 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 @@ -87,6 +87,18 @@ } } + private static void absBulkGet(ShortBuffer b) { + int n = b.capacity(); + int len = n - 7*2; + short[] a = new short[n + 7]; + b.position(42); + b.get(7, a, 7, len); + ck(b, b.position() == 42); + for (int i = 0; i < len; i++) { + ck(b, (long)a[i + 7], (long)((short)ic(i))); + } + } + private static void relPut(ShortBuffer b) { int n = b.capacity(); b.clear(); @@ -136,6 +148,47 @@ } } + private static void absBulkPutArray(ShortBuffer b) { + int n = b.capacity(); + b.clear(); + int lim = n - 7; + int len = lim - 7; + b.limit(lim); + short[] a = new short[len + 7]; + for (int i = 0; i < len; i++) + a[i + 7] = (short)ic(i); + b.position(42); + b.put(7, a, 7, len); + ck(b, b.position() == 42); + } + + private static void absBulkPutBuffer(ShortBuffer b, boolean direct) { + int n = b.capacity(); + b.clear(); + int lim = n - 7; + int len = lim - 7; + b.limit(lim); + ShortBuffer c = direct ? + + + + ByteBuffer.allocateDirect(Short.BYTES*(len + 7)) + .asShortBuffer() + + : ShortBuffer.allocate(len + 7); + + if (direct) + System.out.println("Direct buffer: " + c.getClass().getName()); + + for (int i = 0; i < len; i++) + c.put(i + 7, (short)ic(i)); + b.position(42); + c.position(42); + b.put(7, c, 7, len); + ck(b, b.position() == 42); + ck(c, c.position() == 42); + } + //6231529 private static void callReset(ShortBuffer b) { b.position(0); @@ -452,6 +505,10 @@ fail(problem + String.format(": x=%s y=%s", x, y), xb, yb); } + private static void catchNullArgument(Buffer b, Runnable thunk) { + tryCatch(b, NullPointerException.class, thunk); + } + private static void catchIllegalArgument(Buffer b, Runnable thunk) { tryCatch(b, IllegalArgumentException.class, thunk); } @@ -476,7 +533,10 @@ if (ex.isAssignableFrom(x.getClass())) { caught = true; } else { - fail(x.getMessage() + " not expected"); + String s = x.getMessage(); + if (s == null) + s = x.getClass().getName(); + fail(s + " not expected"); } } if (!caught) { @@ -513,6 +573,15 @@ bulkPutBuffer(b); relGet(b); + absBulkPutArray(b); + absBulkGet(b); + + absBulkPutBuffer(b, direct); + absBulkGet(b); + + absBulkPutBuffer(b, !direct); + absBulkGet(b); + @@ -612,6 +681,37 @@ } } + // Exceptions in absolute bulk operations + + catchNullArgument(b, () -> b.get(7, null, 0, 42)); + catchNullArgument(b, () -> b.put(7, (short[])null, 0, 42)); + catchNullArgument(b, () -> b.put(7, (ShortBuffer)null, 0, 42)); + + short[] tmpa = new short[42]; + catchIndexOutOfBounds(b, () -> b.get(7, tmpa, -1, 42)); + catchIndexOutOfBounds(b, () -> b.get(7, tmpa, 42, 1)); + catchIndexOutOfBounds(b, () -> b.get(7, tmpa, 41, -1)); + catchIndexOutOfBounds(b, () -> b.get(-1, tmpa, 0, 1)); + catchIndexOutOfBounds(b, () -> b.get(b.limit(), tmpa, 0, 1)); + catchIndexOutOfBounds(b, () -> b.get(b.limit() - 41, tmpa, 0, 42)); + + catchIndexOutOfBounds(b, () -> b.put(7, tmpa, -1, 42)); + catchIndexOutOfBounds(b, () -> b.put(7, tmpa, 42, 1)); + catchIndexOutOfBounds(b, () -> b.put(7, tmpa, 41, -1)); + catchIndexOutOfBounds(b, () -> b.put(-1, tmpa, 0, 1)); + catchIndexOutOfBounds(b, () -> b.put(b.limit(), tmpa, 0, 1)); + catchIndexOutOfBounds(b, () -> b.put(b.limit() - 41, tmpa, 0, 42)); + + ShortBuffer tmpb = ShortBuffer.allocate(42); + catchIndexOutOfBounds(b, () -> b.put(7, tmpb, -1, 42)); + catchIndexOutOfBounds(b, () -> b.put(7, tmpb, 42, 1)); + catchIndexOutOfBounds(b, () -> b.put(7, tmpb, 42, -1)); + catchIndexOutOfBounds(b, () -> b.put(7, tmpb, 41, 2)); + catchIndexOutOfBounds(b, () -> b.put(-1, tmpb, 0, 1)); + catchIndexOutOfBounds(b, () -> b.put(b.limit(), tmpb, 0, 1)); + catchIndexOutOfBounds(b, () -> b.put(0, tmpb, 0, -1)); + catchIndexOutOfBounds(b, () -> b.put(b.limit() - 41, tmpb, 0, 42)); + // Values b.clear(); @@ -819,6 +919,8 @@ catchReadOnlyBuffer(b, () -> absPut(rb)); catchReadOnlyBuffer(b, () -> bulkPutArray(rb)); catchReadOnlyBuffer(b, () -> bulkPutBuffer(rb)); + catchReadOnlyBuffer(b, () -> absBulkPutArray(rb)); + catchReadOnlyBuffer(b, () -> absBulkPutBuffer(rb, direct)); // put(ShortBuffer) should not change source position final ShortBuffer src = ShortBuffer.allocate(1);