java.nio.file.FileSystemLoopException Java Examples

The following examples show how to use java.nio.file.FileSystemLoopException. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source Project: dragonwell8_jdk   Author: alibaba   File: StreamTest.java    License: GNU General Public License v2.0 6 votes vote down vote up
private void validateFileSystemLoopException(Path start, Path... causes) {
    try (Stream<Path> s = Files.walk(start, FileVisitOption.FOLLOW_LINKS)) {
        try {
            int count = s.mapToInt(p -> 1).reduce(0, Integer::sum);
            fail("Should got FileSystemLoopException, but got " + count + "elements.");
        } catch (UncheckedIOException uioe) {
            IOException ioe = uioe.getCause();
            if (ioe instanceof FileSystemLoopException) {
                FileSystemLoopException fsle = (FileSystemLoopException) ioe;
                boolean match = false;
                for (Path cause: causes) {
                    if (fsle.getFile().equals(cause.toString())) {
                        match = true;
                        break;
                    }
                }
                assertTrue(match);
            } else {
                fail("Unexpected UncheckedIOException cause " + ioe.toString());
            }
        }
    } catch(IOException ex) {
        fail("Unexpected IOException " + ex);
    }
}
 
Example #2
Source Project: TencentKona-8   Author: Tencent   File: StreamTest.java    License: GNU General Public License v2.0 6 votes vote down vote up
private void validateFileSystemLoopException(Path start, Path... causes) {
    try (Stream<Path> s = Files.walk(start, FileVisitOption.FOLLOW_LINKS)) {
        try {
            int count = s.mapToInt(p -> 1).reduce(0, Integer::sum);
            fail("Should got FileSystemLoopException, but got " + count + "elements.");
        } catch (UncheckedIOException uioe) {
            IOException ioe = uioe.getCause();
            if (ioe instanceof FileSystemLoopException) {
                FileSystemLoopException fsle = (FileSystemLoopException) ioe;
                boolean match = false;
                for (Path cause: causes) {
                    if (fsle.getFile().equals(cause.toString())) {
                        match = true;
                        break;
                    }
                }
                assertTrue(match);
            } else {
                fail("Unexpected UncheckedIOException cause " + ioe.toString());
            }
        }
    } catch(IOException ex) {
        fail("Unexpected IOException " + ex);
    }
}
 
Example #3
Source Project: jdk8u60   Author: chenghanpeng   File: StreamTest.java    License: GNU General Public License v2.0 6 votes vote down vote up
private void validateFileSystemLoopException(Path start, Path... causes) {
    try (Stream<Path> s = Files.walk(start, FileVisitOption.FOLLOW_LINKS)) {
        try {
            int count = s.mapToInt(p -> 1).reduce(0, Integer::sum);
            fail("Should got FileSystemLoopException, but got " + count + "elements.");
        } catch (UncheckedIOException uioe) {
            IOException ioe = uioe.getCause();
            if (ioe instanceof FileSystemLoopException) {
                FileSystemLoopException fsle = (FileSystemLoopException) ioe;
                boolean match = false;
                for (Path cause: causes) {
                    if (fsle.getFile().equals(cause.toString())) {
                        match = true;
                        break;
                    }
                }
                assertTrue(match);
            } else {
                fail("Unexpected UncheckedIOException cause " + ioe.toString());
            }
        }
    } catch(IOException ex) {
        fail("Unexpected IOException " + ex);
    }
}
 
Example #4
Source Project: openjdk-jdk8u   Author: AdoptOpenJDK   File: StreamTest.java    License: GNU General Public License v2.0 6 votes vote down vote up
private void validateFileSystemLoopException(Path start, Path... causes) {
    try (Stream<Path> s = Files.walk(start, FileVisitOption.FOLLOW_LINKS)) {
        try {
            int count = s.mapToInt(p -> 1).reduce(0, Integer::sum);
            fail("Should got FileSystemLoopException, but got " + count + "elements.");
        } catch (UncheckedIOException uioe) {
            IOException ioe = uioe.getCause();
            if (ioe instanceof FileSystemLoopException) {
                FileSystemLoopException fsle = (FileSystemLoopException) ioe;
                boolean match = false;
                for (Path cause: causes) {
                    if (fsle.getFile().equals(cause.toString())) {
                        match = true;
                        break;
                    }
                }
                assertTrue(match);
            } else {
                fail("Unexpected UncheckedIOException cause " + ioe.toString());
            }
        }
    } catch(IOException ex) {
        fail("Unexpected IOException " + ex);
    }
}
 
