{"record":{"id":"0a5f85e8d8313e05","repo":"alibaba/spring-ai-alibaba","slug":"graphname-cannot-be-null-or-empty","errorCode":null,"errorMessage":"graphName cannot be null or empty","messagePattern":"graphName cannot be null or empty","errorType":"http","errorClass":"ResponseStatusException","httpStatus":400,"severity":"warning","filePath":"spring-ai-alibaba-studio/src/main/java/com/alibaba/cloud/ai/agent/studio/controller/GraphController.java","lineNumber":75,"sourceCode":"\t * @return A list of graph names.\n\t */\n\t@GetMapping(\"/list-graphs\")\n\tpublic List<String> listGraphs() {\n\t\tList<String> graphNames = graphLoader.listGraphs();\n\t\tlog.debug(\"Listing graphs. Found: {}\", graphNames);\n\t\treturn graphNames.stream().sorted().collect(toList());\n\t}\n\n\t/**\n\t * Returns the graph representation (Mermaid format) for the given graph name.\n\t *\n\t * @param graphName The name of the graph.\n\t * @return GraphResponse containing the Mermaid diagram source.\n\t */\n\t@GetMapping(\"/graphs/{graphName}/representation\")\n\tpublic GraphResponse getGraphRepresentation(@PathVariable String graphName) {\n\t\tif (graphName == null || graphName.isBlank()) {\n\t\t\tthrow new ResponseStatusException(org.springframework.http.HttpStatus.BAD_REQUEST,\n\t\t\t\t\t\"graphName cannot be null or empty\");\n\t\t}\n\t\ttry {\n\t\t\tCompiledGraph graph = graphLoader.loadGraph(graphName);\n\t\t\tString title = graph.stateGraph != null ? graph.stateGraph.getName() : graphName;\n\t\t\tGraphRepresentation repr = graph.getGraph(GraphRepresentation.Type.MERMAID, title);\n\t\t\treturn new GraphResponse(repr.content(), true);\n\t\t}\n\t\tcatch (Exception e) {\n\t\t\tlog.warn(\"Failed to get graph representation for: {}\", graphName, e);\n\t\t\tthrow new ResponseStatusException(org.springframework.http.HttpStatus.NOT_FOUND,\n\t\t\t\t\t\"Graph not found: \" + graphName, e);\n\t\t}\n\t}\n}\n","sourceCodeStart":57,"sourceCodeEnd":91,"githubUrl":"https://github.com/alibaba/spring-ai-alibaba/blob/f82da0b50f35744c13968191be2b1cd2452ef550/spring-ai-alibaba-studio/src/main/java/com/alibaba/cloud/ai/agent/studio/controller/GraphController.java#L57-L91","documentation":"GraphController.getGraphRepresentation validates the {graphName} path variable and throws a 400 BAD_REQUEST ResponseStatusException when it is null or blank before attempting to load the graph. In practice the path variable can only be blank when an empty path segment is requested.","triggerScenarios":"GET /graphs/{graphName}/representation with an empty/whitespace graphName path segment (e.g. /graphs/%20/representation).","commonSituations":"Client templates with an unfilled graphName variable producing an empty segment; URL-encoded whitespace; proxies stripping path segments.","solutions":["Ensure the client passes a real graph name in the URL path.","Trim/validate graphName client-side before building the URL.","List available graphs first (graphLoader.listGraphs()) and pick a valid one."],"exampleFix":"// before\nfetch(`/graphs/${graphName}/representation`);\n// after\nif (!graphName?.trim()) throw new Error('graphName required');\nfetch(`/graphs/${encodeURIComponent(graphName)}/representation`);","handlingStrategy":"validation","validationCode":"// client-side, before the request\nif (typeof graphName !== 'string' || !graphName.trim()) {\n  throw new Error('graphName is required');\n}","typeGuard":"function hasGraphName(p) {\n  return typeof p.graphName === 'string' && p.graphName.trim().length > 0;\n}","tryCatchPattern":"try {\n  const res = await fetch(`/graphs/${encodeURIComponent(graphName)}/representation`);\n  if (!res.ok) throw new Error(res.status + ' ' + (await res.text()));\n} catch (e) {\n  if (e.message.startsWith('400')) { /* fix graphName param */ }\n}","preventionTips":["Interpolate non-empty, trimmed graphName values into URLs.","Encode path segments with encodeURIComponent.","Check router params for undefined before building URLs."],"tags":["http-400","rest","validation"],"backgroundTag":"empty-required-field","analyzedSha":"f82da0b50f35744c13968191be2b1cd2452ef550","analyzedAt":"2026-09-09T15:32:42.421Z","contentChangedAt":"2026-09-09T15:32:42.421Z","schemaVersion":2},"datasetVersion":"2026-09-17T15:17:12.973Z"}