108108 * it should have been done this way to begin with.</li>
109109 * <li><em>Removed all references to System.out, System.err, and the like.</em>
110110 * Shame on me. All I can say is sorry they were ever there.</li>
111- * <li><em>Throws NullPointerExceptions and IllegalArgumentExceptions</em> as needed
111+ * <li><em>Throws IllegalArgumentExceptions</em> as needed
112112 * such as when passed arrays are null or offsets are invalid.</li>
113113 * <li>Cleaned up as much javadoc as I could to avoid any javadoc warnings.
114114 * This was especially annoying before for people who were thorough in their
@@ -635,7 +635,7 @@ public static void encode( java.nio.ByteBuffer raw, java.nio.CharBuffer encoded
635635 * @param serializableObject The object to encode
636636 * @return The Base64-encoded object
637637 * @throws java.io.IOException if there is an error
638- * @throws NullPointerException if serializedObject is null
638+ * @throws IllegalArgumentException if serializedObject is null
639639 * @since 1.4
640640 */
641641 public static String encodeObject ( java .io .Serializable serializableObject )
@@ -678,7 +678,7 @@ public static String encodeObject( java.io.Serializable serializableObject, int
678678 throws java .io .IOException {
679679
680680 if ( serializableObject == null ){
681- throw new NullPointerException ( "Cannot serialize a null object." );
681+ throw new IllegalArgumentException ( "Cannot serialize a null object." );
682682 } // end if: null
683683
684684 // Streams
@@ -733,7 +733,7 @@ public static String encodeObject( java.io.Serializable serializableObject, int
733733 *
734734 * @param source The data to convert
735735 * @return The data in Base64-encoded form
736- * @throws NullPointerException if source array is null
736+ * @throws IllegalArgumentException if source array is null
737737 * @since 1.4
738738 */
739739 public static String encodeBytes ( byte [] source ) {
@@ -778,7 +778,7 @@ public static String encodeBytes( byte[] source ) {
778778 * @see Base64#GZIP
779779 * @see Base64#DO_BREAK_LINES
780780 * @throws java.io.IOException if there is an error
781- * @throws NullPointerException if source array is null
781+ * @throws IllegalArgumentException if source array is null
782782 * @since 2.0
783783 */
784784 public static String encodeBytes ( byte [] source , int options ) throws java .io .IOException {
@@ -800,8 +800,7 @@ public static String encodeBytes( byte[] source, int options ) throws java.io.IO
800800 * @param off Offset in array where conversion should begin
801801 * @param len Length of data to convert
802802 * @return The Base64-encoded data as a String
803- * @throws NullPointerException if source array is null
804- * @throws IllegalArgumentException if source array, offset, or length are invalid
803+ * @throws IllegalArgumentException if source array is null if source array, offset, or length are invalid
805804 * @since 1.4
806805 */
807806 public static String encodeBytes ( byte [] source , int off , int len ) {
@@ -848,8 +847,7 @@ public static String encodeBytes( byte[] source, int off, int len ) {
848847 * @see Base64#GZIP
849848 * @see Base64#DO_BREAK_LINES
850849 * @throws java.io.IOException if there is an error
851- * @throws NullPointerException if source array is null
852- * @throws IllegalArgumentException if source array, offset, or length are invalid
850+ * @throws IllegalArgumentException if source array is null, if source array, offset, or length are invalid
853851 * @since 2.0
854852 */
855853 public static String encodeBytes ( byte [] source , int off , int len , int options ) throws java .io .IOException {
@@ -876,7 +874,7 @@ public static String encodeBytes( byte[] source, int off, int len, int options )
876874 *
877875 * @param source The data to convert
878876 * @return The Base64-encoded data as a byte[] (of ASCII characters)
879- * @throws NullPointerException if source array is null
877+ * @throws IllegalArgumentException if source array is null
880878 * @since 2.3.1
881879 */
882880 public static byte [] encodeBytesToBytes ( byte [] source ) {
@@ -904,14 +902,13 @@ public static byte[] encodeBytesToBytes( byte[] source ) {
904902 * @see Base64#GZIP
905903 * @see Base64#DO_BREAK_LINES
906904 * @throws java.io.IOException if there is an error
907- * @throws NullPointerException if source array is null
908- * @throws IllegalArgumentException if source array, offset, or length are invalid
905+ * @throws IllegalArgumentException if source array is null, if source array, offset, or length are invalid
909906 * @since 2.3.1
910907 */
911908 public static byte [] encodeBytesToBytes ( byte [] source , int off , int len , int options ) throws java .io .IOException {
912909
913910 if ( source == null ){
914- throw new NullPointerException ( "Cannot serialize a null array." );
911+ throw new IllegalArgumentException ( "Cannot serialize a null array." );
915912 } // end if: null
916913
917914 if ( off < 0 ){
@@ -1047,8 +1044,7 @@ public static byte[] encodeBytesToBytes( byte[] source, int off, int len, int op
10471044 * @param destOffset the index where output will be put
10481045 * @param options alphabet type is pulled from this (standard, url-safe, ordered)
10491046 * @return the number of decoded bytes converted
1050- * @throws NullPointerException if source or destination arrays are null
1051- * @throws IllegalArgumentException if srcOffset or destOffset are invalid
1047+ * @throws IllegalArgumentException if source or destination arrays are null, if srcOffset or destOffset are invalid
10521048 * or there is not enough room in the array.
10531049 * @since 1.3
10541050 */
@@ -1058,10 +1054,10 @@ private static int decode4to3(
10581054
10591055 // Lots of error checking and exception throwing
10601056 if ( source == null ){
1061- throw new NullPointerException ( "Source array was null." );
1057+ throw new IllegalArgumentException ( "Source array was null." );
10621058 } // end if
10631059 if ( destination == null ){
1064- throw new NullPointerException ( "Destination array was null." );
1060+ throw new IllegalArgumentException ( "Destination array was null." );
10651061 } // end if
10661062 if ( srcOffset < 0 || srcOffset + 3 >= source .length ){
10671063 throw new IllegalArgumentException ( String .format (
@@ -1167,7 +1163,7 @@ public static byte[] decode( byte[] source, int off, int len, int options )
11671163
11681164 // Lots of error checking and exception throwing
11691165 if ( source == null ){
1170- throw new NullPointerException ( "Cannot decode null source array." );
1166+ throw new IllegalArgumentException ( "Cannot decode null source array." );
11711167 } // end if
11721168 if ( off < 0 || off + len > source .length ){
11731169 throw new IllegalArgumentException ( String .format (
@@ -1251,13 +1247,13 @@ public static byte[] decode( String s ) throws java.io.IOException {
12511247 * @param options encode options such as URL_SAFE
12521248 * @return the decoded data
12531249 * @throws java.io.IOException if there is an error
1254- * @throws NullPointerException if <tt>s</tt> is null
1250+ * @throws IllegalArgumentException if <tt>s</tt> is null
12551251 * @since 1.4
12561252 */
12571253 public static byte [] decode ( String s , int options ) throws java .io .IOException {
12581254
12591255 if ( s == null ){
1260- throw new NullPointerException ( "Input string was null." );
1256+ throw new IllegalArgumentException ( "Input string was null." );
12611257 } // end if
12621258
12631259 byte [] bytes ;
@@ -1322,7 +1318,7 @@ public static byte[] decode( String s, int options ) throws java.io.IOException
13221318 *
13231319 * @param encodedObject The Base64 data to decode
13241320 * @return The decoded and deserialized object
1325- * @throws NullPointerException if encodedObject is null
1321+ * @throws IllegalArgumentException if encodedObject is null
13261322 * @throws java.io.IOException if there is a general error
13271323 * @throws ClassNotFoundException if the decoded object is of a
13281324 * class that cannot be found by the JVM
@@ -1344,7 +1340,7 @@ public static Object decodeToObject( String encodedObject )
13441340 * @param options Various parameters related to decoding
13451341 * @param loader Optional class loader to use in deserializing classes.
13461342 * @return The decoded and deserialized object
1347- * @throws NullPointerException if encodedObject is null
1343+ * @throws IllegalArgumentException if encodedObject is null
13481344 * @throws java.io.IOException if there is a general error
13491345 * @throws ClassNotFoundException if the decoded object is of a
13501346 * class that cannot be found by the JVM
@@ -1415,14 +1411,14 @@ public Class<?> resolveClass(java.io.ObjectStreamClass streamClass)
14151411 * @param dataToEncode byte array of data to encode in base64 form
14161412 * @param filename Filename for saving encoded data
14171413 * @throws java.io.IOException if there is an error
1418- * @throws NullPointerException if dataToEncode is null
1414+ * @throws IllegalArgumentException if dataToEncode is null
14191415 * @since 2.1
14201416 */
14211417 public static void encodeToFile ( byte [] dataToEncode , String filename )
14221418 throws java .io .IOException {
14231419
14241420 if ( dataToEncode == null ){
1425- throw new NullPointerException ( "Data to encode was null." );
1421+ throw new IllegalArgumentException ( "Data to encode was null." );
14261422 } // end iff
14271423
14281424 Base64 .OutputStream bos = null ;
0 commit comments