{"record":{"id":"87ea0894b94188b9","repo":"microg/GmsCore","slug":"rotationtimehours-is-not-in-range-of-0x1-0xffff","errorCode":null,"errorMessage":"rotationTimeHours is not in range of 0x1-0xffff","messagePattern":"rotationTimeHours is not in range of 0x1-0xffff","errorType":"validation","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"play-services-threadnetwork/src/main/java/com/google/android/gms/threadnetwork/ThreadNetworkCredentials.java","lineNumber":177,"sourceCode":"    }\n\n    /**\n     * The class represents Thread Security Policy.\n     */\n    public static class SecurityPolicy {\n        private final int rotationTimeHours;\n        private final byte[] flags;\n\n        /**\n         * Creates a new {@link SecurityPolicy} object.\n         *\n         * @param rotationTimeHours the value for Thread key rotation in hours. Must be in range of 0x1-0xffff.\n         * @param flags             security policy flags with length of either 1 byte for Thread 1.1 or 2 bytes for Thread 1.2 or higher.\n         * @throws IllegalArgumentException if {@code rotationTimeHours} is not in range of 0x1-0xffff or\n         *                                  length of flags is smaller than {@link ThreadNetworkCredentials#LENGTH_MIN_SECURITY_POLICY_FLAGS}.\n         */\n        public SecurityPolicy(int rotationTimeHours, byte[] flags) {\n            if (rotationTimeHours < 1 || rotationTimeHours > 0xffff) throw new IllegalArgumentException(\"rotationTimeHours is not in range of 0x1-0xffff\");\n            if (flags.length < LENGTH_MIN_SECURITY_POLICY_FLAGS) throw new IllegalArgumentException(\"length of flags is smaller than LENGTH_MIN_SECURITY_POLICY_FLAGS\");\n            this.rotationTimeHours = rotationTimeHours;\n            this.flags = flags;\n        }\n\n        /**\n         * Returns 1 byte flags for Thread 1.1 or 2 bytes flags for Thread 1.2.\n         */\n        public byte[] getFlags() {\n            return flags;\n        }\n\n        /**\n         * Returns the Security Policy Rotation Time in hours.\n         */\n        public int getRotationTimeHours() {\n            return rotationTimeHours;\n        }","sourceCodeStart":159,"sourceCodeEnd":195,"githubUrl":"https://github.com/microg/GmsCore/blob/157c9d86ac46c195a86c2f15ab55c84036223f95/play-services-threadnetwork/src/main/java/com/google/android/gms/threadnetwork/ThreadNetworkCredentials.java#L159-L195","documentation":"ThreadNetworkCredentials.SecurityPolicy's constructor validates that rotationTimeHours is within the Thread-spec range 0x1-0xffff and throws IllegalArgumentException otherwise. The rotation time is a 16-bit unsigned field in the Thread network dataset, so 0 or values above 65535 are unrepresentable and invalid.","triggerScenarios":"Constructing a SecurityPolicy with rotationTimeHours == 0 or > 65535, e.g. from a dataset field parsed without range validation or a default of 0 used to mean 'unset'.","commonSituations":"Initializing rotationTimeHours to 0 as a placeholder; reading the value from a TLV parser that returns a wider int; config files with 0 meaning 'use default'.","solutions":["Use a value in [1, 65535]; the Thread default rotation time is 672 hours","Validate the parsed value before constructing SecurityPolicy","Replace 0 placeholder defaults with the spec default (672)","If the source is unsigned 16-bit data, mask with & 0xFFFF and confirm it's nonzero"],"exampleFix":"// before\nSecurityPolicy policy = new SecurityPolicy(0, flags); // IllegalArgumentException\n// after\nint rotationTimeHours = 672; // Thread default, must be 1..0xffff\nSecurityPolicy policy = new SecurityPolicy(rotationTimeHours, flags);","handlingStrategy":"validation","validationCode":"if (rotationTimeHours < 1 || rotationTimeHours > 0xffff) throw new IllegalArgumentException(\"rotationTimeHours must be in 0x1-0xffff, got \" + rotationTimeHours);","typeGuard":"boolean isValidRotationTime(int hours) { return hours >= 1 && hours <= 0xffff; }","tryCatchPattern":"try {\n    SecurityPolicy p = new SecurityPolicy(rotationTimeHours, flags);\n} catch (IllegalArgumentException e) {\n    // fall back to the Thread default of 672 hours\n}","preventionTips":["Use the Thread default (672 hours) instead of 0 placeholders","Mask unsigned 16-bit fields with & 0xFFFF and check nonzero","Validate dataset fields parsed from TLV/JSON before constructing objects"],"tags":["thread-network","validation","range-check","java"],"backgroundTag":"argument-out-of-range","analyzedSha":"157c9d86ac46c195a86c2f15ab55c84036223f95","analyzedAt":"2026-09-06T17:27:33.892Z","contentChangedAt":"2026-09-06T17:27:33.892Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}