Example #5
Source Project: openjdk-jdk8u-backup   Author: AdoptOpenJDK   File: StreamTest.java    License: GNU General Public License v2.0 6 votes vote down vote up
private void validateFileSystemLoopException(Path start, Path... causes) {
    try (Stream<Path> s = Files.walk(start, FileVisitOption.FOLLOW_LINKS)) {
        try {
            int count = s.mapToInt(p -> 1).reduce(0, Integer::sum);
            fail("Should got FileSystemLoopException, but got " + count + "elements.");
        } catch (UncheckedIOException uioe) {
            IOException ioe = uioe.getCause();
            if (ioe instanceof FileSystemLoopException) {
                FileSystemLoopException fsle = (FileSystemLoopException) ioe;
                boolean match = false;
                for (Path cause: causes) {
                    if (fsle.getFile().equals(cause.toString())) {
                        match = true;
                        break;
                    }
                }
                assertTrue(match);
            } else {
                fail("Unexpected UncheckedIOException cause " + ioe.toString());
            }
        }
    } catch(IOException ex) {
        fail("Unexpected IOException " + ex);
    }
}
 
Example #6
Source Project: openjdk-jdk9   Author: AdoptOpenJDK   File: StreamTest.java    License: GNU General Public License v2.0 6 votes vote down vote up
private void validateFileSystemLoopException(Path start, Path... causes) {
    try (Stream<Path> s = Files.walk(start, FileVisitOption.FOLLOW_LINKS)) {
        try {
            int count = s.mapToInt(p -> 1).reduce(0, Integer::sum);
            fail("Should got FileSystemLoopException, but got " + count + "elements.");
        } catch (UncheckedIOException uioe) {
            IOException ioe = uioe.getCause();
            if (ioe instanceof FileSystemLoopException) {
                FileSystemLoopException fsle = (FileSystemLoopException) ioe;
                boolean match = false;
                for (Path cause: causes) {
                    if (fsle.getFile().equals(cause.toString())) {
                        match = true;
                        break;
                    }
                }
                assertTrue(match);
            } else {
                fail("Unexpected UncheckedIOException cause " + ioe.toString());
            }
        }
    } catch(IOException ex) {
        fail("Unexpected IOException " + ex);
    }
}
 
Example #7
Source Project: jdk8u-jdk   Author: lambdalab-mirror   File: StreamTest.java    License: GNU General Public License v2.0 6 votes vote down vote up
private void validateFileSystemLoopException(Path start, Path... causes) {
    try (Stream<Path> s = Files.walk(start, FileVisitOption.FOLLOW_LINKS)) {
        try {
            int count = s.mapToInt(p -> 1).reduce(0, Integer::sum);
            fail("Should got FileSystemLoopException, but got " + count + "elements.");
        } catch (UncheckedIOException uioe) {
            IOException ioe = uioe.getCause();
            if (ioe instanceof FileSystemLoopException) {
                FileSystemLoopException fsle = (FileSystemLoopException) ioe;
                boolean match = false;
                for (Path cause: causes) {
                    if (fsle.getFile().equals(cause.toString())) {
                        match = true;
                        break;
                    }
                }
                assertTrue(match);
            } else {
                fail("Unexpected UncheckedIOException cause " + ioe.toString());
            }
        }
    } catch(IOException ex) {
        fail("Unexpected IOException " + ex);
    }
}
 
Example #8
Source Project: hottub   Author: dsrg-uoft   File: StreamTest.java    License: GNU General Public License v2.0 6 votes vote down vote up
private void validateFileSystemLoopException(Path start, Path... causes) {
    try (Stream<Path> s = Files.walk(start, FileVisitOption.FOLLOW_LINKS)) {
        try {
            int count = s.mapToInt(p -> 1).reduce(0, Integer::sum);
            fail("Should got FileSystemLoopException, but got " + count + "elements.");
        } catch (UncheckedIOException uioe) {
            IOException ioe = uioe.getCause();
            if (ioe instanceof FileSystemLoopException) {
                FileSystemLoopException fsle = (FileSystemLoopException) ioe;
                boolean match = false;
                for (Path cause: causes) {
                    if (fsle.getFile().equals(cause.toString())) {
                        match = true;
                        break;
                    }
                }
                assertTrue(match);
            } else {
                fail("Unexpected UncheckedIOException cause " + ioe.toString());
            }
        }
    } catch(IOException ex) {
        fail("Unexpected IOException " + ex);
    }
}
 
