redis/jedis · error · InstantiationError

Must not instantiate this class

Error message

Must not instantiate this class

What it means

BuilderFactory is a utility class of static Builder constants for converting Redis replies into Java types. Its constructor is private and deliberately throws InstantiationError to prevent instantiation, since all functionality is exposed via static fields. This error means you (or reflection/serialization code) tried to create a new BuilderFactory instance.

Solutions

  1. Remove the `new BuilderFactory()` call and use the static Builder constants directly, e.g. `BuilderFactory.STRING`
  2. If a framework needs to instantiate it, register it as non-instantiable or exclude it from reflective instantiation
  3. If you need custom reply building, implement redis.clients.jedis.Builder yourself rather than subclassing/instantiating BuilderFactory

Example fix

// before
BuilderFactory factory = new BuilderFactory();
Object val = factory.build(data);
// after
Object val = BuilderFactory.STRING.build(data);
Defensive patterns

Strategy: validation

Validate before calling

if (factory == null || factory.getClass() == BuilderFactory.class) { /* use static constants instead of instantiating */ }

Type guard

static boolean isBuilderFactoryConstant(Object o) { return o instanceof redis.clients.jedis.Builder; }

Try / catch

try { new BuilderFactory(); } catch (InstantiationError e) { logger.warn("BuilderFactory is a static utility class; use its Builder constants"); }

Prevention

When it happens

Trigger: Calling `new BuilderFactory()` from user code, or frameworks that instantiate classes via reflection (e.g. some serializers, DI containers, or code-coverage tooling instantiating classes with private constructors).

Common situations: Accidental autocomplete-driven instantiation of a constants-only utility class; reflection-based tests requiring a constructor; serialization libraries attempting to deserialize BuilderFactory.

Understand the failure class

Background: UnsupportedOperationException and "is not supported" errors: when a library deliberately refuses a call — this error's family across 30 libraries.

Related errors


AI-assisted analysis of redis/jedis@6dac31d4c2 (2026-09-08). Data as JSON: /api/errors/ef9ec06151cc0570. Report an issue: GitHub.

Appendix: source

Thrown at src/main/java/redis/clients/jedis/BuilderFactory.java:2638

      final List<Object> list = (List<Object>) data;
      if (list.isEmpty()) return Collections.emptyList();

      final List<KeyValue<Long, byte[]>> result = new ArrayList<>(list.size());
      for (Object pair : list) {
        List<Object> entry = (List<Object>) pair;
        result.add(KeyValue.of(LONG.build(entry.get(0)), BINARY.build(entry.get(1))));
      }
      return result;
    }

    @Override
    public String toString() {
      return "List<KeyValue<Long, byte[]>>";
    }
  };

  private BuilderFactory() {
    throw new InstantiationError("Must not instantiate this class");
  }
}

View on GitHub (pinned to 6dac31d4c2)