diff --git a/src/main/java/com/aliyun/oss/internal/OSSObjectOperation.java b/src/main/java/com/aliyun/oss/internal/OSSObjectOperation.java index 4cc0e266..54a3a4de 100644 --- a/src/main/java/com/aliyun/oss/internal/OSSObjectOperation.java +++ b/src/main/java/com/aliyun/oss/internal/OSSObjectOperation.java @@ -941,7 +941,10 @@ public boolean doesObjectExistWithRedirect(GenericRequest genericRequest) throws ossObject = this.getObject(getObjectRequest); return true; } catch (OSSException e) { - if (e.getErrorCode().equals(OSSErrorCode.NO_SUCH_BUCKET) || e.getErrorCode().equals(OSSErrorCode.NO_SUCH_KEY)) { + String errorCode = e.getErrorCode(); + if (errorCode != null && + (errorCode.equals(OSSErrorCode.NO_SUCH_BUCKET) || + errorCode.equals(OSSErrorCode.NO_SUCH_KEY))) { return false; } throw e;