quarkusio/quarkus · error · UnsupportedOperationException
Cannot use `" + methodName + "` method without a default typ
Error message
Cannot use `" + methodName + "` method without a default type configured. Consider using the `" + methodName + "` method accepting the type or configure the default type for the cache " + getName()
What it means
RedisCacheImpl stores values as encoded bytes; to decode on read it needs a value Class (classOfValue), which comes from build-time value-type configuration. The type-less convenience methods (get(key, loader), getAsync, getOrDefault, getOrNull) call enforceDefaultType and fail with UnsupportedOperationException when no default type was configured for the cache.
Source
Thrown at extensions/redis-cache/runtime/src/main/java/io/quarkus/cache/redis/runtime/RedisCacheImpl.java:305
public <K, V> Uni<Void> put(K key, V value) {
return put(key, new StaticSupplier<>(value));
}
@Override
public <K, V> Uni<Void> put(K key, Supplier<V> supplier) {
byte[] encodedKey = marshaller.encode(computeActualKey(encodeKey(key)));
byte[] encodedValue = marshaller.encode(supplier.get());
return withConnection(new Function<RedisConnection, Uni<Void>>() {
@Override
public Uni<Void> apply(RedisConnection connection) {
return set(connection, encodedKey, encodedValue);
}
});
}
private void enforceDefaultType(String methodName) {
if (classOfValue == null) {
throw new UnsupportedOperationException("Cannot use `" + methodName + "` method without a default type configured. "
+ "Consider using the `" + methodName
+ "` method accepting the type or configure the default type for the cache "
+ getName());
}
}
@Override
public <K, V> Uni<V> getOrDefault(K key, V defaultValue) {
enforceDefaultType("getOrDefault");
return getOrDefault(key, classOfValue, defaultValue);
}
@Override
public <K, V> Uni<V> getOrDefault(K key, Class<V> clazz, V defaultValue) {
return getOrDefault(key, (Type) clazz, defaultValue);
}
@OverrideView on GitHub (pinned to e1c734241f)
Solutions
- Set quarkus.cache.redis.<cacheName>.value-type=... in configuration so the default type is known
- Use the typed API variant: cache.get(key, MyType.class, loader) instead of the untyped get(key, loader)
- Add a @CacheResult-annotated method so the value type is inferred at build time
- Cast through the typed Cache interface and always pass the value Class explicitly
Example fix
// before V v = redisCache.get(key, k -> load(k)); // after V v = redisCache.get(key, MyType.class, k -> load(k));
Defensive patterns
Strategy: validation
Validate before calling
// before using untyped API
if (System.getProperty("quarkus.cache.redis.my-cache.value-type") == null) {
// use typed API instead
cache.get(key, MyType.class, loader);
} Try / catch
try {
cache.get(key, loader);
} catch (UnsupportedOperationException e) {
// fall back to typed overload
cache.get(key, MyType.class, loader);
} Prevention
- Always configure quarkus.cache.redis.<name>.value-type for programmatically used caches
- Prefer the typed get(key, Class, loader) overloads by default
- Add integration tests that touch each named cache
When it happens
Trigger: Calling cache.get(key, loader), getAsync, getOrDefault, or getOrNull on a Redis cache whose value type was not configured at build time (no quarkus.cache.redis.<cache>.value-type and no inferable @CacheResult type).
Common situations: Programmatically created/obtained caches (CacheManager.getCache) used with the untyped API; configuration-only caches without any annotated method; tests obtaining caches by name.
Related errors
- No datasource named '<dataSourceName>' exists
- Proxy configuration with name ${key} was requested but quark
- Unable to determine the value type for '" + cacheName + "' R
- Cannot cache `null` value
- Failed to load application configuration
AI-assisted analysis of quarkusio/quarkus@e1c734241f (2026-09-05).
Data as JSON: /api/errors/97e3d9583ecc106c.
Report an issue: GitHub.