{"record":{"id":"9cc38a7a97a8b524","repo":"TooTallNate/Java-WebSocket","slug":"source-array-was-null","errorCode":null,"errorMessage":"Source array was null.","messagePattern":"Source array was null\\.","errorType":"validation","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"src/main/java/org/java_websocket/util/Base64.java","lineNumber":808,"sourceCode":"   *\n   * @param source      the array to convert\n   * @param srcOffset   the index where conversion begins\n   * @param destination the array to hold the conversion\n   * @param destOffset  the index where output will be put\n   * @param options     alphabet type is pulled from this (standard, url-safe, ordered)\n   * @return the number of decoded bytes converted\n   * @throws IllegalArgumentException if source or destination arrays are null, if srcOffset or\n   *                                  destOffset are invalid or there is not enough room in the\n   *                                  array.\n   * @since 1.3\n   */\n  private static int decode4to3(\n      byte[] source, int srcOffset,\n      byte[] destination, int destOffset, int options) {\n\n    // Lots of error checking and exception throwing\n    if (source == null) {\n      throw new IllegalArgumentException(\"Source array was null.\");\n    }   // end if\n    if (destination == null) {\n      throw new IllegalArgumentException(\"Destination array was null.\");\n    }   // end if\n    if (srcOffset < 0 || srcOffset + 3 >= source.length) {\n      throw new IllegalArgumentException(String.format(\n          \"Source array with length %d cannot have offset of %d and still process four bytes.\",\n          source.length, srcOffset));\n    }   // end if\n    if (destOffset < 0 || destOffset + 2 >= destination.length) {\n      throw new IllegalArgumentException(String.format(\n          \"Destination array with length %d cannot have offset of %d and still store three bytes.\",\n          destination.length, destOffset));\n    }   // end if\n\n    final byte[] DECODABET = getDecodabet(options);\n\n    // Example: Dk==","sourceCodeStart":790,"sourceCodeEnd":826,"githubUrl":"https://github.com/TooTallNate/Java-WebSocket/blob/afeacbf8c0f6f6a761c9d9daed8c813dd3b8ed7d/src/main/java/org/java_websocket/util/Base64.java#L790-L826","documentation":"decode4to3 is Base64's internal 4-byte-to-3-byte decoding step. It requires both a non-null source and destination array; a null source is rejected immediately with IllegalArgumentException. This is an internal precondition violated by a caller passing null input into a decode path.","triggerScenarios":"A decode call chain (decode/decodeBytes/decodeFromFile wrappers) reaches decode4to3 with source == null — e.g. passing a null byte[] into a decode API that does not null-check earlier.","commonSituations":"Decoding a byte[] field read from config/database that is null; calling the deprecated decode(Object) style APIs with null; refactored code where an earlier null-check was removed.","solutions":["Null-check the input byte[] before invoking any Base64 decode API.","Treat a null payload as an empty result or an explicit error in your own code instead of forwarding it.","If input is untrusted, validate at the API boundary and return a 400-style error rather than letting it propagate."],"exampleFix":"// before\nbyte[] decoded = Base64.decode(data);\n\n// after\nbyte[] decoded = (data == null) ? new byte[0] : Base64.decode(data);","handlingStrategy":"type-guard","validationCode":"if (data != null) {\n    byte[] decoded = Base64.decode(data);\n} else {\n    // treat as empty or surface a validation error\n}","typeGuard":"static boolean isDecodable(byte[] input) {\n    return input != null;\n}","tryCatchPattern":"try {\n    decoded = Base64.decode(data);\n} catch (IllegalArgumentException e) {\n    // null or malformed input\n    decoded = null;\n}","preventionTips":["Null-check byte[] payloads at the deserialization boundary before any crypto/base64 step.","Prefer Optional<byte[]> over nullable byte[] fields in internal APIs.","Add @NonNull annotations so static analysis catches null flow into decode calls."],"tags":["java","base64","null","illegal-argument"],"backgroundTag":"null-argument","analyzedSha":"afeacbf8c0f6f6a761c9d9daed8c813dd3b8ed7d","analyzedAt":"2026-09-09T14:39:47.546Z","contentChangedAt":"2026-09-09T14:39:47.546Z","schemaVersion":2},"datasetVersion":"2026-09-16T09:17:16.951Z"}