changeset 7410:857d99bef21d

8005394: Base64.Decoder/Encoder.wrap(XStream) don't throw NPE for null args passed Summary: to check null for dec/enc.wrap methods Reviewed-by: alanb
author sherman
date Thu, 31 Jan 2013 11:09:36 -0800
parents 3f766f58c48a
children 278397f752da
files src/share/classes/java/util/Base64.java test/java/util/Base64/TestBase64.java
diffstat 2 files changed, 5 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/src/share/classes/java/util/Base64.java	Thu Jan 31 10:55:15 2013 -0800
+++ b/src/share/classes/java/util/Base64.java	Thu Jan 31 11:09:36 2013 -0800
@@ -413,6 +413,7 @@
          *          specified Base64 encoded format
          */
         public OutputStream wrap(OutputStream os) {
+            Objects.requireNonNull(os);
             return new EncOutputStream(os, isURL ? toBase64URL : toBase64,
                                        newline, linemax);
         }
@@ -866,6 +867,7 @@
          *          byte stream
          */
         public InputStream wrap(InputStream is) {
+            Objects.requireNonNull(is);
             return new DecInputStream(is, isURL ? fromBase64URL : fromBase64, isMIME);
         }
 
--- a/test/java/util/Base64/TestBase64.java	Thu Jan 31 10:55:15 2013 -0800
+++ b/test/java/util/Base64/TestBase64.java	Thu Jan 31 11:09:36 2013 -0800
@@ -22,7 +22,7 @@
  */
 
 /**
- * @test 4235519 8004212
+ * @test 4235519 8004212 8005394
  * @summary tests java.util.Base64
  */
 
@@ -295,6 +295,7 @@
         checkNull(new Runnable() { public void run() { enc.encode(bb_null); }});
         checkNull(new Runnable() { public void run() { enc.encode(bb_null, ByteBuffer.allocate(10), 0); }});
         checkNull(new Runnable() { public void run() { enc.encode(ByteBuffer.allocate(10), bb_null, 0); }});
+        checkNull(new Runnable() { public void run() { enc.wrap(null); }});
     }
 
     private static void testNull(final Base64.Decoder dec) {
@@ -305,6 +306,7 @@
         checkNull(new Runnable() { public void run() { dec.decode(bb_null); }});
         checkNull(new Runnable() { public void run() { dec.decode(bb_null, ByteBuffer.allocate(10)); }});
         checkNull(new Runnable() { public void run() { dec.decode(ByteBuffer.allocate(10), bb_null); }});
+        checkNull(new Runnable() { public void run() { dec.wrap(null); }});
     }
 
     private static interface Testable {