Skip to content

Commit b2ec044

Browse files
committed
fix doesObjectExist bug.
1 parent 9bb64d5 commit b2ec044

File tree

2 files changed

+8
-1
lines changed

2 files changed

+8
-1
lines changed

src/main/java/com/aliyun/oss/internal/OSSObjectOperation.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -963,7 +963,7 @@ public boolean doesObjectExistWithRedirect(GenericRequest genericRequest) throws
963963
ossObject = this.getObject(getObjectRequest);
964964
return true;
965965
} catch (OSSException e) {
966-
if (e.getErrorCode() == OSSErrorCode.NO_SUCH_BUCKET || e.getErrorCode() == OSSErrorCode.NO_SUCH_KEY) {
966+
if (e.getErrorCode().equals(OSSErrorCode.NO_SUCH_BUCKET) || e.getErrorCode().equals(OSSErrorCode.NO_SUCH_KEY)) {
967967
return false;
968968
}
969969
throw e;

src/test/java/com/aliyun/oss/integrationtests/DoesObjectExistTest.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,13 @@ public void testExistingBucketAndNonExistentObject() {
9090
} catch (Exception e) {
9191
Assert.fail(e.getMessage());
9292
}
93+
94+
try {
95+
boolean exist = ossClient.doesObjectExist(bucketName, nonexistentKey, false);
96+
Assert.assertFalse(exist);
97+
} catch (Exception e) {
98+
Assert.fail(e.getMessage());
99+
}
93100
}
94101

95102
@Test

0 commit comments

Comments
 (0)