{"record":{"id":"c9ef046b0043e3b7","repo":"dotnet/wpf","slug":"reader-or-compresseddata-was-null-in-compress","errorCode":null,"errorMessage":"reader or compressedData was null in compress","messagePattern":"reader or compressedData was null in compress","errorType":"exception","errorClass":"ArgumentNullException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.DotNet.Wpf/src/PresentationCore/MS/internal/Ink/InkSerializedFormat/GorillaCodec.cs","lineNumber":410,"sourceCode":"                {\n                    writer.Write((uint)input[i], bitCount);\n                }\n            }\n        }\n\n        /// <summary>\n        /// Compress - compresses the byte[] being read by the BitStreamReader into compressed data\n        /// </summary>\n        /// <param name=\"bitCount\">the number of bits to use for each element</param>\n        /// <param name=\"reader\">a reader over the byte[] to compress</param>\n        /// <param name=\"encodingType\">int, short or byte?</param>\n        /// <param name=\"unitsToEncode\">number of logical units to encoded</param>\n        /// <param name=\"compressedData\">output write buffer</param>\n        internal void Compress(int bitCount, BitStreamReader reader, GorillaEncodingType encodingType, int unitsToEncode, List<byte> compressedData)\n        {\n            if (null == reader || null == compressedData)\n            {\n                throw new ArgumentNullException(StrokeCollectionSerializer.ISFDebugMessage(\"reader or compressedData was null in compress\"));\n            }\n            ArgumentOutOfRangeException.ThrowIfNegative(bitCount);\n            ArgumentOutOfRangeException.ThrowIfNegative(unitsToEncode);\n\n            if (bitCount == 0)\n            {\n                //adjust if the bitcount is 0\n                //(this makes bitCount 32)\n                switch (encodingType)\n                {\n                    case GorillaEncodingType.Int:\n                        {\n                            bitCount = Native.BitsPerInt;\n                            break;\n                        }\n                    case GorillaEncodingType.Short:\n                        {\n                            bitCount = Native.BitsPerShort;","sourceCodeStart":392,"sourceCodeEnd":428,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/PresentationCore/MS/internal/Ink/InkSerializedFormat/GorillaCodec.cs#L392-L428","documentation":"This overload of GorillaCodec.Compress (reading from a BitStreamReader) validates that both the reader and the compressedData output list are non-null, throwing ArgumentNullException with this message. As with the array-based overload, null buffers indicate a caller bug rather than corrupt data.","triggerScenarios":"Calling Compress(bitCount, reader, encodingType, unitsToEncode, compressedData) with reader == null (BitStreamReader never constructed or failed construction) or compressedData == null.","commonSituations":"Custom encoding pipelines where the BitStreamReader creation was skipped or a stream was null before wrapping; refactors that moved buffer initialization away from the call site.","solutions":["Construct the BitStreamReader from a valid, non-null source stream before calling Compress.","Initialize compressedData = new List<byte>() before the call.","Add explicit null checks for both arguments in the calling method.","Use the high-level StrokeCollection serialization APIs so buffers are managed for you."],"exampleFix":"// before\nGorillaCodec codec = new GorillaCodec();\ncodec.Compress(8, reader, GorillaEncodingType.OneByte, count, null);\n// after\nList<byte> compressedData = new List<byte>();\ncodec.Compress(8, reader, GorillaEncodingType.OneByte, count, compressedData);","handlingStrategy":"validation","validationCode":"if (reader == null) throw new ArgumentNullException(nameof(reader));\nif (compressedData == null) throw new ArgumentNullException(nameof(compressedData));","typeGuard":"bool CanCompress(BitStreamReader r, List<byte> outBuf) => r != null && outBuf != null;","tryCatchPattern":"try { codec.Compress(bitCount, reader, encodingType, units, outBuf); }\ncatch (ArgumentNullException ex) { log.Error(\"Missing BitStreamReader/output buffer\", ex); throw; }","preventionTips":["Build the BitStreamReader immediately before use from a verified non-null stream.","Allocate the output list at the same call site that invokes Compress.","Guard earlier pipeline steps so a null upstream stream cannot propagate into the codec."],"tags":["ink","gorilla-codec","compression","null-argument"],"backgroundTag":"null-argument","analyzedSha":"81131a70a4c573cd62748a5c36908fc4d662daa9","analyzedAt":"2026-09-14T10:12:48.479Z","contentChangedAt":"2026-09-14T10:12:48.479Z","schemaVersion":2},"datasetVersion":"2026-09-22T01:17:13.364Z"}