[Arakhnę-Dev] [140] Make more robust against malformed filenames.

[ Thread Index | Date Index | More arakhne.org/dev Archives ]


Revision: 140
Author:   galland
Date:     2010-05-07 10:06:53 +0200 (Fri, 07 May 2010)
Log Message:
-----------
Make more robust against malformed filenames.

Modified Paths:
--------------
    trunk/arakhneVmutils/java/src/main/java/org/arakhne/vmutil/FileSystem.java
    trunk/arakhneVmutils/java/src/main/java/org/arakhne/vmutil/Resources.java
    trunk/arakhneVmutils/java/src/test/java/org/arakhne/vmutil/FileSystemTest.java
    trunk/arakhneVmutils/java/src/test/java/org/arakhne/vmutil/ResourcesTest.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-05-07 08:06:27 UTC (rev 139)
+++ trunk/arakhneVmutils/java/src/main/java/org/arakhne/vmutil/FileSystem.java	2010-05-07 08:06:53 UTC (rev 140)
@@ -257,6 +257,8 @@
 		else
 			path = filename.getPath();
 		
+		if ("".equals(path)) return null; //$NON-NLS-1$
+		
 		int idx = path.lastIndexOf(URL_PATH_SEPARATOR_CHAR);
 		if (idx==path.length()-1)
 			idx = path.lastIndexOf(URL_PATH_SEPARATOR_CHAR, path.length()-2);
@@ -281,16 +283,29 @@
 			return null;
 		}
 	}
