This is the mail archive of the java-patches@gcc.gnu.org mailing list for the Java project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Patch: FYI: Exception cleanup in gnu.gcj.runtime.VMClassLoader


VMClassLoader had an exception handler block like the following:

catch (Exception x)
{
// Just ignore any badness. }


This sort of thing is a bad idea because a) it can hide real exceptions deep within the runtime, causing hard-to-debug problems later; and b) it promotes the use of exceptions as part of normal execution flow, which is a bad idea for performance reasons (we especially want to avoid this during runtime startup).

I'm checking in the following patch, which adds a specific handler for the checked MalformedURLException. This exception should never happen, so we just rethrow it as a RuntimeException if it does.

Regards

Bryce


2004-07-05  Bryce McKinlay  <mckinlay@redhat.com>

	* gnu/gcj/runtime/VMClassLoader.java (init): Check classpath entry
	before passing to URL constructor. Rethrow any MalformedURLException
	as a RuntimeException. Catch MalformedURLException specifically, not
	all exceptions.

Index: VMClassLoader.java
===================================================================
RCS file: /cvs/gcc/gcc/libjava/gnu/gcj/runtime/VMClassLoader.java,v
retrieving revision 1.14
diff -u -r1.14 VMClassLoader.java
--- VMClassLoader.java	18 Jun 2004 13:53:19 -0000	1.14
+++ VMClassLoader.java	5 Jul 2004 23:10:56 -0000
@@ -47,58 +47,58 @@
 	String e = st.nextToken ();
 	try
 	  {
-	    if (!e.endsWith (File.separator) && new File (e).isDirectory ())
+	    File path = new File(e);
+	    // Ignore invalid paths.
+	    if (!path.exists())
+	      continue;
+	    if (!e.endsWith (File.separator) && path.isDirectory ())
 	      addURL(new URL("file", "", -1, e + File.separator));
 	    else
 	      addURL(new URL("file", "", -1, e));
 	  } 
 	catch (java.net.MalformedURLException x)
 	  {
-	    /* Ignore this path element */
+	    // This should never happen.
+	    throw new RuntimeException(x);
 	  }
       }
 
     // Add the contents of the extensions directories.  
     st = new StringTokenizer (System.getProperty ("java.ext.dirs"),
 			      System.getProperty ("path.separator", ":"));
-    while (st.hasMoreElements ())
+
+    try
       {
-	String dirname = st.nextToken ();
-	try
+	while (st.hasMoreElements ())
 	  {
+	    String dirname = st.nextToken ();
 	    File dir = new File (dirname);
             if (dir.exists ())
             {
               if (! dirname.endsWith (File.separator))
-                  dirname = dirname + File.separator;
+        	  dirname = dirname + File.separator;
               String files[] 
-                = dir.list (new FilenameFilter ()
+        	= dir.list (new FilenameFilter ()
                             { 
                               public boolean accept (File dir, String name)
                               {
-                                return (name.endsWith (".jar") 
-                                        || name.endsWith (".zip"));
+                        	return (name.endsWith (".jar") 
+                                	|| name.endsWith (".zip"));
                               }
                             });
               for (int i = files.length - 1; i >= 0; i--)
-                addURL(new URL("file", "", -1, dirname + files[i]));
+        	addURL(new URL("file", "", -1, dirname + files[i]));
             }
 	  }
-	catch (Exception x)
-	  {
-	    // Just ignore any badness.  
-	  }
-      }
 
-    // Add core:/ to the end of the java.class.path so any resources
-    // compiled into this executable may be found.
-    try
-      {
+	// Add core:/ to the end of the java.class.path so any resources
+	// compiled into this executable may be found.
 	addURL(new URL("core", "", -1, "/"));
       }
     catch (java.net.MalformedURLException x)
       {
 	// This should never happen.
+	throw new RuntimeException(x);
       }
   }
 

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]