Tencent/QMUI_Android · error · IllegalStateException

customFactory must implement interface QMUISchemeFragmentFac

Error message

customFactory must implement interface QMUISchemeFragmentFactory.

What it means

The fragment-side counterpart of error 24: generateCustomFactory requires that for fragment schemes (isActivity == false) the customFactory class implements QMUISchemeFragmentFactory. The processor throws IllegalStateException when the subtype check fails.

Source

Thrown at arch-compiler/src/main/java/com/qmuiteam/qmui/arch/SchemeProcessor.java:347

            builder.add("}");
        }
        return builder.build();
    }


    private CodeBlock generateCustomFactory(boolean isActivity, AnnotationMirror annotationMirror){
        AnnotationValue customFactory = getAnnotationValue(annotationMirror, "customFactory");
        if (customFactory == null) {
            return CodeBlock.of("null");
        }
        TypeMirror typeMirror = (TypeMirror) customFactory.getValue();
        if(isActivity){
            if (!isSubtypeOfType(typeMirror, QMUISchemeIntentFactoryType)) {
                throw new IllegalStateException("customFactory must implement interface QMUISchemeIntentFactory.");
            }
        }else{
            if (!isSubtypeOfType(typeMirror, QMUISchemeFragmentFactoryType)) {
                throw new IllegalStateException("customFactory must implement interface QMUISchemeFragmentFactory.");
            }
        }

        return CodeBlock.of("$T.class", typeMirror);
    }

    private CodeBlock generateCustomMatcher(AnnotationMirror annotationMirror){
        AnnotationValue customFactory = getAnnotationValue(annotationMirror, "customMatcher");
        if (customFactory == null) {
            return CodeBlock.of("null");
        }
        TypeMirror typeMirror = (TypeMirror) customFactory.getValue();
        if (!isSubtypeOfType(typeMirror, QMUISchemeMatcherType)) {
            throw new IllegalStateException("customMatcher must implement interface QMUISchemeMatcher.");
        }

        return CodeBlock.of("$T.class", typeMirror);
    }

View on GitHub (pinned to 026e7d4866)

Solutions

  1. Implement QMUISchemeFragmentFactory in the customFactory class used by the fragment scheme.
  2. If it is actually an activity factory, move it to the activity's scheme annotation and create a fragment-specific factory.
  3. Confirm the correct QMUISchemeFragmentFactory import is used in the factory class declaration.

Example fix

// before
class MyFragmentFactory : QMUISchemeIntentFactory { ... } // wrong interface

// after
class MyFragmentFactory : QMUISchemeFragmentFactory { override fun create(fragment: QMUIFragment, ...): QMUIFragment? = ... }
Defensive patterns

Strategy: validation

Validate before calling

fun validateFragmentFactory(cls: Class<*>) =
    check(QMUISchemeFragmentFactory::class.java.isAssignableFrom(cls)) { "${cls.name} must implement QMUISchemeFragmentFactory" }

Type guard

fun isValidFragmentFactory(cls: Class<*>): Boolean =
    QMUISchemeFragmentFactory::class.java.isAssignableFrom(cls)

Prevention

When it happens

Trigger: Annotating a Fragment with a scheme annotation whose customFactory element references a class that does not implement QMUISchemeFragmentFactory.

Common situations: Reusing an activity's QMUISchemeIntentFactory implementation for a fragment scheme; factory class lost its interface after refactoring; wrong import of the factory interface.

Understand the failure class

Background: Type mismatch errors: IllegalArgumentException, TypeError and type guards across 150 open-source libraries — this error's family across 150 libraries.

Related errors


AI-assisted analysis of Tencent/QMUI_Android@026e7d4866 (2026-09-06). Data as JSON: /api/errors/b4b3df1698a31d10. Report an issue: GitHub.