{"record":{"id":"97a4b82960eb5214","repo":"microg/GmsCore","slug":"the-id-is-not-of-length-16-bytes","errorCode":null,"errorMessage":"the id is not of length 16 bytes","messagePattern":"the id is not of length 16 bytes","errorType":"validation","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"play-services-threadnetwork/src/main/java/com/google/android/gms/threadnetwork/ThreadBorderAgent.java","lineNumber":44,"sourceCode":"    public ThreadBorderAgent(@Param(2) byte[] id) {\n        this.id = id;\n    }\n\n    /**\n     * Returns the id which uniquely identifies a Thread Border Agent device.\n     */\n    public byte[] getId() {\n        return id;\n    }\n\n    /**\n     * Creates a new {@link ThreadBorderAgent.Builder} for constructing a {@link ThreadBorderAgent}.\n     *\n     * @param id the id which uniquely identifies a Border Agent. The length must be 16 bytes.\n     * @throws IllegalArgumentException if the id is not of length 16 bytes.\n     */\n    public static Builder newBuilder(byte[] id) {\n        if (id.length != 16) throw new IllegalArgumentException(\"the id is not of length 16 bytes\");\n        return new Builder(id);\n    }\n\n    /**\n     * Builder for constructing {@link ThreadBorderAgent} instances.\n     */\n    public static class Builder {\n        private byte[] id;\n\n        private Builder(byte[] id) {\n            this.id = id;\n        }\n\n        /**\n         * Constructs a {@link ThreadBorderAgent} as configured by this builder.\n         */\n        public ThreadBorderAgent build() {\n            return new ThreadBorderAgent(id);","sourceCodeStart":26,"sourceCodeEnd":62,"githubUrl":"https://github.com/microg/GmsCore/blob/157c9d86ac46c195a86c2f15ab55c84036223f95/play-services-threadnetwork/src/main/java/com/google/android/gms/threadnetwork/ThreadBorderAgent.java#L26-L62","documentation":"ThreadBorderAgent.newBuilder(byte[] id) validates that the Border Agent identifier is exactly 16 bytes and throws IllegalArgumentException otherwise. Thread Border Agent IDs are defined by the Thread specification as 16-byte UUID-like values, so any other length cannot be a valid identifier.","triggerScenarios":"Passing a byte[] whose length is not 16 to ThreadBorderAgent.newBuilder() — e.g. a truncated copy, a hex/base64-decoded string of the wrong length, or a raw device-reported ID of 8 bytes.","commonSituations":"Decoding a border agent ID from a string (hex/base64) that drops leading zeros or includes separators; receiving IDs from an API that returns shorter identifiers; copy-pasting an ID with wrong encoding.","solutions":["Verify id.length == 16 before calling newBuilder and reject/repair the input","Re-encode the identifier correctly: parse as a 16-byte UUID (UUID.toString/fromString maps to 16 bytes)","If hex-decoding, confirm the hex string is 32 characters and decode without trimming","Log the actual length to find where the ID got truncated or padded"],"exampleFix":"// before\nbyte[] id = hexStringToByteArray(agentHex); // may be wrong length\nThreadBorderAgent agent = ThreadBorderAgent.newBuilder(id).build();\n// after\nbyte[] id = hexStringToByteArray(agentHex);\nif (id.length != 16) throw new IllegalArgumentException(\"Border agent id must be 16 bytes, got \" + id.length);\nThreadBorderAgent agent = ThreadBorderAgent.newBuilder(id).build();","handlingStrategy":"validation","validationCode":"if (id == null || id.length != 16) throw new IllegalArgumentException(\"Border agent id must be exactly 16 bytes, got \" + (id == null ? \"null\" : id.length));","typeGuard":"boolean isValidBorderAgentId(byte[] id) { return id != null && id.length == 16; }","tryCatchPattern":"try {\n    ThreadBorderAgent.Builder b = ThreadBorderAgent.newBuilder(id);\n} catch (IllegalArgumentException e) {\n    // log and reject the malformed identifier\n}","preventionTips":["Validate identifier length at the parsing boundary (hex/base64 decoders)","Use UUID parsing for 16-byte identifiers","Log the raw source string when a decode yields the wrong length"],"tags":["thread-network","validation","byte-array","java"],"backgroundTag":"invalid-argument-format","analyzedSha":"157c9d86ac46c195a86c2f15ab55c84036223f95","analyzedAt":"2026-09-06T17:27:33.892Z","contentChangedAt":"2026-09-06T17:27:33.892Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}