{"record":{"id":"67af0d4143fa13b9","repo":"Activiti/Activiti","slug":"error-while-generating-process-image","errorCode":null,"errorMessage":"Error while generating process image","messagePattern":"Error while generating process image","errorType":"exception","errorClass":"ActivitiImageException","httpStatus":null,"severity":"error","filePath":"activiti-core/activiti-image-generator/src/main/java/org/activiti/image/impl/DefaultProcessDiagramCanvas.java","lineNumber":308,"sourceCode":"    /**\n     * Generates an image of what currently is drawn on the canvas.\n     * <p>\n     * Throws an {@link ActivitiImageException} when {@link #close()} is already\n     * called.\n     */\n    public InputStream generateImage() {\n        if (closed) {\n            throw new ActivitiImageException(\"ProcessDiagramGenerator already closed\");\n        }\n\n        try {\n            ByteArrayOutputStream stream = new ByteArrayOutputStream();\n            Writer out;\n            out = new OutputStreamWriter(stream, \"UTF-8\");\n            g.stream(out, true);\n            return new ByteArrayInputStream(stream.toByteArray());\n        } catch (UnsupportedEncodingException | SVGGraphics2DIOException e) {\n            throw new ActivitiImageException(\"Error while generating process image\", e);\n        }\n    }\n\n    /**\n     * Closes the canvas which dissallows further drawing and releases graphical\n     * resources.\n     */\n    public void close() {\n        g.dispose();\n        closed = true;\n    }\n\n    public void drawNoneStartEvent(String id, String name, GraphicInfo graphicInfo) {\n        drawStartEvent(id, name, graphicInfo, null);\n    }\n\n    public void drawTimerStartEvent(String id, String name, GraphicInfo graphicInfo) {\n        drawStartEvent(id, name, graphicInfo, TIMER_IMAGE);","sourceCodeStart":290,"sourceCodeEnd":326,"githubUrl":"https://github.com/Activiti/Activiti/blob/56435b1a97deeafdc09dd40074b056c89fba5a8a/activiti-core/activiti-image-generator/src/main/java/org/activiti/image/impl/DefaultProcessDiagramCanvas.java#L290-L326","documentation":"generateImage() streams the diagram as SVG using a Graphics2D SVG adapter. If the stream operation fails — UnsupportedEncodingException for the hard-coded UTF-8 or an SVGGraphics2DIOException from the SVG library — it is wrapped in this ActivitiImageException.","triggerScenarios":"Any I/O or SVG-generation failure while writing the SVG (e.g. SVGGraphics2DIOException from invalid drawn content or an underlying stream error), or a JVM lacking the UTF-8 charset name.","commonSituations":"Diagrams containing shapes/labels that the SVG generator cannot encode; JVM with unusual charset configuration; failures deep in the Batik-based SVGGraphics2D implementation.","solutions":["Inspect the wrapped cause (getCause()) to find whether it is encoding or SVG-IO related and address that specific failure","Ensure the JVM supports UTF-8 (standard on all modern JVMs; fix any custom charset provider issues)","Simplify/fix unusual BPMN diagram elements (custom label text, exotic characters) that may break SVG generation","Upgrade Activiti's image generator or the underlying SVG library version"],"exampleFix":"// before\nInputStream is = generator.generateDiagram(bpmnModel, \"png\", activityId); // may throw\n// after\ntry {\n    InputStream is = generator.generateDiagram(bpmnModel, \"png\", activityId);\n} catch (ActivitiImageException e) {\n    logger.error(\"Diagram generation failed\", e.getCause());\n    throw e;\n}","handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"try {\n    InputStream is = canvas.generateImage();\n} catch (ActivitiImageException e) {\n    if (e.getMessage().equals(\"Error while generating process image\")) {\n        Throwable root = deepestCause(e);\n        if (root instanceof SVGGraphics2DIOException) {\n            // handle SVG encoding failure, e.g. simplify diagram content\n        }\n    } else { throw e; }\n}","preventionTips":["Log and inspect getCause() to distinguish SVGGraphics2DIOException from encoding problems","Avoid exotic characters/custom content in diagram labels that may break SVG output","Run diagram generation on standard JVMs with normal charset configuration"],"tags":["svg","image-generation","diagram"],"backgroundTag":"http-request-failed","analyzedSha":"56435b1a97deeafdc09dd40074b056c89fba5a8a","analyzedAt":"2026-09-09T21:00:06.703Z","contentChangedAt":"2026-09-09T21:00:06.703Z","schemaVersion":2},"datasetVersion":"2026-09-17T15:17:12.973Z"}