From aaac8c0636e12c40c46170bf4989bd34bb577430 Mon Sep 17 00:00:00 2001 From: Brian Burkhalter Date: Thu, 28 Aug 2025 17:38:09 +0000 Subject: [PATCH] 8366254: (fs) UnixException.translateToIOException should translate ELOOP to FileSystemLoopException Reviewed-by: vyazici, alanb --- .../unix/classes/sun/nio/fs/UnixException.java | 10 ++++++---- test/jdk/java/nio/file/Files/IsSameFile.java | 5 +++-- 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/src/java.base/unix/classes/sun/nio/fs/UnixException.java b/src/java.base/unix/classes/sun/nio/fs/UnixException.java index 9c90911f9cf..0f0de768109 100644 --- a/src/java.base/unix/classes/sun/nio/fs/UnixException.java +++ b/src/java.base/unix/classes/sun/nio/fs/UnixException.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2008, 2016, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2008, 2025, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -92,9 +92,11 @@ class UnixException extends Exception { return new NoSuchFileException(file, other, null); if (errno() == UnixConstants.EEXIST) return new FileAlreadyExistsException(file, other, null); - if (errno() == UnixConstants.ELOOP) - return new FileSystemException(file, other, errorString() - + " or unable to access attributes of symbolic link"); + if (errno() == UnixConstants.ELOOP) { + String msg = file + ": " + errorString() + + " or unable to access attributes of symbolic link"; + return new FileSystemLoopException(msg); + } // fallback to the more general exception return new FileSystemException(file, other, errorString()); diff --git a/test/jdk/java/nio/file/Files/IsSameFile.java b/test/jdk/java/nio/file/Files/IsSameFile.java index 00bac0fb5a7..44e03a15a02 100644 --- a/test/jdk/java/nio/file/Files/IsSameFile.java +++ b/test/jdk/java/nio/file/Files/IsSameFile.java @@ -22,7 +22,7 @@ */ /* @test - * @bug 8154364 + * @bug 8154364 8366254 * @summary Test of Files.isSameFile * @requires (os.family != "windows") * @library .. /test/lib @@ -33,6 +33,7 @@ import java.io.IOException; import java.io.FileOutputStream; import java.nio.file.Files; import java.nio.file.FileSystem; +import java.nio.file.FileSystemLoopException; import java.nio.file.FileSystemException; import java.nio.file.FileSystems; import java.nio.file.Path; @@ -451,6 +452,6 @@ public class IsSameFile { @ParameterizedTest @MethodSource("linkLoopSource") public void linkLoop(boolean expect, Path x, Path y) throws IOException { - assertThrows(FileSystemException.class, () -> Files.isSameFile(x, y)); + assertThrows(FileSystemLoopException.class, () -> Files.isSameFile(x, y)); } }