mybatis/mybatis-3 · warning · ReflectionException

The DefaultObjectWrapperFactory should never be called to pr

Error message

The DefaultObjectWrapperFactory should never be called to provide an ObjectWrapper.

What it means

DefaultObjectWrapperFactory is MyBatis's no-op ObjectWrapperFactory: hasWrapperFor always returns false, meaning it never supplies wrappers, and MetaObject therefore never calls getWrapperFor on it. If getWrapperFor is invoked anyway (direct call or a subclass/misuse that bypasses hasWrapperFor), it throws a ReflectionException stating it should never be called. This is a guard against incorrect API usage, not a runtime data problem.

Source

Thrown at src/main/java/org/apache/ibatis/reflection/wrapper/DefaultObjectWrapperFactory.java:33

 */
package org.apache.ibatis.reflection.wrapper;

import org.apache.ibatis.reflection.MetaObject;
import org.apache.ibatis.reflection.ReflectionException;

/**
 * @author Clinton Begin
 */
public class DefaultObjectWrapperFactory implements ObjectWrapperFactory {

  @Override
  public boolean hasWrapperFor(Object object) {
    return false;
  }

  @Override
  public ObjectWrapper getWrapperFor(MetaObject metaObject, Object object) {
    throw new ReflectionException(
        "The DefaultObjectWrapperFactory should never be called to provide an ObjectWrapper.");
  }

}

View on GitHub (pinned to 008069adb1)

Solutions

  1. Always gate getWrapperFor with hasWrapperFor(object) returning true (the DefaultObjectWrapperFactory contract)
  2. Provide your own ObjectWrapperFactory implementation if you need custom wrapping
  3. Remove direct calls to DefaultObjectWrapperFactory.getWrapperFor; rely on MetaObject/ObjectWrapperFactory.DEFAULT

Example fix

// before
ObjectWrapper w = factory.getWrapperFor(metaObject, obj); // throws on DefaultObjectWrapperFactory

// after
ObjectWrapper w = factory.hasWrapperFor(obj)
    ? factory.getWrapperFor(metaObject, obj)
    : MetaObject.forObject(obj, objectFactory, factory, reflectorFactory).getObjectWrapper();
Defensive patterns

Strategy: validation

Validate before calling

if (factory.hasWrapperFor(object)) {
  wrapper = factory.getWrapperFor(metaObject, object);
} else {
  // fall back to standard MetaObject wrapping; never call getWrapperFor on DefaultObjectWrapperFactory directly
}

Prevention

When it happens

Trigger: Directly calling new DefaultObjectWrapperFactory().getWrapperFor(metaObject, obj); custom code that iterates ObjectWrapperFactory instances calling getWrapperFor unconditionally without checking hasWrapperFor first.

Common situations: Custom reflection utilities built on MetaObject internals; copy-pasted framework code that assumes every factory produces wrappers; tests poking at wrapper factories directly.

Related errors


AI-assisted analysis of mybatis/mybatis-3@008069adb1 (2026-08-14). Data as JSON: /api/errors/63d6067bf1ccfc27. Report an issue: GitHub.