TempFileHelper java.lang.IllegalArgumentException: Invalid prefix or suffix

Michael Hall mik3hall at gmail.com
Tue Aug 31 15:24:26 UTC 2021


I am getting this error on code running on a recently downloaded 18 ea.

The exception crawl

java.lang.IllegalArgumentException: Invalid prefix or suffix
	at java.base/java.nio.file.TempFileHelper.generatePath(Unknown Source)
	at java.base/java.nio.file.TempFileHelper.create(Unknown Source)
	at java.base/java.nio.file.TempFileHelper.createTempFile(Unknown Source)
	at java.base/java.nio.file.Files.createTempFile(Unknown Source)
	at apple.applescript.AppleScriptEngine.eval(AppleScriptEngine.java:302)
	at apple.applescript.AppleScriptEngine.eval(AppleScriptEngine.java:267)
	at org.cmdline.cmds.Mps.main(Mps.java:28)
	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
	at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
	at java.base/java.lang.reflect.Method.invoke(Unknown Source)
	at org.cmdline.psuedoGestalt.Runner.invoke(Runner.java:209)
	at org.cmdline.psuedoGestalt.Runner.runStatic(Runner.java:236)
	at org.cmdline.psuedoGestalt.Runner.runMain(Runner.java:228)
	at org.cmdline.psuedoGestalt.Runner.run(Runner.java:146)

I believe the error might be coming from TempFileHelper here…

       SecurityManager sm = System.getSecurityManager();
        for (;;) {
            Path f;
            try {
                f = generatePath(prefix, suffix, dir);
            } catch (InvalidPathException e) {
                // don't reveal temporary directory location
                if (sm != null)
                    throw new IllegalArgumentException("Invalid prefix or suffix");
                throw e;

Or possibly generatePath which I think has a similar error.

The code causing the error is…

tmpfile = Files.createTempFile("AppleScriptEngine.", ".scpt").toFile();

This hasn’t been changed by me. Doing this line jshell works. Running the code standalone outside my application works. I think the reason my application fails is that it includes a SecurityManager.

First question. Is “Invalid prefix or suffix” really the best error message for this?

Second question; I have noticed things in the works for the elimination of SecurityManager. However, I thought this was still in the deprecation/warning stages. Should it be causing my code to fail if it is?


More information about the nio-dev mailing list