From 0552f5ad75da1468050f8aa3ffb533bd3c5d4ca8 Mon Sep 17 00:00:00 2001 From: Jesse Glick Date: Fri, 16 Nov 2012 13:41:22 -0500 Subject: [PATCH] [JENKINS-13202] 646154f refinement: resolveSymlink is documented to return null, not throw an exception, when called on a regular file. --- changelog.html | 3 +++ core/src/main/java/hudson/Util.java | 7 +++++++ core/src/test/java/hudson/UtilTest.java | 1 + 3 files changed, 11 insertions(+) diff --git a/changelog.html b/changelog.html index 83f01f9389..b8e107178b 100644 --- a/changelog.html +++ b/changelog.html @@ -61,6 +61,9 @@ Upcoming changes
  • Build records were broken if timezone was changed while running. (issue 15816) +
  • + Symlink detection refinement on Java 7. + (issue 13202)
  • Displaying massive test suite results could bring down Jenkins. (issue 15818) diff --git a/core/src/main/java/hudson/Util.java b/core/src/main/java/hudson/Util.java index a93ef736d0..4f15ec7786 100644 --- a/core/src/main/java/hudson/Util.java +++ b/core/src/main/java/hudson/Util.java @@ -1110,6 +1110,13 @@ public class Util { if (x2 instanceof UnsupportedOperationException) { return null; // no symlinks on this platform } + try { + if (Class.forName("java.nio.file.NotLinkException").isInstance(x2)) { + return null; + } + } catch (ClassNotFoundException x3) { + assert false : x3; // should be Java 7+ here + } if (x2 instanceof IOException) { throw (IOException) x2; } diff --git a/core/src/test/java/hudson/UtilTest.java b/core/src/test/java/hudson/UtilTest.java index 8461ee2ee7..4d5cb0fee1 100644 --- a/core/src/test/java/hudson/UtilTest.java +++ b/core/src/test/java/hudson/UtilTest.java @@ -171,6 +171,7 @@ public class UtilTest { File d = Util.createTempDir(); try { new FilePath(new File(d, "a")).touch(0); + assertNull(Util.resolveSymlink(new File(d, "a"))); Util.createSymlink(d,"a","x", l); assertEquals("a",Util.resolveSymlink(new File(d,"x")));