{"record":{"id":"22c32ffd3a4b9d0f","repo":"mybatis/mybatis-3","slug":"error-building-standard-cache-decorators-cause","errorCode":null,"errorMessage":"Error building standard cache decorators.  Cause: {}","messagePattern":"Error building standard cache decorators\\.  Cause: (.+?)","errorType":"exception","errorClass":"CacheException","httpStatus":null,"severity":"error","filePath":"src/main/java/org/apache/ibatis/mapping/CacheBuilder.java","lineNumber":138,"sourceCode":"      MetaObject metaCache = SystemMetaObject.forObject(cache);\n      if (size != null && metaCache.hasSetter(\"size\")) {\n        metaCache.setValue(\"size\", size);\n      }\n      if (clearInterval != null) {\n        cache = new ScheduledCache(cache);\n        ((ScheduledCache) cache).setClearInterval(clearInterval);\n      }\n      if (readWrite) {\n        cache = new SerializedCache(cache);\n      }\n      cache = new LoggingCache(cache);\n      cache = new SynchronizedCache(cache);\n      if (blocking) {\n        cache = new BlockingCache(cache);\n      }\n      return cache;\n    } catch (Exception e) {\n      throw new CacheException(\"Error building standard cache decorators.  Cause: \" + e, e);\n    }\n  }\n\n  private void setCacheProperties(Cache cache) {\n    if (properties != null) {\n      MetaObject metaCache = SystemMetaObject.forObject(cache);\n      for (Map.Entry<Object, Object> entry : properties.entrySet()) {\n        String name = (String) entry.getKey();\n        String value = (String) entry.getValue();\n        if (metaCache.hasSetter(name)) {\n          Class<?> type = metaCache.getSetterType(name);\n          if (String.class == type) {\n            metaCache.setValue(name, value);\n          } else if (int.class == type || Integer.class == type) {\n            metaCache.setValue(name, Integer.valueOf(value));\n          } else if (long.class == type || Long.class == type) {\n            metaCache.setValue(name, Long.valueOf(value));\n          } else if (short.class == type || Short.class == type) {","sourceCodeStart":120,"sourceCodeEnd":156,"githubUrl":"https://github.com/mybatis/mybatis-3/blob/008069adb1b089579b5dcba87ee591908b263274/src/main/java/org/apache/ibatis/mapping/CacheBuilder.java#L120-L156","documentation":"CacheBuilder.build() wraps its whole decorator-stack construction (FifoCache/LruCache/ScheduledCache/SerializedCache/LoggingCache/SynchronizedCache/BlockingCache plus property setting) in a try/catch and rethrows any Exception as CacheException with this message. It is a catch-all: reflection failures, property conversion errors, or cache implementation exceptions during build surface here.","triggerScenarios":"Building a cache via <cache type=\"...\"/> or CacheBuilder where any decorator step throws: a setCacheProperties conversion failure, cache class instantiation failure, ScheduledCache with bad clearInterval, or SerializedCache on a non-Serializable model class hit later during build-time checks.","commonSituations":"Custom cache implementations in mapper XML; eviction/clearInterval attributes typo'd or wrong units; readWrite=true with non-Serializable cached objects; decorator constructors throwing under different MyBatis versions.","solutions":["Inspect the chained cause — the underlying exception identifies the failing decorator or property.","If the cause mentions a property, fix the <cache> attributes (names/types must match the cache implementation's setters).","If the cause is instantiation-related, verify the cache class has the required constructors (String id, and Cache for decorators).","Simplify: temporarily remove custom attributes/decorators (readWrite, blocking, eviction) and add them back one at a time to isolate the failing setting."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"try {\n  Cache cache = new CacheBuilder(id).implementation(MyCache.class).build();\n} catch (CacheException e) {\n  throw new ConfigurationException(\"Cache '\" + id + \"' misconfigured: \" + e.getCause(), e);\n}","preventionTips":["Build custom caches first in a unit test with the same <cache> attributes as production XML.","Keep attribute names/types aligned with the cache implementation's setters (primitive/String only).","Add the custom cache configuration to integration tests so it is exercised at every build."],"tags":["mybatis","cache","configuration"],"backgroundTag":null,"analyzedSha":"008069adb1b089579b5dcba87ee591908b263274","analyzedAt":"2026-08-14T13:07:10.264Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}