{"record":{"id":"355764a0654e56ab","repo":"MyCATApache/Mycat-Server","slug":"runtimeexception-e","errorCode":null,"errorMessage":"RuntimeException(e)","messagePattern":"RuntimeException\\(e\\)","errorType":"exception","errorClass":"RuntimeException","httpStatus":null,"severity":"critical","filePath":"src/main/java/io/mycat/memory/unsafe/ringbuffer/common/sequence/Sequence.java","lineNumber":47,"sourceCode":" * of concurrent operations including CAS and order writes.\n *\n * <p>Also attempts to be more efficient with regards to false\n * sharing by adding padding around the volatile field.\n */\npublic class Sequence extends RhsPadding\n{\n    public static final long INITIAL_VALUE = -1L;\n    private static final long VALUE_OFFSET;\n\n    static\n    {\n        try\n        {\n            VALUE_OFFSET = Platform.objectFieldOffset(Value.class.getDeclaredField(\"value\"));\n        }\n        catch (final Exception e)\n        {\n            throw new RuntimeException(e);\n        }\n    }\n\n    /**\n     * Create a sequence initialised to -1.\n     */\n    public Sequence()\n    {\n        this(INITIAL_VALUE);\n    }\n\n    /**\n     * Create a sequence with a specified initial value.\n     *\n     * @param initialValue The initial value for this sequence.\n     */\n    public Sequence(final long initialValue)\n    {","sourceCodeStart":29,"sourceCodeEnd":65,"githubUrl":"https://github.com/MyCATApache/Mycat-Server/blob/65f8d8beb752f935752f2a0eec0ab017facab9ef/src/main/java/io/mycat/memory/unsafe/ringbuffer/common/sequence/Sequence.java#L29-L65","documentation":"The static initializer of io.mycat.memory.unsafe.ringbuffer.common.Sequence resolves the offset of the inner Value.value field via sun.misc.Unsafe.objectFieldOffset(Platform). If the reflection lookup fails for any reason, the catch block rethrows it as a RuntimeException, which surfaces as an ExceptionInInitializerError wrapping this RuntimeException on first use of the class.","triggerScenarios":"Class initialization of Sequence on a JVM where Value.value cannot be reflectively accessed — e.g. a security manager denying reflection, a refactored/renamed Value class, or strict module access (JPMS) blocking sun.misc.Unsafe field access.","commonSituations":"Running on newer JDKs with strong encapsulation of internals; security policies in application servers; incompatible jar versions where the Value inner class changed.","solutions":["Run on a JDK where sun.misc.Unsafe objectFieldOffset works (or add --add-opens for the relevant package on JDK 9+)","Check the JVM security manager / policy isn't denying ReflectPermission","Verify the mycat memory jar version is consistent — no mixed versions where Value was renamed","Read the cause chain: ExceptionInInitializerError -> RuntimeException -> NoSuchFieldException tells exactly which lookup failed"],"exampleFix":"// before (JDK 16+ failure)\njava -jar app.jar\n// after\njava --add-opens java.base/java.lang=ALL-UNNAMED --add-opens java.base/jdk.internal.misc=ALL-UNNAMED -jar app.jar","handlingStrategy":"try-catch","validationCode":"try {\n    Value.class.getDeclaredField(\"value\"); // probe the reflective lookup before triggering class init\n} catch (NoSuchFieldException e) {\n    throw new IllegalStateException(\"incompatible jar: Value.value missing\", e);\n}","typeGuard":null,"tryCatchPattern":"try {\n    Sequence seq = new Sequence();\n} catch (Throwable t) {\n    Throwable cause = t.getCause(); // ExceptionInInitializerError -> RuntimeException -> reflection cause\n    throw new IllegalStateException(\"Sequence init failed on this JVM: \" + cause, t);\n}","preventionTips":["Test class init on the target JDK early; JDK 16+ may need --add-opens","Pin consistent versions of the mycat memory jars","Avoid security managers that deny ReflectPermission in this code path","Read the full cause chain — the reflection exception names the missing member"],"tags":["reflection","class-init","unsafe","jvm"],"backgroundTag":"module-init-failed","analyzedSha":"65f8d8beb752f935752f2a0eec0ab017facab9ef","analyzedAt":"2026-09-11T00:12:21.696Z","contentChangedAt":"2026-09-11T00:12:21.696Z","schemaVersion":2},"datasetVersion":"2026-09-16T04:17:20.429Z"}