RFR: 8314498: [macos] Transferring File objects to Finder fails [v2]

Arik Hadas duke at openjdk.org
Fri Sep 29 19:35:33 UTC 2023


> Credit goes to JetBrain that fixed it in JetBrainsRuntime (commit 24819d9). This fix was also cherry-picked to muCommander and was verified on macOS 12.6.8 and macOs 13, on X86_64 and on M1.
> 
> Reproducer/step-to-verify:
> 1. Compile the following class:
> 
> import java.awt.Toolkit;
> import java.awt.datatransfer.DataFlavor;
> import java.awt.datatransfer.Transferable;
> import java.awt.datatransfer.UnsupportedFlavorException;
> import java.io.IOException;
> import java.nio.file.Files;
> import java.nio.file.Path;
> import java.util.Arrays;
> 
> public class Arik {
> 
>     public static void main(String[] args) throws IOException, UnsupportedFlavorException {
>         System.out.println("copying a file to the clipboard2");
>         var path = Files.createTempFile(null, null);
>         Files.writeString(path.toAbsolutePath(), "test");
>         Toolkit.getDefaultToolkit().getSystemClipboard().setContents(new MyTransferable(path), null);
>         try {
>             Thread.sleep(Long.MAX_VALUE);
>         } catch (InterruptedException e) {
>         }
>     }
> 
>     public static class MyTransferable implements Transferable {
>         private Path path;
> 
>         MyTransferable(Path path) {
>             this.path = path;
>         }
> 
>         @Override
>         public DataFlavor[] getTransferDataFlavors() {
>             return new DataFlavor[] { DataFlavor.javaFileListFlavor };
>         }
> 
>         @Override
>         public boolean isDataFlavorSupported(DataFlavor flavor) {
>             return flavor.equals(DataFlavor.javaFileListFlavor);
>         }
> 
>         @Override
>         public Object getTransferData(DataFlavor flavor) throws UnsupportedFlavorException, IOException {
>             return Arrays.asList(path.toFile());
>         }
>         
>     }
> }
> 
> 2. Run the compiled class using current JRE (`java Arik`)
> 3. Switch to Finder and check the content of the clipboard (`Edit -> Show Clipboard`)
> 4. Verify you see "Cliboard contents: unknown" as in the following screenshot:
> <img width="479" alt="clipboard-before" src="https://github.com/openjdk/jdk/assets/6020068/71d29b2e-209f-4445-a1e0-ecb3fc3e388b">
> 
> 5. Verify you cannot paste the content of the clipboard to Finder (`Edit -> Paste` is disabled)
> 6. Run the compiled class using JRE that includes this change (`java Arik`)
> 7. 3. Switch to Finder and check the content of the clipboard (`Edit -> Show Clipboard`)
> 8. Verify you see "Cliboard contents: file URL / items" as in the following screenshot:
> <img width="479" alt="clipboard-after" src="https://github.com/openjdk/jdk/ass...

Arik Hadas has refreshed the contents of this pull request, and previous commits have been removed. The incremental views will show differences compared to the previous content of the PR. The pull request contains one new commit since the last revision:

  8314498: [macos] Transferring File objects to Finder fails
  
  Credit goes to JetBrain that fixed it in JetBrainsRuntime (commit 24819d9).
  This fix was also cherry-picked to muCommander and was verified on macOS
  12.6.8 and macOs 13, on X86_64 and on M1.

-------------

Changes:
  - all: https://git.openjdk.org/jdk/pull/15980/files
  - new: https://git.openjdk.org/jdk/pull/15980/files/71ac872e..c7a0e59e

Webrevs:
 - full: https://webrevs.openjdk.org/?repo=jdk&pr=15980&range=01
 - incr: https://webrevs.openjdk.org/?repo=jdk&pr=15980&range=00-01

  Stats: 0 lines in 0 files changed: 0 ins; 0 del; 0 mod
  Patch: https://git.openjdk.org/jdk/pull/15980.diff
  Fetch: git fetch https://git.openjdk.org/jdk.git pull/15980/head:pull/15980

PR: https://git.openjdk.org/jdk/pull/15980


More information about the client-libs-dev mailing list