< prev index next >
test/jdk/java/lang/ProcessBuilder/Basic.java
Print this page
@@ -72,10 +72,15 @@
static final String cfUserTextEncoding = System.getenv("__CF_USER_TEXT_ENCODING");
/* used for AIX only */
static final String libpath = System.getenv("LIBPATH");
+ /* Used for regex String matching for long error messages */
+ static final String PERMISSION_DENIED_ERROR_MSG = "(Permission denied|error=13, The file access permissions do not allow the specified action)";
+ static final String NO_SUCH_FILE_ERROR_MSG = "(No such file|error=2, A file or directory in the path name does not exist.)";
+ static final String NO_SUCH_FILE_OR_DIR_ERROR_MSG = "(No such file or directory|error=2, A file or directory in the path name does not exist)";
+
/**
* Returns the number of milliseconds since time given by
* startNanoTime, which must have been previously returned from a
* call to {@link System.nanoTime()}.
*/
@@ -303,11 +308,11 @@
pb.start();
fail("Expected IOException not thrown");
} catch (IOException e) {
String m = e.getMessage();
if (EnglishUnix.is() &&
- ! matches(m, "Permission denied"))
+ ! matches(m, PERMISSION_DENIED_ERROR_MSG))
unexpected(e);
} catch (Throwable t) { unexpected(t); }
}
public static class JavaChild {
@@ -413,11 +418,11 @@
pb.start();
fail("Expected IOException not thrown");
} catch (IOException e) {
String m = e.getMessage();
if (EnglishUnix.is() &&
- ! matches(m, "No such file"))
+ ! matches(m, NO_SUCH_FILE_ERROR_MSG))
unexpected(e);
} catch (Throwable t) { unexpected(t); }
// Not on PATH at all; directories exist
new File("dir1").mkdirs();
@@ -426,11 +431,11 @@
pb.start();
fail("Expected IOException not thrown");
} catch (IOException e) {
String m = e.getMessage();
if (EnglishUnix.is() &&
- ! matches(m, "No such file"))
+ ! matches(m, NO_SUCH_FILE_ERROR_MSG))
unexpected(e);
} catch (Throwable t) { unexpected(t); }
// Can't execute a directory -- permission denied
// Report EACCES errno
@@ -1980,11 +1985,11 @@
new ProcessBuilder("").start();
fail("Expected IOException not thrown");
} catch (IOException e) {
String m = e.getMessage();
if (EnglishUnix.is() &&
- ! matches(m, "No such file or directory"))
+ ! matches(m, NO_SUCH_FILE_OR_DIR_ERROR_MSG))
unexpected(e);
} catch (Throwable t) { unexpected(t); }
//----------------------------------------------------------------
// Check that attempt to execute program name with funny
@@ -1996,12 +2001,12 @@
fail("Expected IOException not thrown");
} catch (IOException e) {
String m = e.getMessage();
Pattern p = Pattern.compile(programName);
if (! matches(m, programName)
- || (EnglishUnix.is()
- && ! matches(m, "No such file or directory")))
+ || (EnglishUnix.is() &&
+ ! matches(m, NO_SUCH_FILE_OR_DIR_ERROR_MSG)))
unexpected(e);
} catch (Throwable t) { unexpected(t); }
//----------------------------------------------------------------
// Attempt to start process in nonexistent directory fails.
@@ -2013,11 +2018,11 @@
fail("Expected IOException not thrown");
} catch (IOException e) {
String m = e.getMessage();
if (! matches(m, "in directory")
|| (EnglishUnix.is() &&
- ! matches(m, "No such file or directory")))
+ ! matches(m, NO_SUCH_FILE_OR_DIR_ERROR_MSG)))
unexpected(e);
} catch (Throwable t) { unexpected(t); }
//----------------------------------------------------------------
// Attempt to write 4095 bytes to the pipe buffer without a
@@ -2293,11 +2298,11 @@
fail("Expected IOException not thrown");
} catch (IOException e) {
new File("./emptyCommand").delete();
String m = e.getMessage();
if (EnglishUnix.is() &&
- ! matches(m, "Permission denied"))
+ ! matches(m, PERMISSION_DENIED_ERROR_MSG))
unexpected(e);
} catch (Throwable t) { unexpected(t); }
new File("emptyCommand").delete();
< prev index next >