[Arakhnę-Dev] [193] * Add guards on function parameters. |
[ Thread Index |
Date Index
| More arakhne.org/dev Archives
]
Revision: 193
Author: galland
Date: 2010-10-05 21:29:16 +0200 (Tue, 05 Oct 2010)
Log Message:
-----------
* Add guards on function parameters.
Modified Paths:
--------------
trunk/arakhneVmutils/java/src/main/java/org/arakhne/vmutil/FileSystem.java
Modified: trunk/arakhneVmutils/java/src/main/java/org/arakhne/vmutil/FileSystem.java
===================================================================
--- trunk/arakhneVmutils/java/src/main/java/org/arakhne/vmutil/FileSystem.java 2010-10-05 16:59:30 UTC (rev 192)
+++ trunk/arakhneVmutils/java/src/main/java/org/arakhne/vmutil/FileSystem.java 2010-10-05 19:29:16 UTC (rev 193)
@@ -824,6 +824,7 @@
*/
public static boolean hasExtension(File filename, String extension) {
if (filename==null) return false;
+ assert(extension!=null);
String extent = extension;
if (!"".equals(extent) && !extent.startsWith(EXTENSION_SEPARATOR)) //$NON-NLS-1$
extent = EXTENSION_SEPARATOR+extent;
@@ -845,6 +846,7 @@
*/
public static boolean hasExtension(URL filename, String extension) {
if (filename==null) return false;
+ assert(extension!=null);
String extent = extension;
if (!"".equals(extent) && !extent.startsWith(EXTENSION_SEPARATOR)) //$NON-NLS-1$
extent = EXTENSION_SEPARATOR+extent;
@@ -930,6 +932,7 @@
*/
public static File replaceExtension(File filename, String extension) {
if (filename==null) return null;
+ if (extension==null) return filename;
File dir = filename.getParentFile();
String name = filename.getName();
int idx = name.lastIndexOf(getFileExtensionCharacter());
@@ -946,6 +949,7 @@
*/
public static URL replaceExtension(URL filename, String extension) {
if (filename==null) return null;
+ if (extension==null) return filename;
String path = filename.getPath();
int idx = path.lastIndexOf(URL_PATH_SEPARATOR);
int end = path.length();
@@ -1047,6 +1051,8 @@
* @see #fileCopy(URL, File)
*/
public static void fileCopy(File in, File out) throws IOException {
+ assert(in!=null);
+ assert(out!=null);
FileChannel inChannel = new FileInputStream(in).getChannel();
FileChannel outChannel = new FileOutputStream(out).getChannel();
try {
@@ -1082,6 +1088,8 @@
* @see #fileCopy(File, File)
*/
public static void fileCopy(URL in, File out) throws IOException {
+ assert(in!=null);
+ assert(out!=null);
URLConnection connection = in.openConnection();
ReadableByteChannel inChannel = Channels.newChannel(connection.getInputStream());
FileChannel outChannel = new FileOutputStream(out).getChannel();
@@ -1144,6 +1152,8 @@
* @return the configuration directory of the software for the current user.
*/
public static File getUserConfigurationDirectoryFor(String software) {
+ if (software==null || "".equals(software)) //$NON-NLS-1$
+ throw new IllegalArgumentException();
try {
File userHome = getUserHomeDirectory();
OperatingSystem os = OperatingSystem.getCurrentOS();
@@ -1201,6 +1211,8 @@
* @return the configuration directory of the software for the current user.
*/
public static File getSystemConfigurationDirectoryFor(String software) {
+ if (software==null || "".equals(software)) //$NON-NLS-1$
+ throw new IllegalArgumentException();
OperatingSystem os = OperatingSystem.getCurrentOS();
if (os.isUnixCompliant()) {
File[] roots = File.listRoots();
@@ -1249,6 +1261,8 @@
* @return the configuration directory of the software for the current user.
*/
public static File getSystemSharedLibraryDirectoryFor(String software) {
+ if (software==null || "".equals(software)) //$NON-NLS-1$
+ throw new IllegalArgumentException();
OperatingSystem os = OperatingSystem.getCurrentOS();
if (os.isUnixCompliant()) {
File[] roots = File.listRoots();
@@ -1303,6 +1317,7 @@
* @throws IllegalArgumentException is the URL was malformed.
*/
public static File convertURLToFile(URL url) {
+ if (url==null) return null;
URI uri;
try {
// this is the step that can fail, and so
@@ -1336,7 +1351,7 @@
}
}
- if (URISchemeType.FILE.isURI(uri)) {
+ if (uri!=null && URISchemeType.FILE.isURI(uri)) {
String auth = uri.getAuthority();
String path = uri.getPath();
if (path==null) path = uri.getRawPath();
@@ -1969,6 +1984,7 @@
* @throws MalformedURLException
*/
public static URL getParentURL(URL url) throws MalformedURLException {
+ if (url==null) return url;
String path = url.getPath();
String prefix, parentStr;
@@ -2084,8 +2100,7 @@
*/
public static File normalizeWindowsNativeFilename(String filename) {
String fn = extractLocalPath(filename);
- assert(fn!=null);
- if (fn.length()>0) {
+ if (fn!=null && fn.length()>0) {
Pattern pattern = Pattern.compile(WINDOW_NATIVE_FILENAME_PATTERN);
Matcher matcher = pattern.matcher(fn);
if (matcher.find()) {
@@ -2127,6 +2142,7 @@
* @since 4.0
*/
public static URL toShortestURL(URL url) {
+ if (url==null) return null;
String s = url.toExternalForm().replaceAll("/$", ""); //$NON-NLS-1$//$NON-NLS-2$
String sp;
Iterator<URL> classpath = ClasspathUtil.getClasspath();
@@ -2159,8 +2175,8 @@
* @throws IOException when is is impossible to retreive canonical paths.
*/
public static File makeRelative(File filenameToMakeRelative, File rootPath) throws IOException {
- assert(filenameToMakeRelative!=null);
- assert(rootPath!=null);
+ if (filenameToMakeRelative==null || rootPath==null)
+ throw new IllegalArgumentException();
if (!filenameToMakeRelative.isAbsolute()) return filenameToMakeRelative;
if (!rootPath.isAbsolute()) return filenameToMakeRelative;
@@ -2186,8 +2202,8 @@
* @since 6.0
*/
public static File makeRelative(File filenameToMakeRelative, URL rootPath) throws IOException {
- assert(filenameToMakeRelative!=null);
- assert(rootPath!=null);
+ if (filenameToMakeRelative==null || rootPath==null)
+ throw new IllegalArgumentException();
if (!filenameToMakeRelative.isAbsolute()) return filenameToMakeRelative;
@@ -2211,8 +2227,8 @@
* @since 6.0
*/
public static File makeRelative(URL filenameToMakeRelative, URL rootPath) throws IOException {
- assert(filenameToMakeRelative!=null);
- assert(rootPath!=null);
+ if (filenameToMakeRelative==null || rootPath==null)
+ throw new IllegalArgumentException();
String basename = largeBasename(filenameToMakeRelative);
URL dir = dirname(filenameToMakeRelative);