Skip to content

[Native Image] ExtendedOpenOption.DIRECT failing with --future-defaults=all #12567

@dennishendriksen

Description

@dennishendriksen

Describe the Issue

I'm running into an issue with GraalVM CE 25.0.1 when using ExtendedOpenOption.DIRECT together with --future-defaults.

Example on a Linux system supporting O_DIRECT:

dd if=/dev/zero of=four_kb_file oflag=direct bs=4k count=1
# DirectSupportedApp.java
import com.sun.nio.file.ExtendedOpenOption;
import java.io.IOException;
import java.nio.channels.FileChannel;
import java.nio.file.Path;
import java.nio.file.StandardOpenOption;

public class DirectSupportedApp {
  public static void main(String[] args) throws IOException {
    try(FileChannel fileChannel = FileChannel.open(Path.of("four_kb_file"), StandardOpenOption.READ, ExtendedOpenOption.DIRECT)) {
      System.out.println(fileChannel.size());
    }
  }
}

works without native image

> $ javac DirectSupportedApp.java;java DirectSupportedApp
> 4096

works with native image as well

> $ native-image -cp . DirectSupportedApp; ./directsupportedapp
> 4096

doesn't work with native image with future defaults

> $ native-image --future-defaults=all -cp . DirectSupportedApp; ./directsupportedapp
$ ./directsupportedapp
Exception in thread "main" java.lang.UnsupportedOperationException: DIRECT not supported
        at java.base@25/sun.nio.fs.UnixChannelFactory$Flags.toFlags(UnixChannelFactory.java:100)
        at java.base@25/sun.nio.fs.UnixChannelFactory.newFileChannel(UnixChannelFactory.java:115)
        at java.base@25/sun.nio.fs.UnixChannelFactory.newFileChannel(UnixChannelFactory.java:145)
        at java.base@25/sun.nio.fs.UnixFileSystemProvider.newFileChannel(UnixFileSystemProvider.java:211)
        at java.base@25/java.nio.channels.FileChannel.open(FileChannel.java:301)
        at java.base@25/java.nio.channels.FileChannel.open(FileChannel.java:353)
        at DirectSupportedApp.main(DirectSupportedApp.java:9)
        at java.base@25/java.lang.invoke.LambdaForm$DMH/sa346b79c.invokeStaticInit(LambdaForm$DMH)

works with native image with future defaults subset

> $ native-image --future-defaults=run-time-initialize-security-providers,complete-reflection-types -cp . DirectSupportedApp; ./directsupportedapp
> 4096

Since I'm building and running on the same machine I would not expect the failures.

This issue was brought to the attention of vjovanov who suggested this ticket is for @zapster.

Using the latest version of GraalVM can resolve many issues.

GraalVM Version

.

Operating System and Version

.

Troubleshooting Confirmation

Run Command

.

Expected Behavior

.

Actual Behavior

.

Steps to Reproduce

.

Additional Context

No response

Run-Time Log Output and Error Messages

No response

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions