{"record":{"id":"97725f36108adfd7","repo":"xpipe-io/xpipe","slug":"value-must-be-an-instance-of-classname","errorCode":null,"errorMessage":"Value must be an instance of ${className}","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":17,"sourceCode":"package io.xpipe.app.util;\n\nimport io.xpipe.app.core.AppI18n;\nimport io.xpipe.app.storage.DataStoreEntryRef;\nimport io.xpipe.app.store.DataStore;\n\nimport java.util.Arrays;\nimport java.util.List;\n\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        }","sourceCodeStart":1,"sourceCodeEnd":35,"githubUrl":"https://github.com/xpipe-io/xpipe/blob/d85ca821baa46092a320ebb13546d7240adb74f8/app/src/main/java/io/xpipe/app/util/Validators.java#L1-L35","documentation":"Validators.isType(DataStoreEntryRef ref, Class c) validates that a store reference points to a store of the expected type. It throws a ValidationException when the ref is null, the referenced store is null, or the store's class is not assignable from c. This guards option/configuration fields that must reference a specific DataStore implementation.","triggerScenarios":"Calling Validators.isType(ref, SomeStore.class) where ref is null, ref.getStore() is null, or the referenced entry's store is a different DataStore subclass than c.","commonSituations":"A user selected a connection of the wrong kind in a dialog (e.g. a generic store where an SSH connection is required); a store entry was deleted so the ref dangles; validation runs before the store is resolved.","solutions":["Ensure the user/config selects a store entry of the required type before validation runs.","Check the reference before validating: if (ref != null && c.isInstance(ref.getStore())) proceed.","Restrict the store picker to entries matching the required store class so invalid selections cannot occur."],"exampleFix":"// before\nValidators.isType(ref, ScriptStore.class);\n// after\nif (ref != null && ref.getStore() != null && ScriptStore.class.isInstance(ref.getStore())) {\n    Validators.isType(ref, ScriptStore.class);\n}","handlingStrategy":"try-catch","validationCode":"if (ref == null || ref.getStore() == null || !c.isInstance(ref.getStore())) {\n    // resolve or reject before calling Validators.isType\n}","typeGuard":"public static <T extends DataStore> boolean isStoreType(DataStoreEntryRef<?> ref, Class<T> c) {\n    return ref != null && ref.getStore() != null && c.isInstance(ref.getStore());\n}","tryCatchPattern":"try {\n    Validators.isType(ref, MyStore.class);\n} catch (ValidationException e) {\n    // wrong or dangling store type; ask user to reselect\n}","preventionTips":["Restrict store pickers to entries of the required store class","Resolve references before validation runs","Handle store deletion so dangling refs are cleaned up"],"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"}