{"record":{"id":"19eab82588086d9f","repo":"alibaba/spring-ai-alibaba","slug":"oss-object-name-is-invalid","errorCode":null,"errorMessage":"oss object name is invalid","messagePattern":"oss object name is invalid","errorType":"validation","errorClass":"IllegalArgumentException","httpStatus":500,"severity":"error","filePath":"spring-ai-alibaba-admin/spring-ai-alibaba-admin-server-core/src/main/java/com/alibaba/cloud/ai/studio/core/base/manager/OssManager.java","lineNumber":210,"sourceCode":"\t */\n\tpublic void downloadFile(String objectName, String path) {\n\t\tlong start = System.currentTimeMillis();\n\t\ttry {\n\t\t\tString bucketName = getBucket();\n\t\t\tossClientInternal.getObject(new GetObjectRequest(bucketName, objectName), new File(path));\n\t\t\tLogUtils.monitor(\"ossManager\", \"downloadFile\", start, SUCCESS, path, objectName, path);\n\t\t}\n\t\tcatch (Exception e) {\n\t\t\tLogUtils.monitor(\"ossManager\", \"downloadFile\", start, SUCCESS, path, e.getMessage(), e);\n\t\t\tthrow new BizException(ErrorCode.OSS_DOWNLOAD_ERROR.toError(), e);\n\t\t}\n\t}\n\n\tpublic String generateURL(String objectName) {\n\t\tlong start = System.currentTimeMillis();\n\t\tString safeObjectName = trimObjectName(objectName);\n\t\tif (StringUtils.isBlank(objectName)) {\n\t\t\tthrow new IllegalArgumentException(\"oss object name is invalid\");\n\t\t}\n\n\t\ttry {\n\t\t\tString bucketName = getBucket();\n\t\t\tDate expiration = new Date(System.currentTimeMillis() + URl_EXPIRE_TIME.toMillis());\n\t\t\tURL url = ossClient.generatePresignedUrl(bucketName, safeObjectName, expiration);\n\t\t\tLogUtils.monitor(\"ossManager\", \"generateURL\", start, SUCCESS, objectName, url);\n\t\t\treturn url.toString().replace(\"http://\", \"https://\");\n\t\t}\n\t\tcatch (Exception e) {\n\t\t\tLogUtils.monitor(\"ossManager\", \"generateURL\", start, SUCCESS, objectName, null, e);\n\t\t\tthrow new BizException(ErrorCode.OSS_GEN_URL_ERROR.toError(), e);\n\t\t}\n\t}\n\n\t/**\n\t * download file as string\n\t * @param objectName object name","sourceCodeStart":192,"sourceCodeEnd":228,"githubUrl":"https://github.com/alibaba/spring-ai-alibaba/blob/f82da0b50f35744c13968191be2b1cd2452ef550/spring-ai-alibaba-admin/spring-ai-alibaba-admin-server-core/src/main/java/com/alibaba/cloud/ai/studio/core/base/manager/OssManager.java#L192-L228","documentation":"OssManager.generateURL throws a plain IllegalArgumentException('oss object name is invalid') when the objectName argument is null or blank. Note the check inspects the raw objectName while the presigned URL is built from trimObjectName(objectName); the guard exists to prevent generating presigned URLs for empty keys. It is an unchecked exception, not a BizException.","triggerScenarios":"Calling generateURL(null) or generateURL(\"\") or generateURL(\"   \") — typically when the object key comes from an upstream record whose objectName column is empty.","commonSituations":"A file record in the DB was never uploaded so its objectName field is null; a request param is missing; upstream code stores empty string instead of null after a failed upload.","solutions":["Check that objectName is non-blank before calling generateURL","Fix the upstream data so the record always holds a valid OSS key after upload","Handle the IllegalArgumentException at the call site and return a sensible default/error to clients"],"exampleFix":"// before\nString url = ossManager.generateURL(record.getObjectName());\n// after\nString objectName = record.getObjectName();\nif (objectName == null || objectName.isBlank()) {\n    throw new IllegalStateException(\"Record has no uploaded object\");\n}\nString url = ossManager.generateURL(objectName);","handlingStrategy":"validation","validationCode":"if (objectName == null || objectName.isBlank()) {\n    throw new IllegalArgumentException(\"objectName required before generating URL\");\n}","typeGuard":"boolean isValidObjectName(String objectName) {\n    return objectName != null && !objectName.isBlank();\n}","tryCatchPattern":"try {\n    return ossManager.generateURL(objectName);\n} catch (IllegalArgumentException e) {\n    if (e.getMessage().contains(\"oss object name is invalid\")) {\n        return null; // or default URL\n    }\n    throw e;\n}","preventionTips":["Validate objectName at the boundary where records are loaded","Reject or repair DB rows with null/empty objectName after a failed upload","Never generate URLs for placeholders or empty keys"],"tags":["oss","argument-validation","null"],"backgroundTag":"null-argument","analyzedSha":"f82da0b50f35744c13968191be2b1cd2452ef550","analyzedAt":"2026-09-09T15:32:42.421Z","contentChangedAt":"2026-09-09T15:32:42.421Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}