You are viewing a plain text version of this content. The canonical link for it is here.
Posted to common-dev@hadoop.apache.org by Stefan Groschupf <sg...@media-style.com> on 2006/02/09 23:36:18 UTC

not jdk 1.4 compatibility

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.

Stefan 

Re: not jdk 1.4 compatibility

Posted by Doug Cutting <cu...@apache.org>.
Thanks, I just applied that.

In the future, please provide patches as attachments rather than inline, 
otherwise they can get linewrapped and otherwise mangled.

Doug

Re: not jdk 1.4 compatibility

Posted by "Bryan A. Pendleton" <bp...@geekdom.net>.
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 <ow...@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

Re: not jdk 1.4 compatibility

Posted by Owen O'Malley <ow...@yahoo-inc.com>.
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