{"record":{"id":"848735b4a8867e4d","repo":"mybatis/mybatis-3","slug":"not-allowed-to-update-a-nullcachekey-instance","errorCode":null,"errorMessage":"Not allowed to update a NullCacheKey instance.","messagePattern":"Not allowed to update a NullCacheKey instance\\.","errorType":"exception","errorClass":"CacheException","httpStatus":null,"severity":"error","filePath":"src/main/java/org/apache/ibatis/cache/NullCacheKey.java","lineNumber":33,"sourceCode":" */\npackage org.apache.ibatis.cache;\n\n/**\n * @author Clinton Begin\n *\n * @deprecated Since 3.5.3, This class never used and will be removed future version.\n */\n@Deprecated\npublic final class NullCacheKey extends CacheKey {\n\n  private static final long serialVersionUID = 3704229911977019465L;\n\n  public NullCacheKey() {\n  }\n\n  @Override\n  public void update(Object object) {\n    throw new CacheException(\"Not allowed to update a NullCacheKey instance.\");\n  }\n\n  @Override\n  public void updateAll(Object[] objects) {\n    throw new CacheException(\"Not allowed to update a NullCacheKey instance.\");\n  }\n}\n","sourceCodeStart":15,"sourceCodeEnd":41,"githubUrl":"https://github.com/mybatis/mybatis-3/blob/008069adb1b089579b5dcba87ee591908b263274/src/main/java/org/apache/ibatis/cache/NullCacheKey.java#L15-L41","documentation":"Thrown by the deprecated NullCacheKey class (deprecated since 3.5.3 because it is unused by the framework) when update(Object) is called on it. The class still exists for backward compatibility so old custom code constructing NullCacheKey directly does not break at class-load time, but mutation remains forbidden: a null key must stay empty to remain equal to every other null key.","triggerScenarios":"Legacy user code that does new NullCacheKey().update(x) — e.g. old custom cache decorators, executors, or tutorials targeting mybatis < 3.5.3 that instantiate NullCacheKey instead of using CacheKey.NULL_CACHE_KEY.","commonSituations":"Codebases built against very old mybatis (pre-3.4) where NullCacheKey was constructed directly; copy-pasted custom cache implementations from old blog posts; upgrading mybatis without revisiting custom cache plumbing.","solutions":["Replace new NullCacheKey() usages with the shared CacheKey.NULL_CACHE_KEY constant and never call update on it","Delete the direct instantiation entirely — the framework supplies the sentinel where needed","If you truly need a mutable empty key, use new CacheKey() instead"],"exampleFix":"// before\nCacheKey key = new NullCacheKey();\nkey.update(param);\n\n// after\nCacheKey key = new CacheKey();\nkey.update(param);","handlingStrategy":"validation","validationCode":"if (key instanceof NullCacheKey) throw new IllegalStateException(\"attempt to mutate NullCacheKey\");","typeGuard":"@Deprecated static boolean isNullKey(CacheKey k) { return k instanceof org.apache.ibatis.cache.NullCacheKey || k == CacheKey.NULL_CACHE_KEY; }","tryCatchPattern":null,"preventionTips":["Stop constructing NullCacheKey; use CacheKey.NULL_CACHE_KEY","Remove custom cache code copied from pre-3.5.3 sources"],"tags":["mybatis","cache","deprecated","sentinel"],"backgroundTag":null,"analyzedSha":"008069adb1b089579b5dcba87ee591908b263274","analyzedAt":"2026-08-14T13:07:10.264Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}