From a2ab860629780bad667de39114aa335ffdc3d323 Mon Sep 17 00:00:00 2001 From: Stefan Bodewig Date: Fri, 16 Apr 2010 20:18:51 +0000 Subject: [PATCH] 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 --- .../tools/ant/util/SymbolicLinkUtils.java | 6 ++-- .../tools/ant/util/SymlinkUtilsTest.java | 33 +++++++++++++++++++ 2 files changed, 37 insertions(+), 2 deletions(-) create mode 100644 src/tests/junit/org/apache/tools/ant/util/SymlinkUtilsTest.java diff --git a/src/main/org/apache/tools/ant/util/SymbolicLinkUtils.java b/src/main/org/apache/tools/ant/util/SymbolicLinkUtils.java index 8c3f200c5..83fc0ee79 100644 --- a/src/main/org/apache/tools/ant/util/SymbolicLinkUtils.java +++ b/src/main/org/apache/tools/ant/util/SymbolicLinkUtils.java @@ -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.

* - * @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()); } diff --git a/src/tests/junit/org/apache/tools/ant/util/SymlinkUtilsTest.java b/src/tests/junit/org/apache/tools/ant/util/SymlinkUtilsTest.java new file mode 100644 index 000000000..85c12baf4 --- /dev/null +++ b/src/tests/junit/org/apache/tools/ant/util/SymlinkUtilsTest.java @@ -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("/")); + } + +}