Azure / azure-sdk-for-java

This repository is for active development of the Azure SDK for Java. For consumers of the SDK we recommend visiting our public developer docs at https://docs.microsoft.com/java/azure/ or our versioned developer docs at https://azure.github.io/azure-sdk-for-java.
MIT License
2.29k stars 1.95k forks source link

[BUG] Files in the root failed renaming with status code 400 InvalidSourceUri error for ADLS java SDK #19491

Closed MuazmaZ closed 3 years ago

MuazmaZ commented 3 years ago

Describe the bug Trying to upload the content in a temporary file first then renaming the file for ADLS java SDK During the testing, the files being in the root failed renaming with status code 400 InvalidSourceUri error. When a folder is used everything works fine.

Exception or Stack Trace Add the exception log and stack trace if available

To Reproduce These are the steps can reproduce the problem without going into details until you ask me to:

  1. build DataLakeServiceClient
  2. getFileSytemClient("testfilesystem")
  3. getDirectoryClient("")
  4. tempfile = createFile("temp_tesfile") - At this point the file is created in root directory
  5. tempfile.rename(null, "testfile") - Getting 400 Bad Request InvalidSourceUri error

Debugging the code in the DataLakePathClient.class in renameWithResponse method there is the following line (line 168 for me): String renameSource = "/" + this.dataLakePathAsynchClient.getFileSystemName() + "/" + Utility.urlEncode(this.dataLakePathAsynchClient.getObjectPath());

this.dataLakePathAsynchClient.getObjectPath() returns the path starting with a slash, so if the file is in the root directory the string will be "/testfilesystem/%2Ftemp_testfile" having double slashes. Setting the value in the debugger to "/testfilesystem/temp_testfile'' with one slash the rename finishing successfully.

If the file is not in the root directory it is working correctly as this.dataLakePathAsynchClient.getObjectPath() returns the path without the slash.

Having a slash trimming here would remediate this so I would like to check whether there is a configuration/code I should use if I work with the root directory? Is it an incorrect behavior?

Expected behavior Files in the root should be renamed

Screenshots N/A

Setup (please complete the following information):

Additional context This is for extension created on Apache NiFi ADLS processor: https://nifi.apache.org/docs/nifi-docs/components/org.apache.nifi/nifi-azure-nar/1.12.1/org.apache.nifi.processors.azure.storage.PutAzureDataLakeStorage/index.html

Information Checklist Kindly make sure that you have added all the following information above and check off the required fields otherwise we will treat the issuer as an incomplete report

rickle-msft commented 3 years ago

@MuazmaZ This looks like a bug to me. Thank you for the details and taking the extra steps to debug. I'll work on establishing a repro and then once I confirm the behavior I'll work on a fix

MuazmaZ commented 3 years ago

@rickle-msft the member who reported the issue to me has a PR for the issue: https://github.com/Azure/azure-sdk-for-java/pull/19498. Please take a look.

rickle-msft commented 3 years ago

Thank you for the heads up. I will take a look