hadoop-common-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Bryan A. Pendleton" ...@geekdom.net>
Subject Re: not jdk 1.4 compatibility
Date Thu, 09 Feb 2006 23:18:39 GMT
Here's a patch for both the 1.4 problem, and adding some defensive coding
that prevents a NPE if you're, say, running code with no JARs in your
classpath:
---
Index:
C:/parc/eclipse.workspace.prefuse/hadoop/src/java/org/apache/hadoop/mapred/JobConf.java
===================================================================
---
C:/parc/eclipse.workspace.prefuse/hadoop/src/java/org/apache/hadoop/mapred/JobConf.java
(revision 376379)
+++
C:/parc/eclipse.workspace.prefuse/hadoop/src/java/org/apache/hadoop/mapred/JobConf.java
(working copy)
@@ -69,7 +69,9 @@
    */
   public JobConf(Configuration conf, Class aClass) {
     this(conf);
-    setJar(findContainingJar(aClass));
+    String found = findContainingJar(aClass);
+    if(found != null)
+        setJar(found);
   }


@@ -295,14 +297,17 @@
    * @throws IOException
    */
   private static String findContainingJar(Class my_class) {
-    ClassLoader loader = my_class.getClassLoader();
+    ClassLoader loader = my_class.getClassLoader();
     String class_file = my_class.getName().replaceAll("\\.", "/") +
".class";
     try {
       for(Enumeration itr = loader.getResources(class_file);
           itr.hasMoreElements();) {
         URL url = (URL) itr.nextElement();
         if ("jar".equals(url.getProtocol())) {
-          return url.getPath().replace("file:", "").replaceAll("!.*$", "");
+            String toReturn = url.getPath();
+            if(toReturn.startsWith("file:"))
+                toReturn = toReturn.substring("file:".length());
+          return toReturn.replaceAll("!.*$", "");
         }
       }
     } catch (IOException e) {
---
On 2/9/06, Owen O'Malley <owen@yahoo-inc.com> wrote:
>
>
> On Feb 9, 2006, at 2:36 PM, Stefan Groschupf wrote:
>
> > Hi,
> > hadoop build not under jdk 1.4 anymore.
> > JobConf.java line: 305
> >      return url.getPath().replace("file:", "").replaceAll("!.*$", "");
> > may it would be better to use replaceAll or replaceFirst here.
>
> You are right. Sorry about that. I guess I should install a 1.4
> compiler to make sure that it doesn't happen again.
>
> -- Owen
>
>


--
Bryan A. Pendleton
Ph: (877) geek-1-bp
Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message