HADOOP-6796. FileStatus allows null srcPath but crashes if that's done. Contributed by Rodrigo Schmidt.

git-svn-id: https://svn.apache.org/repos/asf/hadoop/common/trunk@953100 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Eli Collins 2010-06-09 17:57:49 +00:00
parent 2232093326
commit b78612c4e2
3 changed files with 92 additions and 12 deletions

View File

@ -76,6 +76,8 @@ Trunk (unreleased changes)
HADOOP-6687. user object in the subject in UGI should be reused in case HADOOP-6687. user object in the subject in UGI should be reused in case
of a relogin. (jnp via boryas) of a relogin. (jnp via boryas)
HADOOP-6796. FileStatus allows null srcPath but crashes if that's done. (Rodrigo Schmidt via eli)
Release 0.21.0 - Unreleased Release 0.21.0 - Unreleased
INCOMPATIBLE CHANGES INCOMPATIBLE CHANGES

View File

@ -29,19 +29,19 @@ import org.apache.hadoop.io.Writable;
*/ */
public class FileStatus implements Writable, Comparable { public class FileStatus implements Writable, Comparable {
private Path path; private Path path = null;
private long length; private long length = 0;
private boolean isdir; private boolean isdir = false;
private short block_replication; private short block_replication = 0;
private long blocksize; private long blocksize = 0;
private long modification_time; private long modification_time = 0;
private long access_time; private long access_time = 0;
private FsPermission permission; private FsPermission permission = null;
private String owner; private String owner = null;
private String group; private String group = null;
private Path symlink; private Path symlink = null;
public FileStatus() { this(0, false, 0, 0, 0, 0, null, null, null, null); } public FileStatus() {}
//We should deprecate this soon? //We should deprecate this soon?
public FileStatus(long length, boolean isdir, int block_replication, public FileStatus(long length, boolean isdir, int block_replication,
@ -63,6 +63,12 @@ public class FileStatus implements Writable, Comparable {
access_time, permission, owner, group, null, path); access_time, permission, owner, group, null, path);
} }
private void stateSanityCheck() {
if (path == null) {
throw new IllegalArgumentException("path cannot be null");
}
}
public FileStatus(long length, boolean isdir, public FileStatus(long length, boolean isdir,
int block_replication, int block_replication,
long blocksize, long modification_time, long access_time, long blocksize, long modification_time, long access_time,
@ -81,6 +87,7 @@ public class FileStatus implements Writable, Comparable {
this.group = (group == null) ? "" : group; this.group = (group == null) ? "" : group;
this.symlink = symlink; this.symlink = symlink;
this.path = path; this.path = path;
stateSanityCheck();
} }
/** /**

View File

@ -0,0 +1,71 @@
/**
* 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;
import static org.junit.Assert.assertTrue;
import org.junit.Test;
import org.apache.hadoop.fs.permission.FsPermission;
public class TestFileStatus {
@Test
public void testFileStatusNullPath() throws Exception {
new FileStatus();
new FileStatus(1,false,3,3,4, new Path("/")); new FileStatus(1,false,5,3,4,5,null,null,null,new Path("/a/b"));
new FileStatus(1,false,5,3,4,5,null,null,null,null,new Path("/a/b"));
new FileStatus(1,false,5,3,4,5,new FsPermission((short) 7),
"bla","bla",new Path ("/b/c"), new Path("/a/b"));
boolean error = false;
try{
new FileStatus(1,false,3,3,4, null);
} catch (IllegalArgumentException exc) {
error = true;
}
assertTrue("Accepted null path", error);
try {
new FileStatus(1,false,5,3,4,5,null,null,null,null);
} catch (IllegalArgumentException exc) {
error = true;
}
assertTrue("Accepted null path",error);
try {
new FileStatus(1,false,5,3,4,5,null,null,null,null,null);
} catch (IllegalArgumentException exc) {
error = true;
}
assertTrue("Accepted null path",error);
try {
new FileStatus(1,false,5,3,4,5,new FsPermission((short) 7),
"bla","bla",new Path ("/b/c"), null);
} catch (IllegalArgumentException exc) {
error = true;
}
assertTrue("Accepted null path",error);
}
}