Java error “posix_spawn is not a supported process launch mechanism on this platform” when trying to spawn a process

Symptom:

Java crashes with the error “posix_spawn is not a supported process launch mechanism on this platform” when trying to run a sub-process, eg. with ProcessBuilder or Runtime.exec().

This affects Turkish users and possibly other languages with non-ASCII characters.

Seen on Mac OS X; probably affects other BSD-like systems.

This is a bug in Java, At the time of writing (July 2014) it affects current releases of both Java 7 and 8.

 

To reproduce:

public static void main(final String[] args) throws IOException {
	Locale.setDefault(new Locale("tr", ""));
	Process exec = Runtime.getRuntime().exec("ls");
}

 

Cure:

Explicitly setting the locale to English works, and suited my situation (although it might not suit yours):

Locale.setDefault(Locale.ENGLISH);

A better workaround would be to explicitly set the jdk.lang.Process.launchMechanism system property, either in code or with launch arguments, avoiding the capitalisation problem (see explanation below):

System.setProperty("jdk.lang.Process.launchMechanism", "POSIX_SPAWN");

 

What’s going on here?

It’s a bug in Java; this one: http://bugs.java.com/bugdatabase/view_bug.do?bug_id=8047340.

The problem is in java.lang.UnixProcess, which converts the string “posix_spawn” to upper case, and expects it to be “POSIX_SPAWN”. In Turkish, it’s not; apparently upper case “i” is not “I”.

This entry was posted in Uncategorized. Bookmark the permalink.

Comments are closed.