test/java/nio/Buffer/Basic-X.java.template

Print this page
rev 11666 : 8065556: (bf) Buffer.position and other methods should include detail in IAE
Summary: Add messages to IAEs which have none.
Reviewed-by: XXX

@@ -1,7 +1,7 @@
 /*
- * Copyright (c) 2000, 2012, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2000, 2015, 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
  * under the terms of the GNU General Public License version 2 only, as
  * published by the Free Software Foundation.

@@ -126,10 +126,18 @@
             c.put(($type$)ic(i));
         c.flip();
         c.position(7);
         b.put(c);
         b.flip();
+        try {
+            b.put(b);
+            fail("IllegalArgumentException expected for putting into same buffer");
+        } catch (IllegalArgumentException e) {
+            if (e.getMessage() == null) {
+                fail("Non-null IllegalArgumentException message expected from putting into same buffer");
+            }
+        }
     }
 
     //6231529
     private static void callReset($Type$Buffer b) {
         b.position(0);

@@ -462,10 +470,46 @@
                     b.mark();
                     b.compact();
                     b.reset();
                 }});
 
+        try {
+            b.position(b.limit() + 1);
+            fail("IllegalArgumentException expected for setting position beyond limit");
+        } catch (IllegalArgumentException e) {
+            if (e.getMessage() == null) {
+                fail("Non-null IllegalArgumentException message expected for setting position beyond limit");
+            }
+        }
+
+        try {
+            b.position(-1);
+            fail("IllegalArgumentException expected for setting negative position");
+        } catch (IllegalArgumentException e) {
+            if (e.getMessage() == null) {
+                fail("Non-null IllegalArgumentException message expected for setting negative position");
+            }
+        }
+
+        try {
+            b.limit(b.capacity() + 1);
+            fail("IllegalArgumentException expected for setting limit beyond capacity");
+        } catch (IllegalArgumentException e) {
+            if (e.getMessage() == null) {
+                fail("Non-null IllegalArgumentException message expected for setting limit beyond capacity");
+            }
+        }
+
+        try {
+            b.limit(-1);
+            fail("IllegalArgumentException expected for setting negative limit");
+        } catch (IllegalArgumentException e) {
+            if (e.getMessage() == null) {
+                fail("Non-null IllegalArgumentException message expected for setting negative limit");
+            }
+        }
+
         // Values
 
         b.clear();
         b.put(($type$)0);
         b.put(($type$)-1);

@@ -932,15 +976,29 @@
         // An IllegalArgumentException will be thrown for negative capacities.
         tryCatch((Buffer) null, IllegalArgumentException.class, new Runnable() {
                 public void run() {
                     $Type$Buffer.allocate(-1);
                 }});
+        try {
+            $Type$Buffer.allocate(-1);
+        } catch (IllegalArgumentException e) {
+            if (e.getMessage() == null) {
+                fail("Non-null IllegalArgumentException message expected attempt to allocate negative capacity buffer");
+            }
+        }
 #if[byte]
         tryCatch((Buffer) null, IllegalArgumentException.class, new Runnable() {
                 public void run() {
                     $Type$Buffer.allocateDirect(-1);
                 }});
+        try {
+            $Type$Buffer.allocateDirect(-1);
+        } catch (IllegalArgumentException e) {
+            if (e.getMessage() == null) {
+                fail("Non-null IllegalArgumentException message expected attempt to allocate negative capacity direct buffer");
+            }
+        }
 #end[byte]
     }
 
     public static void test() {
         testAllocate();