{"record":{"id":"0699ff16be8c68d8","repo":"aeron-io/aeron","slug":"page-size-not-a-power-of-2-page-size-pagesize","errorCode":null,"errorMessage":"Page size not a power of 2: page size={pageSize}","messagePattern":"Page size not a power of 2: page size=(.+?)","errorType":"validation","errorClass":"IllegalStateException","httpStatus":null,"severity":"error","filePath":"aeron-client/src/main/java/io/aeron/logbuffer/LogBufferDescriptor.java","lineNumber":494,"sourceCode":"     * @throws IllegalStateException if the size is not as expected.\n     */\n    public static void checkPageSize(final int pageSize)\n    {\n        if (pageSize < PAGE_MIN_SIZE)\n        {\n            throw new IllegalStateException(\n                \"Page size less than min size of \" + PAGE_MIN_SIZE + \": page size=\" + pageSize);\n        }\n\n        if (pageSize > PAGE_MAX_SIZE)\n        {\n            throw new IllegalStateException(\n                \"Page size more than max size of \" + PAGE_MAX_SIZE + \": page size=\" + pageSize);\n        }\n\n        if (!BitUtil.isPowerOfTwo(pageSize))\n        {\n            throw new IllegalStateException(\"Page size not a power of 2: page size=\" + pageSize);\n        }\n    }\n\n    /**\n     * Get the value of the initial Term id used for this log.\n     *\n     * @param metadataBuffer containing the meta data.\n     * @return the value of the initial Term id used for this log.\n     */\n    public static int initialTermId(final UnsafeBuffer metadataBuffer)\n    {\n        return metadataBuffer.getInt(LOG_INITIAL_TERM_ID_OFFSET);\n    }\n\n    /**\n     * Set the initial term at which this log begins. Initial should be randomised so that stream does not get\n     * reused accidentally.\n     *","sourceCodeStart":476,"sourceCodeEnd":512,"githubUrl":"https://github.com/aeron-io/aeron/blob/6d60124e15e35c11b49ba2e3c2c2858a09a18803/aeron-client/src/main/java/io/aeron/logbuffer/LogBufferDescriptor.java#L476-L512","documentation":"LogBufferDescriptor.checkPageSize requires the page size to be a power of 2, since Aeron computes page alignment with shifts and masks. Any non-power-of-two page size is rejected with IllegalStateException.","triggerScenarios":"Passing pageSize such as 5000, 8192+1, or 1000000 to filePageSize configuration or log buffer factory methods that call checkPageSize.","commonSituations":"Config values derived from OS-specific defaults that are not powers of two, or user-tuned settings like file-page-size=10000.","solutions":["Round the page size to the next power of two with BitUtil.findNextPositivePowerOfTwo","Use canonical sizes: 4096, 8192, 16384, 65536, 1048576","Validate with BitUtil.isPowerOfTwo(pageSize) during configuration load"],"exampleFix":"// before\ndriverCtx.filePageSize(10_000);\n// after\ndriverCtx.filePageSize(BitUtil.findNextPositivePowerOfTwo(10_000)); // 16384","handlingStrategy":"validation","validationCode":"if (!BitUtil.isPowerOfTwo(pageSize)) { pageSize = BitUtil.findNextPositivePowerOfTwo(pageSize); }","typeGuard":null,"tryCatchPattern":"try { driver = MediaDriver.launch(ctx); } catch (final IllegalStateException ex) { if (ex.getMessage().startsWith(\"Page size not a power of 2\")) { ctx.filePageSize(BitUtil.findNextPositivePowerOfTwo(ctx.filePageSize())); driver = MediaDriver.launch(ctx); } else throw ex; }","preventionTips":["Normalize page sizes with findNextPositivePowerOfTwo before setting","Restrict config to a fixed enum of allowed page sizes","Add a startup assertion using BitUtil.isPowerOfTwo"],"tags":["aeron","configuration","page-size","validation"],"backgroundTag":"invalid-config-value","analyzedSha":"6d60124e15e35c11b49ba2e3c2c2858a09a18803","analyzedAt":"2026-09-12T11:17:07.683Z","contentChangedAt":"2026-09-12T11:17:07.683Z","schemaVersion":2},"datasetVersion":"2026-09-15T23:17:13.987Z"}