alibaba/spring-ai-alibaba · error · IllegalArgumentException
oss object name is invalid
Error message
oss object name is invalid
What it means
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.
Source
Thrown at spring-ai-alibaba-admin/spring-ai-alibaba-admin-server-core/src/main/java/com/alibaba/cloud/ai/studio/core/base/manager/OssManager.java:210
*/
public void downloadFile(String objectName, String path) {
long start = System.currentTimeMillis();
try {
String bucketName = getBucket();
ossClientInternal.getObject(new GetObjectRequest(bucketName, objectName), new File(path));
LogUtils.monitor("ossManager", "downloadFile", start, SUCCESS, path, objectName, path);
}
catch (Exception e) {
LogUtils.monitor("ossManager", "downloadFile", start, SUCCESS, path, e.getMessage(), e);
throw new BizException(ErrorCode.OSS_DOWNLOAD_ERROR.toError(), e);
}
}
public String generateURL(String objectName) {
long start = System.currentTimeMillis();
String safeObjectName = trimObjectName(objectName);
if (StringUtils.isBlank(objectName)) {
throw new IllegalArgumentException("oss object name is invalid");
}
try {
String bucketName = getBucket();
Date expiration = new Date(System.currentTimeMillis() + URl_EXPIRE_TIME.toMillis());
URL url = ossClient.generatePresignedUrl(bucketName, safeObjectName, expiration);
LogUtils.monitor("ossManager", "generateURL", start, SUCCESS, objectName, url);
return url.toString().replace("http://", "https://");
}
catch (Exception e) {
LogUtils.monitor("ossManager", "generateURL", start, SUCCESS, objectName, null, e);
throw new BizException(ErrorCode.OSS_GEN_URL_ERROR.toError(), e);
}
}
/**
* download file as string
* @param objectName object nameView on GitHub (pinned to f82da0b50f)
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
Example fix
// before
String url = ossManager.generateURL(record.getObjectName());
// after
String objectName = record.getObjectName();
if (objectName == null || objectName.isBlank()) {
throw new IllegalStateException("Record has no uploaded object");
}
String url = ossManager.generateURL(objectName); Defensive patterns
Strategy: validation
Validate before calling
if (objectName == null || objectName.isBlank()) {
throw new IllegalArgumentException("objectName required before generating URL");
} Type guard
boolean isValidObjectName(String objectName) {
return objectName != null && !objectName.isBlank();
} Try / catch
try {
return ossManager.generateURL(objectName);
} catch (IllegalArgumentException e) {
if (e.getMessage().contains("oss object name is invalid")) {
return null; // or default URL
}
throw e;
} Prevention
- 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
When it happens
Trigger: Calling generateURL(null) or generateURL("") or generateURL(" ") — typically when the object key comes from an upstream record whose objectName column is empty.
Common situations: 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.
Related errors
- Experiment ID cannot be null
- Evaluator version ID cannot be null
- OSS_UPLOAD_ERROR
- OSS_DOWNLOAD_ERROR
- OSS_GEN_URL_ERROR
AI-assisted analysis of alibaba/spring-ai-alibaba@f82da0b50f (2026-09-09).
Data as JSON: /api/errors/19eab82588086d9f.
Report an issue: GitHub.