title: INFO mapreduce.Job: Task Id : attempt_*, Status : FAILED
body: <p>I am trying to implement mutual friends code. After successfully running mapper of this code after entering into reducer its throws errors and cannot produce desired output.</p>
  
  <p><strong>I have driver class as follow:</strong></p>
  
  <pre><code>public class MutualFriends {
  public static void main(String args[]) throws Exception {
          // Standard Job setup procedure.
          Configuration conf = new Configuration();
  
      long milliseconds = 1000*60*60;
      conf.setLong("mapreduce.task.timeout",milliseconds);
  
          Job job = new Job(conf, "Mutual Friends");
          job.setJarByClass(MutualFriends.class);
          job.setMapperClass(FriendsMapper.class);
          //job.setReducerClass(FriendsReducer.class);
      //job.setCombinerClass(FriendsReducer.class);
      job.setReducerClass(FriendsReducer.class);        
      job.setOutputKeyClass(Text.class);
          job.setOutputValueClass(Text.class);
          FileInputFormat.addInputPath(job, new Path(args[0]));
          FileOutputFormat.setOutputPath(job, new Path(args[1]));
          System.exit(job.waitForCompletion(true) ? 0 : 1);
      }
  </code></pre>
  
  <p><strong>Mapper</strong></p>
  
  <pre><code> public static class FriendsMapper
              extends Mapper&lt;Object, Text, Text, Text&gt; {
          private Text m_id = new Text();
          private Text m_others = new Text();
  
          public void map(Object key, Text value, Context context)
                  throws IOException, InterruptedException {
              // In our case, the key is null and the value is one line of our input file.
              // Split by space to separate the user and its friends list.
              String line = value.toString();
              String[] split = line.split(" ");
              String subject = split[0];
              String[] friends = Arrays.copyOfRange(split, 1, split.length);
  
              // For each friend in the list, output the (UserFriend, ListOfFriends) pair
              for(String friend : friends) {
                  String others = line.replace(subject, "").replace(" ", "");
                  String id = subject.compareTo(friend) &lt; 0 ? subject+friend : friend+subject;
                  m_id.set(id);
                  m_others.set(others);
                  context.write(m_id, m_others);
              }
          }
      }
  </code></pre>
  
  <p><strong>Reducer:</strong></p>
  
  <pre><code>public static class FriendsReducer
              extends Reducer&lt;Text, Text, Text, Text&gt; {
          private Text m_result = new Text();
  
          // Calculates intersection of two given Strings, i.e. friends lists
          public String intersection(String s1, String s2) {
              HashSet&lt;Character&gt; h1 = new HashSet&lt;Character&gt;();
              HashSet&lt;Character&gt; h2 = new HashSet&lt;Character&gt;();
  
              for(int i = 0; i &lt; s1.length(); i++) {
                  h1.add(s1.charAt(i));
              }
              for(int j = 0; j &lt; s2.length(); j++) {
                  h2.add(s2.charAt(j));
              }
  
              h1.retainAll(h2);
              Character[] res = h1.toArray(new Character[0]);
              String intersect = new String("");
              for (int i = 0; i &lt; res.length; i++) {
                  intersect += res[i];
              }
  
              char[] letters = intersect.toCharArray();
              Arrays.sort(letters);
              String sortedIntersect = new String(letters);
              return sortedIntersect;
          }
  
          public void reduce(Text key, Iterable&lt;Text&gt; values, Context context)
                  throws IOException, InterruptedException {
              // Prepare a 2-String-Array to hold the values, i.e. the friends lists of
              // our current friends pair.
              String[] combined = new String[2];
              int cur = 0;
              for(Text value : values) {
                  combined[cur++] = value.toString();
              }
  
              // Calculate the intersection of these lists and write result in the form (UserAUserB, MutualFriends).
              m_result.set(intersection(combined[0], combined[1]));
              context.write(key, m_result);
          }
      }
  </code></pre>
  
  <p><strong>error:</strong></p>
  
  <pre><code>15/09/22 16:27:29 INFO mapreduce.Job: Task Id : attempt_1442915698147_0006_r_000000_0, Status : FAILED
  Error: java.lang.NullPointerException
      at MutualFriends$FriendsReducer.intersection(MutualFriends.java:54)
      at MutualFriends$FriendsReducer.reduce(MutualFriends.java:82)
      at MutualFriends$FriendsReducer.reduce(MutualFriends.java:42)
      at org.apache.hadoop.mapreduce.Reducer.run(Reducer.java:171)
      at org.apache.hadoop.mapred.ReduceTask.runNewReducer(ReduceTask.java:627)
      at org.apache.hadoop.mapred.ReduceTask.run(ReduceTask.java:389)
      at org.apache.hadoop.mapred.YarnChild$2.run(YarnChild.java:163)
      at java.security.AccessController.doPrivileged(Native Method)
      at javax.security.auth.Subject.doAs(Subject.java:415)
      at org.apache.hadoop.security.UserGroupInformation.doAs(UserGroupInformation.java:1628)
      at org.apache.hadoop.mapred.YarnChild.main(YarnChild.java:158)
  </code></pre>
  
  <p>Currently M using :
  Ubuntu 14-04
  Hadoop 2.6.0</p>