{"record":{"id":"31997165763af01e","repo":"flowable/flowable-engine","slug":"invalid-attachment-type-value-getclass","errorCode":null,"errorMessage":"Invalid attachment type: \" + value.getClass() + \" for \" + variableContainer","messagePattern":"Invalid attachment type: \" \\+ value\\.getClass\\(\\) \\+ \" for \" \\+ variableContainer","errorType":"exception","errorClass":"FlowableException","httpStatus":null,"severity":"error","filePath":"modules/flowable-engine-common/src/main/java/org/flowable/common/engine/impl/mail/BaseMailActivityDelegate.java","lineNumber":209,"sourceCode":"\n        } else if (value instanceof DataSource dataSource) {\n            message.addAttachment(dataSource);\n\n        } else if (value instanceof DataSource[] dataSources) {\n            for (DataSource dataSource : dataSources) {\n                addExpressionValueAttachment(message, dataSource, variableContainer);\n            }\n\n        } else if (value instanceof ContentItem contentItem) {\n            message.addAttachment(new ContentItemDataSourceWrapper(contentItem, getContentService()));\n\n        } else if (value instanceof ContentItem[] contentItems) {\n            for (ContentItem contentItem : contentItems) {\n                addExpressionValueAttachment(message, contentItem, variableContainer);\n            }\n\n        } else {\n            throw new FlowableException(\"Invalid attachment type: \" + value.getClass() + \" for \" + variableContainer);\n        }\n\n    }\n\n    protected String getStringFromField(Expression expression, V variableContainer) {\n        if (expression != null) {\n            Object value = expression.getValue(variableContainer);\n            if (value != null) {\n                return value.toString();\n            }\n        }\n        return null;\n    }\n\n    protected Collection<String> parseRecipients(Expression expression, V variableContainer) {\n        if (expression == null) {\n            return Collections.emptyList();\n        }","sourceCodeStart":191,"sourceCodeEnd":227,"githubUrl":"https://github.com/flowable/flowable-engine/blob/d6d39ce1c69ff244f2d9dc6af756a9b95e865586/modules/flowable-engine-common/src/main/java/org/flowable/common/engine/impl/mail/BaseMailActivityDelegate.java#L191-L227","documentation":"Mail attachments supplied via the 'attachments' expression must be of a supported type (String file path, File, ContentItem, or ContentItem[]). addExpressionValueAttachment throws FlowableException when the attachment expression resolves to any other class. The message includes the offending value's class to aid diagnosis.","triggerScenarios":"The attachments field expression evaluates to an unsupported type, e.g. a byte[], an InputStream, a List<ContentItem> (not an array), a POJO, or a Collection returned by an expression.","commonSituations":"Passing a java.util.List or List of ContentItem from a variable instead of a ContentItem[] array; passing raw byte[] of file data; passing the wrong variable from a previous service task.","solutions":["Convert the attachment value to the supported types: String path, java.io.File, ContentItem, or ContentItem[]","If you have a List<ContentItem>, convert with list.toArray(new ContentItem[0]) before assigning","Store binary content as a ContentItem via the content engine rather than byte[] when using mail attachments"],"exampleFix":"// before\nexecution.setVariable(\"attachments\", contentItemList); // List<ContentItem>\n// after\nexecution.setVariable(\"attachments\", contentItemList.toArray(new ContentItem[0]));","handlingStrategy":"type-guard","validationCode":"Object att = execution.getVariable(\"attachments\");\nboolean ok = att instanceof String || att instanceof java.io.File\n    || att instanceof ContentItem || att instanceof ContentItem[];\nif (!ok) throw new IllegalArgumentException(\"Unsupported attachment type: \" + att.getClass());","typeGuard":"boolean isSupportedAttachment(Object v) {\n    return v instanceof String || v instanceof java.io.File\n        || v instanceof ContentItem || v instanceof ContentItem[];\n}","tryCatchPattern":"try {\n    // mail task with attachments\n} catch (FlowableException e) {\n    if (e.getMessage().startsWith(\"Invalid attachment type\")) {\n        // convert variable to ContentItem[] before retrying\n    }\n    throw e;\n}","preventionTips":["Store attachments as ContentItem or ContentItem[] process variables","Convert List<ContentItem> to arrays before assigning","Avoid byte[]/InputStream variables for mail attachments"],"tags":["email","attachments","type-mismatch"],"backgroundTag":"type-mismatch","analyzedSha":"d6d39ce1c69ff244f2d9dc6af756a9b95e865586","analyzedAt":"2026-09-11T06:41:19.413Z","contentChangedAt":"2026-09-11T06:41:19.413Z","schemaVersion":2},"datasetVersion":"2026-09-18T11:17:12.947Z"}