Search in sources :

Example 1 with FileSystemLoopException

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;
}
Also used : FileAlreadyExistsException(java.nio.file.FileAlreadyExistsException) AccessDeniedException(java.nio.file.AccessDeniedException) FileNotFoundException(java.io.FileNotFoundException) NoSuchFileException(java.nio.file.NoSuchFileException) DirectoryNotEmptyException(java.nio.file.DirectoryNotEmptyException) AlreadyClosedException(org.apache.lucene.store.AlreadyClosedException) NotDirectoryException(java.nio.file.NotDirectoryException) FileSystemException(java.nio.file.FileSystemException) IndexFormatTooOldException(org.apache.lucene.index.IndexFormatTooOldException) LockObtainFailedException(org.apache.lucene.store.LockObtainFailedException) EOFException(java.io.EOFException) AtomicMoveNotSupportedException(java.nio.file.AtomicMoveNotSupportedException) CorruptIndexException(org.apache.lucene.index.CorruptIndexException) IOException(java.io.IOException) GeoPoint(org.elasticsearch.common.geo.GeoPoint) ElasticsearchException(org.elasticsearch.ElasticsearchException) NoSuchFileException(java.nio.file.NoSuchFileException) IndexFormatTooNewException(org.apache.lucene.index.IndexFormatTooNewException) LockObtainFailedException(org.apache.lucene.store.LockObtainFailedException) AlreadyClosedException(org.apache.lucene.store.AlreadyClosedException) CorruptIndexException(org.apache.lucene.index.CorruptIndexException) FileSystemLoopException(java.nio.file.FileSystemLoopException) NotDirectoryException(java.nio.file.NotDirectoryException) DirectoryNotEmptyException(java.nio.file.DirectoryNotEmptyException) FileSystemException(java.nio.file.FileSystemException) IOException(java.io.IOException) IndexFormatTooOldException(org.apache.lucene.index.IndexFormatTooOldException) FileAlreadyExistsException(java.nio.file.FileAlreadyExistsException) EOFException(java.io.EOFException) FileNotFoundException(java.io.FileNotFoundException) AtomicMoveNotSupportedException(java.nio.file.AtomicMoveNotSupportedException) AccessDeniedException(java.nio.file.AccessDeniedException) IndexFormatTooNewException(org.apache.lucene.index.IndexFormatTooNewException) FileSystemLoopException(java.nio.file.FileSystemLoopException)

Example 2 with FileSystemLoopException

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);
    }
}
Also used : Path(java.nio.file.Path) UncheckedIOException(java.io.UncheckedIOException) FileSystemLoopException(java.nio.file.FileSystemLoopException) Test(org.junit.Test)

Example 3 with 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);
}
Also used : FileSystemException(java.nio.file.FileSystemException) FileSystemLoopException(java.nio.file.FileSystemLoopException)

