Test value(s) for an invalid Linux path-name for Java code

孤者浪人 提交于 2019-12-13 10:52:35

问题


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.


回答1:


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.



来源:https://stackoverflow.com/questions/23679391/test-values-for-an-invalid-linux-path-name-for-java-code

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!