use of java.nio.file.FileSystemLoopException in project elasticsearch by elastic.
the class StreamInput method readException.
public <T extends Exception> T readException() throws IOException {
if (readBoolean()) {
int key = readVInt();
switch(key) {
case 0:
final int ord = readVInt();
return (T) ElasticsearchException.readException(this, ord);
case 1:
String msg1 = readOptionalString();
String resource1 = readOptionalString();
return (T) readStackTrace(new CorruptIndexException(msg1, resource1, readException()), this);
case 2:
String resource2 = readOptionalString();
int version2 = readInt();
int minVersion2 = readInt();
int maxVersion2 = readInt();
return (T) readStackTrace(new IndexFormatTooNewException(resource2, version2, minVersion2, maxVersion2), this);
case 3:
String resource3 = readOptionalString();
if (readBoolean()) {
int version3 = readInt();
int minVersion3 = readInt();
int maxVersion3 = readInt();
return (T) readStackTrace(new IndexFormatTooOldException(resource3, version3, minVersion3, maxVersion3), this);
} else {
String version3 = readOptionalString();
return (T) readStackTrace(new IndexFormatTooOldException(resource3, version3), this);
}
case 4:
return (T) readStackTrace(new NullPointerException(readOptionalString()), this);
case 5:
return (T) readStackTrace(new NumberFormatException(readOptionalString()), this);
case 6:
return (T) readStackTrace(new IllegalArgumentException(readOptionalString(), readException()), this);
case 7:
return (T) readStackTrace(new AlreadyClosedException(readOptionalString(), readException()), this);
case 8:
return (T) readStackTrace(new EOFException(readOptionalString()), this);
case 9:
return (T) readStackTrace(new SecurityException(readOptionalString(), readException()), this);
case 10:
return (T) readStackTrace(new StringIndexOutOfBoundsException(readOptionalString()), this);
case 11:
return (T) readStackTrace(new ArrayIndexOutOfBoundsException(readOptionalString()), this);
case 12:
return (T) readStackTrace(new FileNotFoundException(readOptionalString()), this);
case 13:
final int subclass = readVInt();
final String file = readOptionalString();
final String other = readOptionalString();
final String reason = readOptionalString();
// skip the msg - it's composed from file, other and reason
readOptionalString();
final Exception exception;
switch(subclass) {
case 0:
exception = new NoSuchFileException(file, other, reason);
break;
case 1:
exception = new NotDirectoryException(file);
break;
case 2:
exception = new DirectoryNotEmptyException(file);
break;
case 3:
exception = new AtomicMoveNotSupportedException(file, other, reason);
break;
case 4:
exception = new FileAlreadyExistsException(file, other, reason);
break;
case 5:
exception = new AccessDeniedException(file, other, reason);
break;
case 6:
exception = new FileSystemLoopException(file);
break;
case 7:
exception = new FileSystemException(file, other, reason);
break;
default:
throw new IllegalStateException("unknown FileSystemException with index " + subclass);
}
return (T) readStackTrace(exception, this);
case 14:
return (T) readStackTrace(new IllegalStateException(readOptionalString(), readException()), this);
case 15:
return (T) readStackTrace(new LockObtainFailedException(readOptionalString(), readException()), this);
case 16:
return (T) readStackTrace(new InterruptedException(readOptionalString()), this);
case 17:
return (T) readStackTrace(new IOException(readOptionalString(), readException()), this);
default:
assert false : "no such exception for id: " + key;
}
}
return null;
}
use of java.nio.file.FileSystemLoopException in project j2objc by google.
the class Files2Test method test_walk_FileSystemLoopException.
@Test
public void test_walk_FileSystemLoopException() throws IOException {
// Directory structure.
// root
// └── dir1
// └── file1
//
// file1 is symbolic link to dir1
Path rootDir = Paths.get(filesSetup.getTestDir(), "root");
Path dir1 = Paths.get(filesSetup.getTestDir(), "root/dir");
Path file1 = Paths.get(filesSetup.getTestDir(), "root/dir/file1");
Files.createDirectories(dir1);
Files.createSymbolicLink(file1, dir1.toAbsolutePath());
assertTrue(Files.isSymbolicLink(file1));
try (Stream<Path> pathStream = Files.walk(rootDir, FileVisitOption.FOLLOW_LINKS)) {
pathStream.forEach(path -> assertNotNull(path));
fail();
} catch (UncheckedIOException expected) {
assertTrue(expected.getCause() instanceof FileSystemLoopException);
}
}
use of java.nio.file.FileSystemLoopException in project j2objc by google.
the class FileSystemLoopExceptionTest method test_constructor$String.
public void test_constructor$String() {
FileSystemLoopException exception = new FileSystemLoopException("file");
assertEquals("file", exception.getFile());
assertTrue(exception instanceof FileSystemException);
}
use of java.nio.file.FileSystemLoopException in project crate by crate.
the class StreamInput method readException.
@SuppressWarnings("unchecked")
public <T extends Exception> T readException() throws IOException {
if (readBoolean()) {
int key = readVInt();
switch(key) {
case 0:
final int ord = readVInt();
if (ord == 59) {
final ElasticsearchException ex = new ElasticsearchException(this);
final boolean isExecutorShutdown = readBoolean();
return (T) new EsRejectedExecutionException(ex.getMessage(), isExecutorShutdown);
}
return (T) ElasticsearchException.readException(this, ord);
case 1:
String msg1 = readOptionalString();
String resource1 = readOptionalString();
return (T) readStackTrace(new CorruptIndexException(msg1, resource1, readException()), this);
case 2:
String resource2 = readOptionalString();
int version2 = readInt();
int minVersion2 = readInt();
int maxVersion2 = readInt();
return (T) readStackTrace(new IndexFormatTooNewException(resource2, version2, minVersion2, maxVersion2), this);
case 3:
String resource3 = readOptionalString();
if (readBoolean()) {
int version3 = readInt();
int minVersion3 = readInt();
int maxVersion3 = readInt();
return (T) readStackTrace(new IndexFormatTooOldException(resource3, version3, minVersion3, maxVersion3), this);
} else {
String version3 = readOptionalString();
return (T) readStackTrace(new IndexFormatTooOldException(resource3, version3), this);
}
case 4:
return (T) readStackTrace(new NullPointerException(readOptionalString()), this);
case 5:
return (T) readStackTrace(new NumberFormatException(readOptionalString()), this);
case 6:
return (T) readStackTrace(new IllegalArgumentException(readOptionalString(), readException()), this);
case 7:
return (T) readStackTrace(new AlreadyClosedException(readOptionalString(), readException()), this);
case 8:
return (T) readStackTrace(new EOFException(readOptionalString()), this);
case 9:
return (T) readStackTrace(new SecurityException(readOptionalString(), readException()), this);
case 10:
return (T) readStackTrace(new StringIndexOutOfBoundsException(readOptionalString()), this);
case 11:
return (T) readStackTrace(new ArrayIndexOutOfBoundsException(readOptionalString()), this);
case 12:
return (T) readStackTrace(new FileNotFoundException(readOptionalString()), this);
case 13:
final int subclass = readVInt();
final String file = readOptionalString();
final String other = readOptionalString();
final String reason = readOptionalString();
// skip the msg - it's composed from file, other and reason
readOptionalString();
final Exception exception;
switch(subclass) {
case 0:
exception = new NoSuchFileException(file, other, reason);
break;
case 1:
exception = new NotDirectoryException(file);
break;
case 2:
exception = new DirectoryNotEmptyException(file);
break;
case 3:
exception = new AtomicMoveNotSupportedException(file, other, reason);
break;
case 4:
exception = new FileAlreadyExistsException(file, other, reason);
break;
case 5:
exception = new AccessDeniedException(file, other, reason);
break;
case 6:
exception = new FileSystemLoopException(file);
break;
case 7:
exception = new FileSystemException(file, other, reason);
break;
default:
throw new IllegalStateException("unknown FileSystemException with index " + subclass);
}
return (T) readStackTrace(exception, this);
case 14:
return (T) readStackTrace(new IllegalStateException(readOptionalString(), readException()), this);
case 15:
return (T) readStackTrace(new LockObtainFailedException(readOptionalString(), readException()), this);
case 16:
return (T) readStackTrace(new InterruptedException(readOptionalString()), this);
case 17:
return (T) readStackTrace(new IOException(readOptionalString(), readException()), this);
case 18:
final boolean isExecutorShutdown = readBoolean();
return (T) readStackTrace(new EsRejectedExecutionException(readOptionalString(), isExecutorShutdown), this);
case 19:
return (T) readStackTrace(new UncheckedIOException(readOptionalString(), readException()), this);
default:
throw new IOException("no such exception for id: " + key);
}
}
return null;
}
use of java.nio.file.FileSystemLoopException in project omegat by omegat-org.
the class FileUtilTest method testBuildFileList.
@Test
public void testBuildFileList() throws Exception {
File tempDir = Files.createTempDirectory("omegat").toFile();
assertTrue(tempDir.isDirectory());
File subDir = new File(tempDir, "a");
assertTrue(subDir.mkdirs());
File aFile = new File(subDir, "foo");
assertTrue(aFile.createNewFile());
aFile = new File(subDir, "bar");
assertTrue(aFile.createNewFile());
List<File> list1 = FileUtil.buildFileList(tempDir, false);
assertTrue(list1.isEmpty());
List<File> list2 = FileUtil.buildFileList(tempDir, true);
assertEquals(2, list2.size());
Collections.sort(list2);
assertTrue(list2.get(0).getPath().endsWith("bar"));
try {
File lnk = new File(tempDir, "hoge");
Files.createSymbolicLink(lnk.toPath(), subDir.toPath());
List<File> list3 = FileUtil.buildFileList(lnk, true);
List<File> list4 = FileUtil.buildFileList(subDir, true);
assertEquals(list3.size(), list4.size());
assertTrue(IntStream.range(0, list3.size()).allMatch(i -> {
try {
return list3.get(i).getCanonicalFile().equals(list4.get(i).getCanonicalFile());
} catch (IOException e) {
throw new UncheckedIOException(e);
}
}));
} catch (UnsupportedOperationException | IOException ex) {
// Creating symbolic links appears to not be supported on this
// system
}
try {
Files.createSymbolicLink(new File(tempDir, "baz").toPath(), tempDir.toPath());
FileUtil.buildFileList(tempDir, true);
fail("Should die from file system loop");
} catch (UnsupportedOperationException | IOException ex) {
// Creating symbolic links appears to not be supported on this
// system
} catch (UncheckedIOException ex) {
if (!(ex.getCause() instanceof FileSystemLoopException)) {
throw ex;
}
// Creating symbolic links appears to not be supported on this
// system
}
safeDeleteDirectory(tempDir);
}
Aggregations