Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CloudStorageFileSystemProvider throwing exception with java 21 #1424

Closed
deroffal opened this issue Jun 24, 2024 · 1 comment · Fixed by #1427
Closed

CloudStorageFileSystemProvider throwing exception with java 21 #1424

deroffal opened this issue Jun 24, 2024 · 1 comment · Fixed by #1427
Labels
api: storage Issues related to the googleapis/java-storage-nio API.

Comments

@deroffal
Copy link

Environment details

OS type and version :

  • Ubuntu 22
  • Maco OS 14

Java version :

  • jdk 17 :
openjdk version "17.0.11" 2024-04-16
OpenJDK Runtime Environment Temurin-17.0.11+9 (build 17.0.11+9)
OpenJDK 64-Bit Server VM Temurin-17.0.11+9 (build 17.0.11+9, mixed mode)
  • jdk 21 :
openjdk version "21.0.3" 2024-04-16 LTS
OpenJDK Runtime Environment Temurin-21.0.3+9 (build 21.0.3+9-LTS)
OpenJDK 64-Bit Server VM Temurin-21.0.3+9 (build 21.0.3+9-LTS, mixed mode)

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!

@product-auto-label product-auto-label bot added the api: storage Issues related to the googleapis/java-storage-nio API. label Jun 24, 2024
BenWhitehead added a commit that referenced this issue Jun 25, 2024
…turn null rather than throw UnsupportedOperationException

Currently, when CloudStorageFileSystemProvider#getFileAttributeView is invoked with a class it doesn't recognize it throws an UnsupportedOperationException. The javadocs for FileSystemProvider, however specify that #getFileAttributeView[1] return null if the attribute view type is not available.

This change updates the behavior of CloudStorageFileSystemProvider#getFileAttributeView to return null rather than throw an exception.

Fixes #1424

[1] https://docs.oracle.com/en/java/javase/21/docs/api/java.base/java/nio/file/spi/FileSystemProvider.html#getFileAttributeView(java.nio.file.Path,java.lang.Class,java.nio.file.LinkOption...)
@BenWhitehead
Copy link
Collaborator

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
api: storage Issues related to the googleapis/java-storage-nio API.
Projects
None yet
2 participants