Example 4 with FileSystemLoopException

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;
}
Also used : FileAlreadyExistsException(java.nio.file.FileAlreadyExistsException) AccessDeniedException(java.nio.file.AccessDeniedException) FileNotFoundException(java.io.FileNotFoundException) NoSuchFileException(java.nio.file.NoSuchFileException) DirectoryNotEmptyException(java.nio.file.DirectoryNotEmptyException) UncheckedIOException(java.io.UncheckedIOException) ElasticsearchException(org.elasticsearch.ElasticsearchException) AlreadyClosedException(org.apache.lucene.store.AlreadyClosedException) NotDirectoryException(java.nio.file.NotDirectoryException) FileSystemException(java.nio.file.FileSystemException) IndexFormatTooOldException(org.apache.lucene.index.IndexFormatTooOldException) LockObtainFailedException(org.apache.lucene.store.LockObtainFailedException) EOFException(java.io.EOFException) AtomicMoveNotSupportedException(java.nio.file.AtomicMoveNotSupportedException) EsRejectedExecutionException(org.elasticsearch.common.util.concurrent.EsRejectedExecutionException) CorruptIndexException(org.apache.lucene.index.CorruptIndexException) UncheckedIOException(java.io.UncheckedIOException) IOException(java.io.IOException) GeoPoint(org.elasticsearch.common.geo.GeoPoint) ElasticsearchException(org.elasticsearch.ElasticsearchException) NoSuchFileException(java.nio.file.NoSuchFileException) IndexFormatTooNewException(org.apache.lucene.index.IndexFormatTooNewException) AlreadyClosedException(org.apache.lucene.store.AlreadyClosedException) CorruptIndexException(org.apache.lucene.index.CorruptIndexException) FileSystemException(java.nio.file.FileSystemException) EOFException(java.io.EOFException) FileNotFoundException(java.io.FileNotFoundException) UncheckedIOException(java.io.UncheckedIOException) AccessDeniedException(java.nio.file.AccessDeniedException) LockObtainFailedException(org.apache.lucene.store.LockObtainFailedException) FileSystemLoopException(java.nio.file.FileSystemLoopException) NotDirectoryException(java.nio.file.NotDirectoryException) DirectoryNotEmptyException(java.nio.file.DirectoryNotEmptyException) IOException(java.io.IOException) FileAlreadyExistsException(java.nio.file.FileAlreadyExistsException) IndexFormatTooOldException(org.apache.lucene.index.IndexFormatTooOldException) EsRejectedExecutionException(org.elasticsearch.common.util.concurrent.EsRejectedExecutionException) AtomicMoveNotSupportedException(java.nio.file.AtomicMoveNotSupportedException) IndexFormatTooNewException(org.apache.lucene.index.IndexFormatTooNewException) FileSystemLoopException(java.nio.file.FileSystemLoopException)

Example 5 with FileSystemLoopException

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);
}
Also used : PrintStream(java.io.PrintStream) IntStream(java.util.stream.IntStream) ICollisionCallback(org.omegat.util.FileUtil.ICollisionCallback) Arrays(java.util.Arrays) Files(java.nio.file.Files) Assert.assertTrue(org.junit.Assert.assertTrue) IOException(java.io.IOException) FileUtils(org.apache.commons.io.FileUtils) Test(org.junit.Test) Logger(java.util.logging.Logger) File(java.io.File) FileNotFoundException(java.io.FileNotFoundException) StandardCharsets(java.nio.charset.StandardCharsets) UncheckedIOException(java.io.UncheckedIOException) List(java.util.List) FileSystemLoopException(java.nio.file.FileSystemLoopException) Assert.assertFalse(org.junit.Assert.assertFalse) After(org.junit.After) Assert.fail(org.junit.Assert.fail) Pattern(java.util.regex.Pattern) UnsupportedEncodingException(java.io.UnsupportedEncodingException) Collections(java.util.Collections) Assert.assertEquals(org.junit.Assert.assertEquals) Before(org.junit.Before) UncheckedIOException(java.io.UncheckedIOException) IOException(java.io.IOException) UncheckedIOException(java.io.UncheckedIOException) FileSystemLoopException(java.nio.file.FileSystemLoopException) File(java.io.File) Test(org.junit.Test)

Aggregations

FileSystemLoopException (java.nio.file.FileSystemLoopException)9 IOException (java.io.IOException)5 AccessDeniedException (java.nio.file.AccessDeniedException)5 FileSystemException (java.nio.file.FileSystemException)5 FileNotFoundException (java.io.FileNotFoundException)4 AtomicMoveNotSupportedException (java.nio.file.AtomicMoveNotSupportedException)4 DirectoryNotEmptyException (java.nio.file.DirectoryNotEmptyException)4 FileAlreadyExistsException (java.nio.file.FileAlreadyExistsException)4 NoSuchFileException (java.nio.file.NoSuchFileException)4 NotDirectoryException (java.nio.file.NotDirectoryException)4 EOFException (java.io.EOFException)3 UncheckedIOException (java.io.UncheckedIOException)3 Path (java.nio.file.Path)3 CorruptIndexException (org.apache.lucene.index.CorruptIndexException)3 IndexFormatTooNewException (org.apache.lucene.index.IndexFormatTooNewException)3 IndexFormatTooOldException (org.apache.lucene.index.IndexFormatTooOldException)3 AlreadyClosedException (org.apache.lucene.store.AlreadyClosedException)3 LockObtainFailedException (org.apache.lucene.store.LockObtainFailedException)3 ElasticsearchException (org.elasticsearch.ElasticsearchException)3 Test (org.junit.Test)3