eclipse-vertx/vert.x · error · FileSystemException

Cannot open file for neither reading nor writing

Error message

Cannot open file for neither reading nor writing

What it means

An AsyncFile must be opened in at least read or write mode. The AsyncFileImpl constructor throws this FileSystemException when OpenOptions has both isRead() and isWrite() false, since StandardOpenOption requires at least one access mode for AsynchronousFileChannel.open.

Source

Thrown at vertx-core/src/main/java/io/vertx/core/file/impl/AsyncFileImpl.java:79

  private boolean closed;
  private Runnable closedDeferred;
  private long writesOutstanding;
  private boolean overflow;
  private Handler<Throwable> exceptionHandler;
  private Handler<Void> drainHandler;
  private long writePos;
  private int maxWrites = 128 * 1024;    // TODO - we should tune this for best performance
  private int lwm = maxWrites / 2;
  private int readBufferSize = DEFAULT_READ_BUFFER_SIZE;
  private InboundBuffer<Buffer> queue;
  private Handler<Buffer> handler;
  private Handler<Void> endHandler;
  private long readPos;
  private long readLength = Long.MAX_VALUE;

  AsyncFileImpl(VertxInternal vertx, String path, OpenOptions options, ContextInternal context) {
    if (!options.isRead() && !options.isWrite()) {
      throw new FileSystemException("Cannot open file for neither reading nor writing");
    }
    this.vertx = vertx;
    Path file = Paths.get(path);
    HashSet<OpenOption> opts = new HashSet<>();
    if (options.isRead()) opts.add(StandardOpenOption.READ);
    if (options.isWrite()) opts.add(StandardOpenOption.WRITE);
    if (options.isCreate()) opts.add(StandardOpenOption.CREATE);
    if (options.isCreateNew()) opts.add(StandardOpenOption.CREATE_NEW);
    if (options.isSync()) opts.add(StandardOpenOption.SYNC);
    if (options.isDsync()) opts.add(StandardOpenOption.DSYNC);
    if (options.isDeleteOnClose()) opts.add(StandardOpenOption.DELETE_ON_CLOSE);
    if (options.isSparse()) opts.add(StandardOpenOption.SPARSE);
    if (options.isTruncateExisting()) opts.add(StandardOpenOption.TRUNCATE_EXISTING);
    try {
      if (options.getPerms() != null) {
        FileAttribute<?> attrs = PosixFilePermissions.asFileAttribute(PosixFilePermissions.fromString(options.getPerms()));
        ch = AsynchronousFileChannel.open(file, opts, vertx.workerPool().executor(), attrs);
      } else {

View on GitHub (pinned to fb308bd8c3)

Solutions

  1. Set at least one access mode: options.setRead(true) and/or options.setWrite(true) before open().
  2. For read-modify-write use both: new OpenOptions().setRead(true).setWrite(true).
  3. Validate the OpenOptions loaded from configuration before passing it to fileSystem().open().

Example fix

// before
OpenOptions opts = new OpenOptions(); // read=false, write=false
fileSystem.open("f.txt", opts);
// after
OpenOptions opts = new OpenOptions().setRead(true).setWrite(true);
fileSystem.open("f.txt", opts);
Defensive patterns

Strategy: validation

Validate before calling

if (!options.isRead() && !options.isWrite()) {
  throw new IllegalArgumentException("OpenOptions must set read and/or write");
}
fileSystem.open(path, options);

Try / catch

try {
  fileSystem.open(path, options);
} catch (FileSystemException e) {
  // neither read nor write requested; fix OpenOptions
}

Prevention

When it happens

Trigger: Calling vertx.fileSystem().open(path, new OpenOptions()) with neither setRead(true) nor setWrite(true) - the OpenOptions default has both false.

Common situations: Creating 'new OpenOptions()' without setting any flags before open(); refactoring that removed setWrite(true) but forgot setRead(true); building options from config where the read/write booleans defaulted to false.

Understand the failure class

Background: "Must be a positive integer", "Invalid value", "Unsupported": the invalid-argument-value error family, when a library rejects the value you pass — this error's family across 35 libraries.

Related errors


AI-assisted analysis of eclipse-vertx/vert.x@fb308bd8c3 (2026-09-06). Data as JSON: /api/errors/8ac5db41b5f7d2f2. Report an issue: GitHub.