Example #9
Source Project: openjdk-8-source   Author: keerath   File: StreamTest.java    License: GNU General Public License v2.0 6 votes vote down vote up
private void validateFileSystemLoopException(Path start, Path... causes) {
    try (Stream<Path> s = Files.walk(start, FileVisitOption.FOLLOW_LINKS)) {
        try {
            int count = s.mapToInt(p -> 1).reduce(0, Integer::sum);
            fail("Should got FileSystemLoopException, but got " + count + "elements.");
        } catch (UncheckedIOException uioe) {
            IOException ioe = uioe.getCause();
            if (ioe instanceof FileSystemLoopException) {
                FileSystemLoopException fsle = (FileSystemLoopException) ioe;
                boolean match = false;
                for (Path cause: causes) {
                    if (fsle.getFile().equals(cause.toString())) {
                        match = true;
                        break;
                    }
                }
                assertTrue(match);
            } else {
                fail("Unexpected UncheckedIOException cause " + ioe.toString());
            }
        }
    } catch(IOException ex) {
        fail("Unexpected IOException " + ex);
    }
}
 
Example #10
Source Project: openjdk-8   Author: bpupadhyaya   File: StreamTest.java    License: GNU General Public License v2.0 6 votes vote down vote up
private void validateFileSystemLoopException(Path start, Path... causes) {
    try (Stream<Path> s = Files.walk(start, FileVisitOption.FOLLOW_LINKS)) {
        try {
            int count = s.mapToInt(p -> 1).reduce(0, Integer::sum);
            fail("Should got FileSystemLoopException, but got " + count + "elements.");
        } catch (UncheckedIOException uioe) {
            IOException ioe = uioe.getCause();
            if (ioe instanceof FileSystemLoopException) {
                FileSystemLoopException fsle = (FileSystemLoopException) ioe;
                boolean match = false;
                for (Path cause: causes) {
                    if (fsle.getFile().equals(cause.toString())) {
                        match = true;
                        break;
                    }
                }
                assertTrue(match);
            } else {
                fail("Unexpected UncheckedIOException cause " + ioe.toString());
            }
        }
    } catch(IOException ex) {
        fail("Unexpected IOException " + ex);
    }
}
 
Example #11
Source Project: jdk8u_jdk   Author: JetBrains   File: StreamTest.java    License: GNU General Public License v2.0 6 votes vote down vote up
private void validateFileSystemLoopException(Path start, Path... causes) {
    try (Stream<Path> s = Files.walk(start, FileVisitOption.FOLLOW_LINKS)) {
        try {
            int count = s.mapToInt(p -> 1).reduce(0, Integer::sum);
            fail("Should got FileSystemLoopException, but got " + count + "elements.");
        } catch (UncheckedIOException uioe) {
            IOException ioe = uioe.getCause();
            if (ioe instanceof FileSystemLoopException) {
                FileSystemLoopException fsle = (FileSystemLoopException) ioe;
                boolean match = false;
                for (Path cause: causes) {
                    if (fsle.getFile().equals(cause.toString())) {
                        match = true;
                        break;
                    }
                }
                assertTrue(match);
            } else {
                fail("Unexpected UncheckedIOException cause " + ioe.toString());
            }
        }
    } catch(IOException ex) {
        fail("Unexpected IOException " + ex);
    }
}
 
Example #12
Source Project: jdk8u-jdk   Author: frohoff   File: StreamTest.java    License: GNU General Public License v2.0 6 votes vote down vote up
private void validateFileSystemLoopException(Path start, Path... causes) {
    try (Stream<Path> s = Files.walk(start, FileVisitOption.FOLLOW_LINKS)) {
        try {
            int count = s.mapToInt(p -> 1).reduce(0, Integer::sum);
            fail("Should got FileSystemLoopException, but got " + count + "elements.");
        } catch (UncheckedIOException uioe) {
            IOException ioe = uioe.getCause();
            if (ioe instanceof FileSystemLoopException) {
                FileSystemLoopException fsle = (FileSystemLoopException) ioe;
                boolean match = false;
                for (Path cause: causes) {
                    if (fsle.getFile().equals(cause.toString())) {
                        match = true;
                        break;
                    }
                }
                assertTrue(match);
            } else {
                fail("Unexpected UncheckedIOException cause " + ioe.toString());
            }
        }
    } catch(IOException ex) {
        fail("Unexpected IOException " + ex);
    }
}
 
