8005394: Base64.Decoder/Encoder.wrap(XStream) don't throw NPE for null args passed
authorsherman
Thu, 31 Jan 2013 11:09:36 -0800
changeset 15513 64b67b85e2a2
parent 15512 32046b0f4aa8
child 15514 81f4aa2dd9e3
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
jdk/src/share/classes/java/util/Base64.java
jdk/test/java/util/Base64/TestBase64.java
--- a/jdk/src/share/classes/java/util/Base64.java	Thu Jan 31 10:55:15 2013 -0800
+++ b/jdk/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/jdk/test/java/util/Base64/TestBase64.java	Thu Jan 31 10:55:15 2013 -0800
+++ b/jdk/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 {