Browse Source

isSymbolicLink throws a NPE if invoked for the file system root

git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@935069 13f79535-47bb-0310-9956-ffa450edef68
master
Stefan Bodewig 15 years ago
parent
commit
a2ab860629
2 changed files with 37 additions and 2 deletions
  1. +4
    -2
      src/main/org/apache/tools/ant/util/SymbolicLinkUtils.java
  2. +33
    -0
      src/tests/junit/org/apache/tools/ant/util/SymlinkUtilsTest.java

+ 4
- 2
src/main/org/apache/tools/ant/util/SymbolicLinkUtils.java View File

@@ -64,7 +64,7 @@ public class SymbolicLinkUtils {
* canonical and absolute paths of the file are identical--this
* may lead to false positives on some platforms.</p>
*
* @param file the file to test.
* @param file the file to test. Must not be null.
*
* @return true if the file is a symbolic link.
* @throws IOException on error.
@@ -104,7 +104,9 @@ public class SymbolicLinkUtils {
*/
public boolean isSymbolicLink(File parent, String name)
throws IOException {
File toTest = new File(parent.getCanonicalPath(), name);
File toTest = parent != null
? new File(parent.getCanonicalPath(), name)
: new File(name);
return !toTest.getAbsolutePath().equals(toTest.getCanonicalPath());
}



+ 33
- 0
src/tests/junit/org/apache/tools/ant/util/SymlinkUtilsTest.java View File

@@ -0,0 +1,33 @@
/*
* 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.tools.ant.util;

import java.io.IOException;
import junit.framework.TestCase;

public class SymlinkUtilsTest extends TestCase {

private static final SymbolicLinkUtils SYMLINK_UTILS =
SymbolicLinkUtils.getSymbolicLinkUtils();

public void testRootIsNoSymlink() throws IOException {
assertFalse(SYMLINK_UTILS.isSymbolicLink("/"));
}

}

Loading…
Cancel
Save