{"record":{"id":"2ed45c55a1f84b5a","repo":"quarkusio/quarkus","slug":"form-value-is-a-string","errorCode":null,"errorMessage":"Form value is a string","messagePattern":"Form value is a string","errorType":"exception","errorClass":"RuntimeException","httpStatus":null,"severity":"error","filePath":"independent-projects/resteasy-reactive/server/runtime/src/main/java/org/jboss/resteasy/reactive/server/core/multipart/FormData.java","lineNumber":311,"sourceCode":"        }\n\n        @Override\n        public String getValue() {\n            if (value == null) {\n                throw new RuntimeException(\"Form value is a file\");\n            }\n            return value;\n        }\n\n        @Override\n        public String getCharset() {\n            return charset;\n        }\n\n        @Override\n        public FileItemImpl getFileItem() {\n            if (fileItemImpl == null) {\n                throw new RuntimeException(\"Form value is a string\");\n            }\n            return fileItemImpl;\n        }\n\n        @Override\n        public boolean isFileItem() {\n            return fileItemImpl != null;\n        }\n\n        @Override\n        public CaseInsensitiveMap<String> getHeaders() {\n            return headers;\n        }\n\n        public String getFileName() {\n            return fileName;\n        }\n    }","sourceCodeStart":293,"sourceCodeEnd":329,"githubUrl":"https://github.com/quarkusio/quarkus/blob/e1c734241f34c7919086ceb4c9262b4a58f6de44/independent-projects/resteasy-reactive/server/runtime/src/main/java/org/jboss/resteasy/reactive/server/core/multipart/FormData.java#L293-L329","documentation":"FormData.FileValue.getFileItem() throws when the form value is a plain string, not a file upload. Each multipart entry is either a string or a FileItemImpl; calling the file accessor on a string entry is invalid. A RuntimeException signals the mismatch.","triggerScenarios":"Calling getFileItem() on a FormData attribute when the part was submitted as a simple form field (no filename), or declaring a FileUpload parameter for an attribute the client sends as plain text.","commonSituations":"Client posts a field without enctype=multipart or without a file input while the endpoint expects a file; differing clients hitting the same endpoint (one text, one file); code iterating form values assuming all are files.","solutions":["Check value.isFileItem() before calling getFileItem() and fall back to getValue() for string entries.","Change the endpoint to accept String, or add a separate attribute, for the plain-text case.","Ensure the client actually sends the part as a file (multipart input with filename).","Handle both branches explicitly when reading FormData programmatically."],"exampleFix":"// before\nFileUpload file = (FileUpload) formData.get(\"note\").getFileItem(); // may be a string\n// after\nvar value = formData.get(\"note\");\nFileUpload file = value.isFileItem() ? value.getFileItem() : null;","handlingStrategy":"type-guard","validationCode":"if (!value.isFileItem()) { throw new BadRequestException(\"expected a file upload\"); }","typeGuard":"boolean isFile(FormData.FormValue v) { return v != null && v.isFileItem(); }","tryCatchPattern":"try { return value.getFileItem(); } catch (RuntimeException e) { if (\"Form value is a string\".equals(e.getMessage())) return null; throw e; }","preventionTips":["Require enctype=multipart/form-data on client forms","Verify parts include a filename","Check isFileItem() before getFileItem()","Declare FileUpload parameters only for true file parts"],"tags":["multipart","form-data","rest"],"backgroundTag":"form-value-type-mismatch","analyzedSha":"e1c734241f34c7919086ceb4c9262b4a58f6de44","analyzedAt":"2026-09-05T17:01:29.979Z","contentChangedAt":"2026-09-05T17:01:29.979Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}