Example #13
Source Project: jdk8u-dev-jdk   Author: frohoff   File: StreamTest.java    License: GNU General Public License v2.0 6 votes vote down vote up
private void validateFileSystemLoopException(Path start, Path... causes) {
    try (Stream<Path> s = Files.walk(start, FileVisitOption.FOLLOW_LINKS)) {
        try {
            int count = s.mapToInt(p -> 1).reduce(0, Integer::sum);
            fail("Should got FileSystemLoopException, but got " + count + "elements.");
        } catch (UncheckedIOException uioe) {
            IOException ioe = uioe.getCause();
            if (ioe instanceof FileSystemLoopException) {
                FileSystemLoopException fsle = (FileSystemLoopException) ioe;
                boolean match = false;
                for (Path cause: causes) {
                    if (fsle.getFile().equals(cause.toString())) {
                        match = true;
                        break;
                    }
                }
                assertTrue(match);
            } else {
                fail("Unexpected UncheckedIOException cause " + ioe.toString());
            }
        }
    } catch(IOException ex) {
        fail("Unexpected IOException " + ex);
    }
}
 
Example #14
Source Project: genie   Author: Netflix   File: DirectoryManifest.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
public FileVisitResult visitFileFailed(final Path file, final IOException ioe) {
    if (ioe instanceof FileSystemLoopException) {
        log.warn("Detected file system cycle visiting while visiting {}. Skipping.", file);
        return FileVisitResult.SKIP_SUBTREE;
    } else if (ioe instanceof AccessDeniedException) {
        log.warn("Access denied for file {}. Skipping", file);
        return FileVisitResult.SKIP_SUBTREE;
    } else if (ioe instanceof NoSuchFileException) {
        log.warn("File or directory disappeared while visiting {}. Skipping", file);
        return FileVisitResult.SKIP_SUBTREE;
    } else {
        log.error("Got unknown error {} while visiting {}. Terminating visitor", ioe.getMessage(), file, ioe);
        // TODO: Not sure if we should do this or skip subtree or just continue and ignore it?
        return FileVisitResult.TERMINATE;
    }
}
 
Example #15
Source Project: Java-Coding-Problems   Author: PacktPublishing   File: CopyFileVisitor.java    License: MIT License 5 votes vote down vote up
@Override
public FileVisitResult visitFileFailed(Object file, IOException ioe) throws IOException {

    if (ioe instanceof FileSystemLoopException) {
        System.err.println("Cycle was detected: " + (Path) file);
    } else {
        System.err.println("Error occured, unable to copy:" + (Path) file + " [" + ioe + "]");
    }

    return FileVisitResult.CONTINUE;
}
 
Example #16
Source Project: n4js   Author: eclipse   File: FileCopier.java    License: Eclipse Public License 1.0 5 votes vote down vote up
@Override
public FileVisitResult visitFileFailed(Path file, IOException exc) {
	if (exc instanceof FileSystemLoopException) {
		LOGGER.error("File system loop/cycle detected: " + file, exc);
	} else {
		LOGGER.error("Error while copying resource: " + file, exc);
	}
	return CONTINUE;
}
 
Example #17
Source Project: marathonv5   Author: jalian-systems   File: Copy.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public FileVisitResult visitFileFailed(Path file, IOException exc) {
    if (exc instanceof FileSystemLoopException) {
        System.err.println("cycle detected: " + file);
    } else {
        System.err.format("Unable to copy: %s: %s%n", file, exc);
    }
    return CONTINUE;
}
 
Example #18
Source Project: Processing.R   Author: processing-r   File: TreeCopier.java    License: GNU General Public License v3.0 5 votes vote down vote up
@Override
public FileVisitResult visitFileFailed(final Path file, final IOException exc) {
  if (exc instanceof FileSystemLoopException) {
    System.err.println("cycle detected: " + file);
  } else {
    System.err.format("Unable to copy: %s: %s%n", file, exc);
  }
  return CONTINUE;
}
 
