{"record":{"id":"af51ac5eb08e28e5","repo":"xpipe-io/xpipe","slug":"value-must-be-an-instance-of-classnames","errorCode":null,"errorMessage":"Value must be an instance of ${classNames}","messagePattern":"Value must be an instance of (.+?)","errorType":"validation","errorClass":"ValidationException","httpStatus":null,"severity":"error","filePath":"app/src/main/java/io/xpipe/app/util/Validators.java","lineNumber":27,"sourceCode":"\npublic class Validators {\n\n    public static <T extends DataStore> void isType(DataStoreEntryRef<? extends T> ref, Class<T> c)\n            throws ValidationException {\n        if (ref == null\n                || ref.getStore() == null\n                || !c.isAssignableFrom(ref.getStore().getClass())) {\n            throw new ValidationException(\"Value must be an instance of \" + c.getSimpleName());\n        }\n    }\n\n    public static <T extends DataStore> void isAnyType(DataStoreEntryRef<? extends T> ref, Class<?>... cs)\n            throws ValidationException {\n        if (ref == null\n                || ref.getStore() == null\n                || Arrays.stream(cs)\n                        .noneMatch(c -> c.isAssignableFrom(ref.getStore().getClass()))) {\n            throw new ValidationException(\"Value must be an instance of \"\n                    + Arrays.stream(cs).map(Class::getSimpleName).toList());\n        }\n    }\n\n    public static void nonNull(Object object) throws ValidationException {\n        if (object == null) {\n            throw new ValidationException(AppI18n.get(\"valueMustNotBeEmpty\"));\n        }\n    }\n\n    public static void nonNull(Object object, String name) throws ValidationException {\n        if (object == null) {\n            throw new ValidationException(AppI18n.get(\"mustNotBeEmpty\", name));\n        }\n    }\n\n    public static void contentNonNull(List<?> object) throws ValidationException {\n        if (object.stream().anyMatch(o -> o == null)) {","sourceCodeStart":9,"sourceCodeEnd":45,"githubUrl":"https://github.com/xpipe-io/xpipe/blob/d85ca821baa46092a320ebb13546d7240adb74f8/app/src/main/java/io/xpipe/app/util/Validators.java#L9-L45","documentation":"Validators.isAnyType(ref, cs...) validates that a store reference's store is an instance of at least one of the given classes. It throws a ValidationException listing the allowed class simple names when the ref is null, the store is null, or none of the classes match. It is the multi-type variant of isType.","triggerScenarios":"Validators.isAnyType(ref, A.class, B.class) where ref is null, the store is null, or the store's class matches neither A nor B; the message shows the Java list of allowed class names.","commonSituations":"A configuration field accepts several store kinds but the user picked a different one; a new store type was added but not included in the accepted class list; dangling reference after store deletion.","solutions":["Constrain the store selection UI to the allowed types so only matching entries can be chosen.","Add the intended store class to the varargs list if it is a legitimate new allowed type.","Guard before validating: if (ref != null && ref.getStore() != null && Arrays.stream(cs).anyMatch(c -> c.isInstance(ref.getStore()))) proceed."],"exampleFix":"// before\nValidators.isAnyType(ref, HostStore.class, ScriptStore.class);\n// after\nif (ref != null && ref.getStore() != null) {\n    Validators.isAnyType(ref, HostStore.class, ScriptStore.class);\n}","handlingStrategy":"try-catch","validationCode":"if (ref == null || ref.getStore() == null\n        || Arrays.stream(cs).noneMatch(c -> c.isInstance(ref.getStore()))) {\n    // handle before validation\n}","typeGuard":"public static boolean isAnyStoreType(DataStoreEntryRef<?> ref, Class<?>... cs) {\n    return ref != null && ref.getStore() != null\n        && Arrays.stream(cs).anyMatch(c -> c.isInstance(ref.getStore()));\n}","tryCatchPattern":"try {\n    Validators.isAnyType(ref, AStore.class, BStore.class);\n} catch (ValidationException e) {\n    // store matches none of the allowed types\n}","preventionTips":["Keep the allowed-type list in sync with all accepted store kinds","Constrain selection UI to the accepted classes","Null-check refs before batch validation"],"tags":["java","validation","type-check","datastore"],"backgroundTag":"type-mismatch","analyzedSha":"d85ca821baa46092a320ebb13546d7240adb74f8","analyzedAt":"2026-09-06T14:30:08.251Z","contentChangedAt":"2026-09-06T14:30:08.251Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}