Application initiated file copy command does not work in macOS Catalina & Big Sur

Our application has a backup function that is initiated by a user. The backup function simply makes a copy of the data files to another target folder the user chooses. This function worked fine in Mojave but stopped working in Catalina and Big Sur. I understand that starting in Catalina, Apple introduced security features to ensure 3rd party applications protect their data. I did add the application to Full Disk Access and Files and Folders under System Preferences >> Security & Privacy. In retesting this backup function, it still does not allow the application to make a copy of the data files to another target folder. Any thoughts on what to try next?
Is your app sandboxed?

What API are you using to do the copy?

When it fails, do you get an error? If so, what is that error?

Share and Enjoy

Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@" + "apple.com"

I am not sure what you mean by "is your app sandboxed". Is it in a sandbox test environment? ... to that the answer is no. No error is displayed. The code that initiates the file copy (that worked before on macOS Mojave) of what we're using for backup purposes is:

public static void copyFile(File src, File dest) throws Exception
{
InputStream in = new FileInputStream(src);
OutputStream out = new FileOutputStream(dest);

// Transfer bytes from in to out 1000k buffer
byte[] buf = new byte[1024 * 1000];
int len;

while ((len = in.read(buf)) > 0)
out.write(buf, 0, len);

out.flush();
in.close();
out.close();

}

Code is pretty basic java code that writes bytes from a source to a destination.

I am not sure what you mean by "is your app sandboxed".

I was specifically referring to the App Sandbox (but also see App Sandbox Design Guide which has more details).

Code is pretty basic java code

Oh, you coulda mentioned that earlier (-: Java is weird for all sorts of reasons.

No error is displayed.

Does this code throw an exception? If so, what?

In a typical case what are the source and destination paths?

Share and Enjoy

Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@" + "apple.com"
I appreciate your help! Here is the stack trace on Big Sur:

2021-04-29 23:09:41,071 ERROR com.hrc.utilities.Helper (Helper.java:1272) Could not copy from ../../../.. to /Users/matt/Desktop/Jones Merle M 04.29.2021
java.lang.NullPointerException
     at com.hrc.utilities.Helper.copyDirectory(Helper.java:1252)
     at com.hrc.common.BackupFacade.backup(BackupFacade.java:69)
     at com.hrc.ui.util.DialogDisplayHub$5.doInBackground(DialogDisplayHub.java:922)
     at com.hrc.ui.util.DialogDisplayHub$5.doInBackground(DialogDisplayHub.java:910)
     at org.jdesktop.swingworker.SwingWorker$1.call(Unknown Source)
     at java.util.concurrent.FutureTask.run(FutureTask.java:266)
     at org.jdesktop.swingworker.SwingWorker.run(Unknown Source)
     at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
     at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
     at java.lang.Thread.run(Thread.java:748)

Again, as a sanity check, I ran the same backup code (i.e. straight file copy from source to destination) on Mojave with no issues. The source is from a USB drive (where the portable application runs) and the destination is to the local workstation drive folder the user chooses. Only difference here is the environment of Mojave and Big Sur.

java.lang.NullPointerException

Well, that’s not very helpful. I was hoping that the Java exception would give you some clue as to what’s going on at the file system layer, but a null pointer exception just means that the Java code got itself confused and crashed.

Could not copy from ../../../.. to /Users/matt/Desktop/Jones Merle M 04.29.2021

OK, based on the destination path it’s very likely that you’re tripping over the mandatory access control stuff that I discuss in On File System Permissions. However, it’s hard to be sure because of the above-mentioned failure.

There’s two questions you need answered here:
  • Why are you getting a null pointer exception? Looking at the source of that exception it seems to be in your code (com.hrc.utilities.Helper.copyDirectory). My guess is that some file system call has failed with EPERM and this code has then crashed trying to handle that error, but that’s just a guess. The only way to know for sure is to debug it at the Java level.

  • Why are you not getting the MAC prompt? I’ve seen problems like this before and they are usually the result of a packaging issue, that is, your app is structured in a way that confuses the MAC system. I recommend that you escalate this via the support channel for you Java runtime. It’s likely that they’ve seen it before and know the resolution.

Share and Enjoy

Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@" + "apple.com"
Application initiated file copy command does not work in macOS Catalina & Big Sur
 
 
Q