Example #19
Source Project: mycore   Author: MyCoRe-Org   File: MCRTreeCopier.java    License: GNU General Public License v3.0 5 votes vote down vote up
@Override
public FileVisitResult visitFileFailed(Path file, IOException exc) {
    if (exc instanceof FileSystemLoopException) {
        LOGGER.error("cycle detected: {}", file);
    } else {
        LOGGER.error("Unable to copy: {}", file, exc);
    }
    return FileVisitResult.CONTINUE;
}
 
Example #20
Source Project: studio   Author: craftercms   File: TreeCopier.java    License: GNU General Public License v3.0 5 votes vote down vote up
@Override
public FileVisitResult visitFileFailed(Path file, IOException exc) throws IOException {
    if (exc instanceof FileSystemLoopException) {
        logger.error("cycle detected: " + file);
    } else {
        logger.error("Unable to copy: %s: %s%n", file, exc);
    }
    return CONTINUE;
}
 
Example #21
Source Project: buck   Author: facebook   File: ExceptionHandlerRegistryFactory.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public ExitCode handleException(IOException e) {
  if (e instanceof FileSystemLoopException) {
    return ExitCode.FATAL_GENERIC;
  } else if (e.getMessage() != null
      && e.getMessage().startsWith("No space left on device")) {
    return ExitCode.FATAL_DISK_FULL;
  } else {
    return ExitCode.FATAL_IO;
  }
}
 
Example #22
Source Project: buck   Author: facebook   File: DefaultProjectFilesystem.java    License: Apache License 2.0 5 votes vote down vote up
private void ensureNoLoops(Path p, BasicFileAttributes attrs) throws FileSystemLoopException {
  if (!followLinks) {
    return;
  }
  if (!attrs.isDirectory()) {
    return;
  }
  if (willLoop(p, attrs)) {
    throw new FileSystemLoopException(p.toString());
  }
}
 
Example #23
Source Project: buck   Author: facebook   File: ErrorLoggerTest.java    License: Apache License 2.0 5 votes vote down vote up
@Test
public void testFileSystemLoopException() {
  LoggedErrors errors =
      logException(new TestException(new FileSystemLoopException("It's a loop!")));

  assertNull(errors.userVisible);
  assertThat(
      errors.userVisibleInternal,
      Matchers.containsString(
          "Loop detected in your directory, which may be caused by circular symlink. "
              + "You may consider running the command in a smaller directory."));
  assertThat(
      errors.userVisibleInternal,
      Matchers.containsString("java.nio.file.FileSystemLoopException: It's a loop!"));
}
 
Example #24
Source Project: buck   Author: facebook   File: ErrorLogger.java    License: Apache License 2.0 4 votes vote down vote up
/** Returns the message (and optionally stack trace) for the root cause. */
public String getMessage(boolean suppressStackTraces) {
  if (rootCause instanceof HumanReadableException) {
    return ((HumanReadableException) rootCause).getHumanReadableErrorMessage();
  }

  if (rootCause instanceof InterruptedException
      || rootCause instanceof ClosedByInterruptException) {
    return "Interrupted";
  }

  if (rootCause instanceof BuckIsDyingException) {
    return "Failed because buck was already dying";
  }

  if (isNoSpaceOnDevice()) {
    return rootCause.getMessage();
  }

  String message = "";
  if (rootCause instanceof FileSystemLoopException) {
    // TODO(cjhopman): Is this message helpful? What's a smaller directory?
    message =
        "Loop detected in your directory, which may be caused by circular symlink. "
            + "You may consider running the command in a smaller directory."
            + System.lineSeparator();
  }

  if (rootCause instanceof OutOfMemoryError) {
    message =
        "Buck ran out of memory, you may consider increasing heap size with java args "
            + "(see https://buck.build/files-and-dirs/buckjavaargs.html)"
            + System.lineSeparator();
  }

  if (suppressStackTraces) {
    return String.format(
        "%s%s: %s", message, rootCause.getClass().getName(), rootCause.getMessage());
  }

  return String.format("%s%s", message, Throwables.getStackTraceAsString(originalException));
}
 
Example #25
Source Project: buck   Author: facebook   File: ExceptionHandlerRegistryTest.java    License: Apache License 2.0 4 votes vote down vote up
@Test
public void testWithFileLoopException() {
  assertThat(
      registry.handleException(new FileSystemLoopException("Symlink found")),
      is(ExitCode.FATAL_GENERIC));
}