-
+	
 	/** Replies the basename of the specified file with the extension.
+	 * <p>
+	 * Caution: This function does not support URL format.
 	 *
 	 * @param filename is the name to parse.
 	 * @return the basename of the specified file with the extension.
 	 */
 	public static String largeBasename(String filename) {
 		if (filename==null) return null;
-		int idx = filename.lastIndexOf(File.separatorChar);
-		return (idx<0) ? filename : filename.substring(idx+1);
+		int end = filename.length();
+		int idx;
+		do {
+			end--;
+			idx = filename.lastIndexOf(File.separatorChar, end);
+		}
+		while (idx>=0 && end>=0 && idx>=end);
+		if (idx<0) {
+			if (end<filename.length()-1)
+				return filename.substring(0, end+1);
+			return filename;
+		}
+		return filename.substring(idx+1, end+1);
 	}
 
 	/** Replies the basename of the specified file with the extension.
@@ -311,17 +326,24 @@
 	public static String largeBasename(URL filename) {
 		if (filename==null) return null;
 		String fullPath = filename.getPath();
-		int idx = fullPath.lastIndexOf(URL_PATH_SEPARATOR_CHAR);
+		int idx;
 		int end = fullPath.length();
-		if (idx==end-1) {
-			end --;
-			idx = fullPath.lastIndexOf(URL_PATH_SEPARATOR_CHAR, end-1);
+		do {
+			end--;
+			idx = fullPath.lastIndexOf(URL_PATH_SEPARATOR_CHAR, end);
 		}
-		if (idx<0) idx = -1;
-		return fullPath.substring(idx+1, end);
+		while (idx>=0 && end>=0 && idx>=end);
+		if (idx<0) {
+			if (end<fullPath.length()-1)
+				return fullPath.substring(0, end+1);
+			return fullPath;
+		}
+		return fullPath.substring(idx+1, end+1);
 	}
 
 	/** Reply the basename of the specified file without the last extension.
+	 * <p>
+	 * Caution: This function does not support URL format.
 	 *
 	 * @param filename is the name to parse.
 	 * @return the basename of the specified file without the last extension.
@@ -330,8 +352,22 @@
 	 */
 	public static String basename(String filename) {
 		if (filename==null) return null;
-		int idx = filename.lastIndexOf(File.separatorChar);
-		String basename = (idx<0) ? filename : filename.substring(idx+1);
+		int end = filename.length();
+		int idx;
+		do {
+			end--;
+			idx = filename.lastIndexOf(File.separatorChar, end);
+		}
+		while (idx>=0 && end>=0 && idx>=end);
+		String basename;
+		if (idx<0) {
+			if (end<filename.length()-1)
+				basename = filename.substring(0, end+1);
+			else
+				basename = filename;
+		}
+		else
+			basename =filename.substring(idx+1, end+1);
 		idx = basename.lastIndexOf(getFileExtensionCharacter());
 		if (idx<0) return basename;
 		return basename.substring(0,idx);
@@ -366,28 +402,53 @@
 	public static String basename(URL filename) {
 		if (filename==null) return null;
 		String largeBasename = filename.getPath();
-		int idx = largeBasename.lastIndexOf(URL_PATH_SEPARATOR_CHAR);
 		int end = largeBasename.length();
-		if (idx==end-1) {
-			end --;
-			idx = largeBasename.lastIndexOf(URL_PATH_SEPARATOR_CHAR, end-1);
+		int idx;
+		do {
+			end--;
+			idx = largeBasename.lastIndexOf(URL_PATH_SEPARATOR_CHAR, end);
 		}
-		if (idx<0) idx = -1;
-		largeBasename = largeBasename.substring(idx+1, end);
-		idx = largeBasename.lastIndexOf(getFileExtensionCharacter());
-		if (idx<0) return largeBasename;
-		return largeBasename.substring(0,idx);
+		while (idx>=0 && end>=0 && idx>=end);
+		String basename;
+		if (idx<0) {
+			if (end<largeBasename.length()-1)
+				basename = largeBasename.substring(0, end+1);
+			else
+				basename = largeBasename;
+		}
+		else
+			basename = largeBasename.substring(idx+1, end+1);
+		idx = basename.lastIndexOf(getFileExtensionCharacter());
+		if (idx<0) return basename;
+		return basename.substring(0,idx);
 	}
 
 	/** Reply the basename of the specified file without all the extensions.
+	 * <p>
+	 * Caution: This function does not support URL format.
 	 *
 	 * @param filename is the name to parse.
 	 * @return the basename of the specified file without all the extensions.
 	 */
 	public static String shortBasename(String filename) {
 		if (filename==null) return null;
-		int idx = filename.lastIndexOf(File.separatorChar);
-		String basename = (idx<0) ? filename : filename.substring(idx+1);
+		int idx;
+		int end = filename.length();
+		do {
+			end--;
+			idx = filename.lastIndexOf(URL_PATH_SEPARATOR_CHAR, end);
+		}
+		while (idx>=0 && end>=0 && idx>=end);
+		String basename;
+		if (idx<0) {
+			if (end<filename.length()-1)
+				basename = filename.substring(0, end+1);
+			else
+				basename = filename;
+		}
+		else
+			basename = filename.substring(idx+1, end+1);
+		
 		idx = basename.indexOf(getFileExtensionCharacter());
 		if (idx<0) return basename;
 		return basename.substring(0,idx);
@@ -414,17 +475,26 @@
 	public static String shortBasename(URL filename) {
 		if (filename==null) return null;
 		String largeBasename = filename.getPath();
-		int idx = largeBasename.lastIndexOf(URL_PATH_SEPARATOR_CHAR);
+		int idx;
 		int end = largeBasename.length();
-		if (idx==end-1) {
-			end --;
-			idx = largeBasename.lastIndexOf(URL_PATH_SEPARATOR_CHAR, end-1);
+		do {
+			end--;
+			idx = largeBasename.lastIndexOf(URL_PATH_SEPARATOR_CHAR, end);
 		}
-		if (idx<0) idx = -1;
-		largeBasename = largeBasename.substring(idx+1, end);
-		idx = largeBasename.indexOf(getFileExtensionCharacter());
-		if (idx<0) return largeBasename;
-		return largeBasename.substring(0,idx);
+		while (idx>=0 && end>=0 && idx>=end);
+		String basename;
+		if (idx<0) {
+			if (end<largeBasename.length()-1)
+				basename = largeBasename.substring(0, end+1);
+			else
+				basename = largeBasename;
+		}
+		else
+			basename = largeBasename.substring(idx+1, end+1);
+		
+		idx = basename.indexOf(getFileExtensionCharacter());
+		if (idx<0) return basename;
+		return basename.substring(0,idx);
 	}
 
 	/** Reply the extension of the specified file.

Modified: trunk/arakhneVmutils/java/src/main/java/org/arakhne/vmutil/Resources.java
===================================================================
--- trunk/arakhneVmutils/java/src/main/java/org/arakhne/vmutil/Resources.java	2010-05-07 08:06:27 UTC (rev 139)
+++ trunk/arakhneVmutils/java/src/main/java/org/arakhne/vmutil/Resources.java	2010-05-07 08:06:53 UTC (rev 140)
@@ -67,7 +67,7 @@
      * not found in class paths.
      */
     public static URL getResource(Class<?> clazz, String path) {
-    	return getResource(clazz.getClassLoader(), path);
+    	return getResource(clazz==null? null : clazz.getClassLoader(), path);
     }
 
    	/**
@@ -83,14 +83,22 @@
      * not found in class paths.
      */
     public static URL getResource(ClassLoader classLoader, String path) {
+    	if (path==null) return null;
     	String resourcePath = path;
     	if (path.startsWith("/")) { //$NON-NLS-1$
     		resourcePath = path.substring(1);
     	}
-    	URL url = classLoader.getResource(resourcePath);
+    	
+    	ClassLoader loader = (classLoader==null)
+    			? Resources.class.getClassLoader()
+    			: classLoader;
+    	assert(loader!=null);
+    			
+    	URL url = loader.getResource(resourcePath);
+    	
     	if (url==null) {
     		// Try to find in ./resources sub directory
-    		url = classLoader.getResource("resources/"+resourcePath); //$NON-NLS-1$
+    		url = loader.getResource("resources/"+resourcePath); //$NON-NLS-1$
     	}
     	return url;
     }
@@ -123,7 +131,7 @@
      * not found in class paths.
      */
     public static InputStream getResourceAsStream(Class<?> clazz, String path) {
-    	return getResourceAsStream(clazz.getClassLoader(), path);
+    	return getResourceAsStream(clazz==null ? null : clazz.getClassLoader(), path);
     }
 
     /**
@@ -139,14 +147,19 @@
      * not found in class paths.
      */
     public static InputStream getResourceAsStream(ClassLoader classLoader, String path) {
+    	if (path==null) return null;
     	String resourcePath = path;
     	if (path.startsWith("/")) { //$NON-NLS-1$
     		resourcePath = path.substring(1);
     	}
-    	InputStream is = classLoader.getResourceAsStream(resourcePath);
+    	ClassLoader loader = (classLoader==null)
+    						? Resources.class.getClassLoader()
+    						: classLoader;
+    	assert(loader!=null);
+    	InputStream is = loader.getResourceAsStream(resourcePath);
     	if (is==null) {
     		// Try to find in ./resources sub directory
-    		is = classLoader.getResourceAsStream("resources/"+resourcePath); //$NON-NLS-1$
+    		is = loader.getResourceAsStream("resources/"+resourcePath); //$NON-NLS-1$
     	}
     	return is;
     }

Modified: trunk/arakhneVmutils/java/src/test/java/org/arakhne/vmutil/FileSystemTest.java
===================================================================
--- trunk/arakhneVmutils/java/src/test/java/org/arakhne/vmutil/FileSystemTest.java	2010-05-07 08:06:27 UTC (rev 139)
+++ trunk/arakhneVmutils/java/src/test/java/org/arakhne/vmutil/FileSystemTest.java	2010-05-07 08:06:53 UTC (rev 140)
@@ -85,9 +85,32 @@
 			throw new AssertionFailedError(e.getLocalizedMessage());
 		}
 	}
+
+	private boolean oldLibraryLoaderState;
 	
 	/**
+	 * {@inheritDoc}
 	 */
+	@Override
+	public void setUp() throws Exception {
+		super.setUp();
+		// Disable native library loading during unit tests
+		this.oldLibraryLoaderState = LibraryLoader.isEnable();
+		LibraryLoader.setEnable(false);
+	}
+	
+	/**
+	 * {@inheritDoc}
+	 */
+	@Override
+	public void tearDown() throws Exception {
+		// Restore library loading state
+		LibraryLoader.setEnable(this.oldLibraryLoaderState);
+		super.tearDown();
+	}
+
+	/**
+	 */
 	public void tetIsJarURLURL() {
 		assertFalse(FileSystem.isJarURL(u1));
 		assertFalse(FileSystem.isJarURL(u2));
@@ -149,16 +172,20 @@
 	public void testDirnameFile() {
 		assertEquals(pf1, FileSystem.dirname(f1));
 		assertEquals(pf2, FileSystem.dirname(f2));
+		assertNull(FileSystem.dirname(new File("/"))); //$NON-NLS-1$
 	}
 
 	/**
+	 * @throws MalformedURLException 
 	 */
-	public void testDirnameURL() {
+	public void testDirnameURL() throws MalformedURLException {
 		assertEquals(pu1, FileSystem.dirname(u1));
 		assertEquals(pu2, FileSystem.dirname(u2));
 		assertEquals(pu3, FileSystem.dirname(u3));
 		assertEquals(pu7, FileSystem.dirname(u7));
 		assertEquals(pu13, FileSystem.dirname(u13));
+		assertEquals(new URL("file:///"), FileSystem.dirname(new URL("file:///a/"))); //$NON-NLS-1$ //$NON-NLS-2$
+		assertNull(FileSystem.dirname(new URL("file://"))); //$NON-NLS-1$
 	}
 
 	/**
@@ -166,6 +193,8 @@
 	public void testLargeBasenameString() {
 		assertEquals("test.x.z.z", FileSystem.largeBasename(f1.getAbsolutePath())); //$NON-NLS-1$
 		assertEquals("home", FileSystem.largeBasename(f2.getAbsolutePath())); //$NON-NLS-1$
+		assertEquals("a.b.c", FileSystem.largeBasename("file:///a.b.c/")); //$NON-NLS-1$ //$NON-NLS-2$
+		assertEquals("file:", FileSystem.largeBasename("file://")); //$NON-NLS-1$ //$NON-NLS-2$
 	}
 
 	/**
@@ -173,15 +202,20 @@
 	public void testLargeBasenameFile() {
 		assertEquals("test.x.z.z", FileSystem.largeBasename(f1)); //$NON-NLS-1$
 		assertEquals("home", FileSystem.largeBasename(f2)); //$NON-NLS-1$
+		assertEquals("a.b.c", FileSystem.largeBasename(new File("/a.b.c/"))); //$NON-NLS-1$ //$NON-NLS-2$
+		assertEquals("", FileSystem.largeBasename(new File("/"))); //$NON-NLS-1$ //$NON-NLS-2$
 	}
 
 	/**
+	 * @throws MalformedURLException 
 	 */
-	public void testLargeBasenameURL() {
+	public void testLargeBasenameURL() throws MalformedURLException {
 		assertEquals("test.x.z.z", FileSystem.largeBasename(u1)); //$NON-NLS-1$
 		assertEquals("home", FileSystem.largeBasename(u2)); //$NON-NLS-1$
 		assertEquals("file.x.z.z", FileSystem.largeBasename(u3)); //$NON-NLS-1$
 		assertEquals("file.x.z.z", FileSystem.largeBasename(u7)); //$NON-NLS-1$
+		assertEquals("a.b.c", FileSystem.largeBasename(new URL("file:///a.b.c/"))); //$NON-NLS-1$ //$NON-NLS-2$
+		assertEquals("", FileSystem.largeBasename(new URL("file://"))); //$NON-NLS-1$ //$NON-NLS-2$
 	}
 
 	/**
@@ -189,6 +223,8 @@
 	public void testBasenameString() {
 		assertEquals("test.x.z", FileSystem.basename(f1.getAbsolutePath())); //$NON-NLS-1$
 		assertEquals("home", FileSystem.basename(f2.getAbsolutePath())); //$NON-NLS-1$
+		assertEquals("a.b", FileSystem.basename("/a.b.c/")); //$NON-NLS-1$ //$NON-NLS-2$
+		assertEquals("", FileSystem.basename("")); //$NON-NLS-1$ //$NON-NLS-2$
 	}
 
 	/**
@@ -196,15 +232,20 @@
 	public void testBasenameFile() {
 		assertEquals("test.x.z", FileSystem.basename(f1)); //$NON-NLS-1$
 		assertEquals("home", FileSystem.basename(f2)); //$NON-NLS-1$
+		assertEquals("a.b", FileSystem.basename(new File("/a.b.c/"))); //$NON-NLS-1$ //$NON-NLS-2$
+		assertEquals("", FileSystem.basename(new File("/"))); //$NON-NLS-1$ //$NON-NLS-2$
 	}
 
 	/**
+	 * @throws MalformedURLException 
 	 */
-	public void testBasenameURL() {
+	public void testBasenameURL() throws MalformedURLException {
 		assertEquals("test.x.z", FileSystem.basename(u1)); //$NON-NLS-1$
 		assertEquals("home", FileSystem.basename(u2)); //$NON-NLS-1$
 		assertEquals("file.x.z", FileSystem.basename(u3)); //$NON-NLS-1$
 		assertEquals("file.x.z", FileSystem.basename(u7)); //$NON-NLS-1$
+		assertEquals("a.b", FileSystem.basename(new URL("file:///a.b.c/"))); //$NON-NLS-1$ //$NON-NLS-2$
+		assertEquals("", FileSystem.basename(new URL("file://"))); //$NON-NLS-1$ //$NON-NLS-2$
 	}
 
 	/**
@@ -212,6 +253,8 @@
 	public void testShortBasenameString() {
 		assertEquals("test", FileSystem.shortBasename(f1.getAbsolutePath())); //$NON-NLS-1$
 		assertEquals("home", FileSystem.shortBasename(f2.getAbsolutePath())); //$NON-NLS-1$
+		assertEquals("a", FileSystem.shortBasename("/a.b.c/")); //$NON-NLS-1$ //$NON-NLS-2$
+		assertEquals("", FileSystem.shortBasename("")); //$NON-NLS-1$ //$NON-NLS-2$
 	}
 
 	/**
@@ -219,15 +262,20 @@
 	public void testShortBasenameFile() {
 		assertEquals("test", FileSystem.shortBasename(f1)); //$NON-NLS-1$
 		assertEquals("home", FileSystem.shortBasename(f2)); //$NON-NLS-1$
+		assertEquals("a", FileSystem.shortBasename(new File("/a.b.c/"))); //$NON-NLS-1$ //$NON-NLS-2$
+		assertEquals("", FileSystem.shortBasename(new File("/"))); //$NON-NLS-1$ //$NON-NLS-2$
 	}
 
 	/**
+	 * @throws MalformedURLException 
 	 */
-	public void testShortBasenameURL() {
+	public void testShortBasenameURL() throws MalformedURLException {
 		assertEquals("test", FileSystem.shortBasename(u1)); //$NON-NLS-1$
 		assertEquals("home", FileSystem.shortBasename(u2)); //$NON-NLS-1$
 		assertEquals("file", FileSystem.shortBasename(u3)); //$NON-NLS-1$
 		assertEquals("file", FileSystem.shortBasename(u7)); //$NON-NLS-1$
+		assertEquals("a", FileSystem.shortBasename(new URL("file:///a.b.c/"))); //$NON-NLS-1$ //$NON-NLS-2$
+		assertEquals("", FileSystem.shortBasename(new URL("file://"))); //$NON-NLS-1$ //$NON-NLS-2$
 	}
 
 	/**
@@ -235,16 +283,21 @@
 	public void testExtensionFile() {
 		assertEquals(".z", FileSystem.extension(f1)); //$NON-NLS-1$
 		assertEquals("", FileSystem.extension(f2)); //$NON-NLS-1$
+		assertEquals(".c", FileSystem.extension(new File("/a.b.c/"))); //$NON-NLS-1$ //$NON-NLS-2$
+		assertEquals("", FileSystem.extension(new File("/"))); //$NON-NLS-1$ //$NON-NLS-2$
 	}
 
 	/**
+	 * @throws MalformedURLException 
 	 */
-	public void testExtensionURL() {
+	public void testExtensionURL() throws MalformedURLException {
 		assertEquals(".z", FileSystem.extension(u1)); //$NON-NLS-1$
 		assertEquals("", FileSystem.extension(u2)); //$NON-NLS-1$
 		assertEquals(".z", FileSystem.extension(u3)); //$NON-NLS-1$
 		assertEquals(".z", FileSystem.extension(u7)); //$NON-NLS-1$
 		assertEquals(".z", FileSystem.extension(u13)); //$NON-NLS-1$
+		assertEquals(".c", FileSystem.extension(new URL("file:///a.b.c/"))); //$NON-NLS-1$ //$NON-NLS-2$
+		assertEquals("", FileSystem.extension(new URL("file://"))); //$NON-NLS-1$ //$NON-NLS-2$
 	}
 
 	/**
@@ -252,15 +305,20 @@
 	public void testExtensionsFile() {
 		assertTrue(Arrays.equals(new String[]{"x","z","z"}, FileSystem.extensions(f1))); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
 		assertTrue(Arrays.equals(new String[0], FileSystem.extensions(f2)));
+		assertTrue(Arrays.equals(new String[]{"b","c"}, FileSystem.extensions(new File("/a.b.c/")))); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
+		assertTrue(Arrays.equals(new String[0], FileSystem.extensions(new File("/")))); //$NON-NLS-1$
 	}
 
 	/**
+	 * @throws MalformedURLException 
 	 */
-	public void testExtensionsURL() {
+	public void testExtensionsURL() throws MalformedURLException {
 		assertTrue(Arrays.equals(new String[]{"x","z","z"}, FileSystem.extensions(u1))); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
 		assertTrue(Arrays.equals(new String[0], FileSystem.extensions(u2)));
 		assertTrue(Arrays.equals(new String[]{"x","z","z"}, FileSystem.extensions(u3))); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
 		assertTrue(Arrays.equals(new String[]{"x","z","z"}, FileSystem.extensions(u7))); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
+		assertTrue(Arrays.equals(new String[]{"b","c"}, FileSystem.extensions(new URL("file:///a.b.c/")))); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
+		assertTrue(Arrays.equals(new String[0], FileSystem.extensions(new URL("file://")))); //$NON-NLS-1$
 	}
 
 	/**

Modified: trunk/arakhneVmutils/java/src/test/java/org/arakhne/vmutil/ResourcesTest.java
===================================================================
--- trunk/arakhneVmutils/java/src/test/java/org/arakhne/vmutil/ResourcesTest.java	2010-05-07 08:06:27 UTC (rev 139)
+++ trunk/arakhneVmutils/java/src/test/java/org/arakhne/vmutil/ResourcesTest.java	2010-05-07 08:06:53 UTC (rev 140)
@@ -35,6 +35,8 @@
     /**
      */
     public void testGetResourceString() {
+    	assertNull(Resources.getResource(null));
+
     	URL u1 = Resources.getResource("/org/arakhne/vmutil/test.txt"); //$NON-NLS-1$
     	assertNotNull(u1);
     	
@@ -47,6 +49,8 @@
    	/**
      */
     public void testGetResourceClassString() {
+    	assertNull(Resources.getResource(ResourcesTest.class, null));
+    	
     	URL u1 = Resources.getResource(ResourcesTest.class, "/org/arakhne/vmutil/test.txt"); //$NON-NLS-1$
     	assertNotNull(u1);
     	
@@ -54,11 +58,23 @@
     	assertNotNull(u2);
     	
     	assertEquals(u1,u2);
+
+    	assertNull(Resources.getResource((Class<?>)null, null));
+    	
+    	u1 = Resources.getResource((Class<?>)null, "/org/arakhne/vmutil/test.txt"); //$NON-NLS-1$
+    	assertNotNull(u1);
+    	
+    	u2 = Resources.getResource((Class<?>)null, "org/arakhne/vmutil/test.txt"); //$NON-NLS-1$
+    	assertNotNull(u2);
+    	
+    	assertEquals(u1,u2);
     }
 
    	/**
      */
     public void testGetResourceClassLoaderString() {
+    	assertNull(Resources.getResource(ResourcesTest.class.getClassLoader(), null));    	
+    	
     	URL u1 = Resources.getResource(ResourcesTest.class.getClassLoader(), "/org/arakhne/vmutil/test.txt"); //$NON-NLS-1$
     	assertNotNull(u1);
     	
@@ -66,11 +82,23 @@
     	assertNotNull(u2);
     	
     	assertEquals(u1,u2);
+
+    	assertNull(Resources.getResource((ClassLoader)null, null));    	
+    	
+    	u1 = Resources.getResource((ClassLoader)null, "/org/arakhne/vmutil/test.txt"); //$NON-NLS-1$
+    	assertNotNull(u1);
+    	
+    	u2 = Resources.getResource((ClassLoader)null, "org/arakhne/vmutil/test.txt"); //$NON-NLS-1$
+    	assertNotNull(u2);
+    	
+    	assertEquals(u1,u2);
     }
     
     /**
      */
     public void testGetResourceAsStreamString() {
+    	assertNull(Resources.getResourceAsStream(null));
+
     	InputStream is = Resources.getResourceAsStream("/org/arakhne/vmutil/test.txt"); //$NON-NLS-1$
     	assertNotNull(is);
     	
@@ -81,21 +109,41 @@
    	/**
      */
     public void testGetResourceAsStreamClassString() {
+    	assertNull(Resources.getResourceAsStream(ResourcesTest.class, null));
+
     	InputStream is = Resources.getResourceAsStream(ResourcesTest.class, "/org/arakhne/vmutil/test.txt"); //$NON-NLS-1$
     	assertNotNull(is);
     	
     	is = Resources.getResourceAsStream(ResourcesTest.class, "org/arakhne/vmutil/test.txt"); //$NON-NLS-1$
     	assertNotNull(is);
+
+    	assertNull(Resources.getResourceAsStream((Class<?>)null, null));
+
+    	is = Resources.getResourceAsStream((Class<?>)null, "/org/arakhne/vmutil/test.txt"); //$NON-NLS-1$
+    	assertNotNull(is);
+    	
+    	is = Resources.getResourceAsStream((Class<?>)null, "org/arakhne/vmutil/test.txt"); //$NON-NLS-1$
+    	assertNotNull(is);
     }
 
    	/**
      */
     public void testGetResourceAsStreamClassLoaderString() {
+    	assertNull(Resources.getResourceAsStream(ResourcesTest.class.getClassLoader(), null));
+    	
     	InputStream is = Resources.getResourceAsStream(ResourcesTest.class.getClassLoader(), "/org/arakhne/vmutil/test.txt"); //$NON-NLS-1$
     	assertNotNull(is);
     	
     	is = Resources.getResourceAsStream(ResourcesTest.class.getClassLoader(), "org/arakhne/vmutil/test.txt"); //$NON-NLS-1$
     	assertNotNull(is);
+
+    	assertNull(Resources.getResourceAsStream((ClassLoader)null, null));
+    	
+    	is = Resources.getResourceAsStream((ClassLoader)null, "/org/arakhne/vmutil/test.txt"); //$NON-NLS-1$
+    	assertNotNull(is);
+    	
+    	is = Resources.getResourceAsStream((ClassLoader)null, "org/arakhne/vmutil/test.txt"); //$NON-NLS-1$
+    	assertNotNull(is);
     }
 
 }


Mail converted by MHonArc 2.6.19+ http://listengine.tuxfamily.org/