Skip to content

HADOOP-16138. hadoop fs mkdir / of nonexistent abfs container raises NPE #1302

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Sep 23, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,17 @@ protected void processNonexistentPath(PathData item) throws IOException {
// we want a/b
final Path itemPath = new Path(item.path.toString());
final Path itemParentPath = itemPath.getParent();

if(itemParentPath == null) {
throw new PathNotFoundException(String.format(
"Item: %s parent's path is null. This can happen if mkdir is " +
"called on root, so there's no parent.", itemPath.toString()));
}

if (!item.fs.exists(itemParentPath)) {
throw new PathNotFoundException(itemParentPath.toString());
throw new PathNotFoundException(String.format(
"mkdir failed for path: %s. Item parent path not found: %s.",
itemPath.toString(), itemParentPath.toString()));
}
}
if (!item.fs.mkdirs(item.path)) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
/**
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package org.apache.hadoop.fs.azurebfs;

import java.util.UUID;

import org.junit.Test;

import org.apache.hadoop.fs.FsShell;
import org.apache.hadoop.conf.Configuration;

import static org.apache.hadoop.fs.azurebfs.constants.ConfigurationKeys.AZURE_CREATE_REMOTE_FILESYSTEM_DURING_INITIALIZATION;
import static org.apache.hadoop.fs.azurebfs.constants.FileSystemUriSchemes.ABFS_SCHEME;
import static org.apache.hadoop.fs.azurebfs.constants.TestConfigurationKeys.FS_AZURE_ABFS_ACCOUNT_NAME;

/**
* Tests for Azure Blob FileSystem CLI.
*/
public class ITestAzureBlobFileSystemCLI extends AbstractAbfsIntegrationTest {

public ITestAzureBlobFileSystemCLI() throws Exception {
super();
final AbfsConfiguration conf = getConfiguration();
conf.setBoolean(AZURE_CREATE_REMOTE_FILESYSTEM_DURING_INITIALIZATION, false);
}

/**
* Test for HADOOP-16138: hadoop fs mkdir / of nonexistent abfs
* container raises NPE.
*
* The command should return with 1 exit status, but there should be no NPE.
*
* @throws Exception
*/
@Test
public void testMkdirRootNonExistentContainer() throws Exception {
final Configuration rawConf = getRawConfiguration();
FsShell fsShell = new FsShell(rawConf);
final String account =
rawConf.get(FS_AZURE_ABFS_ACCOUNT_NAME, null);

String nonExistentContainer = "nonexistent-" + UUID.randomUUID();

int result = fsShell.run(new String[] { "-mkdir",
ABFS_SCHEME + "://" + nonExistentContainer + "@" + account + "/" });

assertEquals(1, result);
}
}