quarkusio/quarkus · error · IllegalArgumentException

Not a valid type:

Error message

Not a valid type: 

What it means

ArC's Instance support utility getRequiredType(Type) unwraps Provider-like types (Instance, Provider, etc.): if the type is parameterized and its raw type is assignable to Provider, it returns the first type argument; otherwise it throws IllegalArgumentException('Not a valid type: ...'). It signals that a type passed where a Provider-style required type was expected is not parameterized appropriately.

Source

Thrown at independent-projects/arc/runtime/src/main/java/io/quarkus/arc/impl/InstanceImpl.java:396

            return delegate.hasNext();
        }

        @SuppressWarnings("unchecked")
        @Override
        public InstanceHandle<H> next() {
            return getHandle((InjectableBean<H>) delegate.next());
        }

    }

    private static Type getRequiredType(final Type type) {
        if (isParameterizedType(type)) {
            final ParameterizedType parameterizedType = asParameterizedType(type);
            if (Provider.class.isAssignableFrom(Types.getRawType(parameterizedType.getRawType()))) {
                return parameterizedType.getActualTypeArguments()[0];
            }
        }
        throw new IllegalArgumentException("Not a valid type: " + type);
    }

    private boolean isGetCached(Set<Annotation> annotations) {
        for (Annotation annotation : annotations) {
            if (annotation.annotationType().equals(WithCaching.class)) {
                return true;
            }
        }
        return false;
    }

}

View on GitHub (pinned to e1c734241f)

Solutions

  1. Pass the parameterized type (Instance<Foo>, Provider<Foo>) so the actual type argument can be extracted
  2. If you don't need lazy lookup, pass the payload type Foo directly instead of the Provider wrapper
  3. Fix reflection code to capture generic super type information (TypeLiteral/ParameterizedType) instead of raw Class

Example fix

// before
getRequiredType(Instance.class); // IAE
// after
getRequiredType(new TypeLiteral<Instance<Foo>>() {}.getType());
Defensive patterns

Strategy: validation

Validate before calling

static void requireProviderType(Type type) {
    if (!(type instanceof ParameterizedType pt)
        || !Provider.class.isAssignableFrom(Types.getRawType(pt.getRawType()))) {
        throw new IllegalArgumentException("Expected parameterized Provider/Instance type: " + type);
    }
}

Type guard

static boolean isValidRequiredType(Type t) {
    return t instanceof ParameterizedType pt
        && Provider.class.isAssignableFrom(io.quarkus.arc.impl.Types.getRawType(pt.getRawType()));
}

Try / catch

try {
    Type required = getRequiredType(type);
} catch (IllegalArgumentException e) {
    if (e.getMessage().startsWith("Not a valid type")) {
        throw new IllegalStateException("Pass a parameterized Instance<Foo>/Provider<Foo> type", e);
    }
    throw e;
}

Prevention

When it happens

Trigger: Calling ArC programmatic APIs (e.g. Arc.container().instance(...)/forInjection paths) with a raw (non-parameterized) Instance/Provider type, or a type that does not implement Provider at all.

Common situations: Programmatic container lookups built from reflection where the generic parameter was lost (raw Instance instead of Instance<Foo>); wiring helper code that passes the wrapper type rather than the payload type.

Related errors


AI-assisted analysis of quarkusio/quarkus@e1c734241f (2026-09-05). Data as JSON: /api/errors/006af2aa9a31dda0. Report an issue: GitHub.