-2

I'm unit testing some Java code that must parse an input String as a path-name. I'm using Java 7, so the parsed value is a Path object.

The Paths.get method will throw an InvalidPathException

if the path string cannot be converted to a Path

So, to check my parsing code is robust I need a test value that will cause Paths.get to throw that exception. That is, a String value that is not a valid path. What constitutes a valid path is system (even file-system) dependent, so I am specifically interested in a String that is not a valid POSIX path, or (failing that) not a valid Linux path.

Raedwald
  • 46,613
  • 43
  • 151
  • 237
  • I am answering my own question, as is [encouraged](http://blog.stackoverflow.com/2011/07/its-ok-to-ask-and-answer-your-own-questions/). – Raedwald May 15 '14 at 13:16

1 Answers1

0

POSIX path-names may not contain null characters. Therefore a String that consists of a single NUL character (Unicode code-point 0) will be invalid. That is, the String "\0". I can confirm that Open JDK throws a InvalidPathException, with the message Nul character not allowed, for this case.

Community
  • 1
  • 1
Raedwald
  • 46,613
  • 43
  • 151
  • 237