googleapis / java-storage-nio

Apache License 2.0
68 stars 32 forks source link

CloudStorageFileSystemProvider throwing exception with java 21 #1424

Closed deroffal closed 4 months ago

deroffal commented 4 months ago

Environment details

OS type and version :

Java version :

version : 0.127.19

Steps to reproduce

Hello, Trying to copy a file from a GCP bucket to my application, I noticed that using the method Path#copy(Path, Path, CopyOption...) is throwing an exception with java 21, although it was working well with java 17. Here is an example of code :

    public static void main(String[] args) {
        try {
            Path bucketSource = Paths.get(new URI("gs://my-bucket/file.txt"));

            //copy with FileOutputStream
            Files.copy(bucketSource, new FileOutputStream("./target/fos.txt"));
            System.out.println("copy with FileOutputStream : ok");

            //copy with Path
            Files.copy(bucketSource, Paths.get("./target/path.txt"));
            System.out.println("copy with Path : ok");

        } catch (Exception ex) {
            ex.printStackTrace();
        }
    }

Execution with java 17 :

/Users/ALEXANDRE/.sdkman/candidates/java/17.0.11-tem/bin/java ...
copy with FileOutputStream : ok
copy with Path : ok

Process finished with exit code 0

Execution with java 21 :

/Users/ALEXANDRE/.sdkman/candidates/java/21.0.3-tem/bin/java ...
copy with FileOutputStream : ok
java.lang.UnsupportedOperationException: PosixFileAttributeView
    at com.google.cloud.storage.contrib.nio.CloudStorageFileSystemProvider.getFileAttributeView(CloudStorageFileSystemProvider.java:1023)
    at java.base/java.nio.file.Files.getFileAttributeView(Files.java:1790)
    at java.base/java.nio.file.CopyMoveHelper.copyToForeignTarget(CopyMoveHelper.java:110)
    at java.base/java.nio.file.Files.copy(Files.java:1307)
    at Stat.main(Stat.java:19)

Process finished with exit code 0

Thanks!

BenWhitehead commented 4 months ago

Thank you for reporting, and including a repro. I've added a test and fix for it in #1427