Skip to content

Commit

Permalink
fix listFilesV2 null Exception
Browse files Browse the repository at this point in the history
  • Loading branch information
sxci committed Dec 9, 2019
1 parent b6d8f70 commit 5025e1f
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 3 deletions.
10 changes: 7 additions & 3 deletions src/main/java/com/qiniu/storage/BucketManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -237,8 +237,12 @@ public FileListing listFilesV2(String bucket, String prefix, String marker, int
for (int i = 0; i < lineList.size(); i++) {
String line = lineList.get(i);
JsonObject jsonObject = Json.decode(line, JsonObject.class);
if (!(jsonObject.get("item") instanceof JsonNull))
if (jsonObject == null) {
continue;
}
if (!(jsonObject.get("item") instanceof JsonNull)) {
fileInfoList.add(Json.decode(jsonObject.get("item"), FileInfo.class));
}
String dir = jsonObject.get("dir").getAsString();
if (!"".equals(dir)) commonPrefixSet.add(dir);
if (i == lineList.size() - 1)
Expand Down Expand Up @@ -523,8 +527,8 @@ public Response asynFetch(String url, String bucket, String key) throws QiniuExc
* @throws QiniuException
*/
public Response asynFetch(String url, String bucket, String key, String md5, String etag,
String callbackurl, String callbackbody, String callbackbodytype,
String callbackhost, int fileType) throws QiniuException {
String callbackurl, String callbackbody, String callbackbodytype,
String callbackhost, int fileType) throws QiniuException {
StringMap params = new StringMap()
.putNotNull("key", key)
.putNotNull("md5", md5)
Expand Down
35 changes: 35 additions & 0 deletions src/test/java/test/com/qiniu/storage/BucketTest2.java
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,41 @@ public void testListIteratorWithDefaultLimit() {
}
}

@Test
public void testListV2() {
try {
String[] buckets = new String[]{TestConfig.testBucket_z0};
for (String bucket : buckets) {
FileListing l = bucketManager.listFilesV2(bucket, "sdfisjfisjei", null, 2, null);
}

for (String bucket : buckets) {
FileListing l = bucketManager.listFilesV2(bucket, null, null, 2, null);
Assert.assertNotNull(l.items[0]);
Assert.assertNotNull(l.marker);
}
} catch (QiniuException e) {
Assert.assertTrue(ResCode.find(e.code(), ResCode.getPossibleResCode()));
}
}


@Test
public void testListV2_1() {
try {
String marker = null;
do{
FileListing l = bucketManager.listFilesV2(TestConfig.testBucket_z0, "pi", marker, 2, null);
marker = l.marker;
for (FileInfo f :l.items) {
Assert.assertNotNull(f.key);
}
} while(!StringUtils.isNullOrEmpty(marker));
} catch (QiniuException e) {
Assert.assertTrue(ResCode.find(e.code(), ResCode.getPossibleResCode()));
}
}

/**
* 测试stat
*/
Expand Down

0 comments on commit 5025e1f

Please sign in to comment.