title: ArrayIndexOutOfBoundException in Reducer function of mapreduce
body: <p>I can not understand what the bug is, when I removed the
   <code>job.setSortComparatorClass(LongWritable.DecreasingComparator.class);</code></p>
  
  <p>I got the output but when I tried to use it I'm getting this exception.</p>
  
  <p>Im trying to get the output in decreasing order from the reducer based on the value, hence I have used <code>setsortcomparator</code> class, so please help me out</p>
  
  <pre><code>package topten.mostviewed.movies;
  
  import java.io.IOException;
  
  import org.apache.hadoop.io.IntWritable;
  import org.apache.hadoop.io.LongWritable;
  import org.apache.hadoop.io.Text;
  import org.apache.hadoop.mapreduce.Reducer;
  
  public class MostViewdReducer extends Reducer&lt;Text,IntWritable,Text,LongWritable&gt;
  {
      public void reduce(Text key,Iterable&lt;IntWritable&gt; values,Context context) throws IOException,InterruptedException
      {
          int sum = 0;
          for(IntWritable value:values)
          {
              sum = sum+1;
          }
          context.write(key, new LongWritable(sum));
      }
  }
  package topten.mostviewed.movies;
  
  import java.io.IOException;
  import java.util.StringTokenizer;
  
  import org.apache.hadoop.conf.Configuration;
  import org.apache.hadoop.fs.Path;
  import org.apache.hadoop.io.IntWritable;
  import org.apache.hadoop.io.LongWritable;
  import org.apache.hadoop.io.NullWritable;
  import org.apache.hadoop.io.RawComparator;
  import org.apache.hadoop.io.Text;
  import org.apache.hadoop.mapreduce.Job;
  import org.apache.hadoop.mapreduce.Mapper;
  import org.apache.hadoop.mapreduce.Reducer;
  import org.apache.hadoop.mapreduce.lib.input.FileInputFormat;
  import org.apache.hadoop.mapreduce.lib.output.FileOutputFormat;
  import org.apache.hadoop.util.GenericOptionsParser;
  
  public class MostViewdDriver 
  {
  
     // @SuppressWarnings("unchecked")
      public static void main(String[] args) throws Exception
      {
          Configuration conf = new Configuration();
          String[] otherArgs = new GenericOptionsParser(conf, args).getRemainingArgs();
          if (otherArgs.length != 2)
          {
              System.err.println("Usage: movie &lt;input&gt; &lt;out&gt;");
              System.exit(2);
          }
      Job job = new Job(conf, "Movie ");
      job.setJarByClass(MostViewdDriver.class);
      job.setMapperClass(MostviewdMapper.class);
      job.setReducerClass(MostViewdReducer.class);
  
      job.setMapOutputKeyClass(Text.class);
      job.setMapOutputValueClass(IntWritable.class);
      job.setOutputKeyClass(Text.class);
      job.setOutputValueClass(LongWritable.class);
      job.setSortComparatorClass(LongWritable.DecreasingComparator.class);
  //  job.setSortComparatorClass((Class&lt;? extends RawComparator&gt;) LongWritable.class);
  
      FileInputFormat.addInputPath(job, new Path(otherArgs[0]));
      FileOutputFormat.setOutputPath(job, new Path(otherArgs[1]));
      System.exit(job.waitForCompletion(true) ? 0 : 1);
      }
  }
  </code></pre>
  
  <p>The exception i'm getting is as below:</p>
  
  <blockquote>
    <p>18/10/11 11:35:05 INFO mapreduce.Job: Task Id : attempt_1539236679371_0004_r_000000_2, Status : FAILED
        Error: java.lang.ArrayIndexOutOfBoundsException: 7
                at   org.apache.hadoop.io.WritableComparator.readInt(WritableComparator.java:212)
                at org.apache.hadoop.io.WritableComparator.readLong(WritableComparator.java:226)
                at org.apache.hadoop.io.LongWritable$Comparator.compare(LongWritable.java:91)
                at org.apache.hadoop.io.LongWritable$DecreasingComparator.compare(LongWritable.java:106)
                at org.apache.hadoop.mapreduce.task.ReduceContextImpl.nextKeyValue(ReduceContextImpl.java:158)
                at org.apache.hadoop.mapreduce.task.ReduceContextImpl.nextKey(ReduceContextImpl.java:121)
                at org.apache.hadoop.mapreduce.lib.reduce.WrappedReducer$Context.nextKey(WrappedReducer.java:307)
                at org.apache.hadoop.mapreduce.Reducer.run(Reducer.java:170)
                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:168)
                at java.security.AccessController.doPrivileged(Native Method)
                at javax.security.auth.Subject.doAs(Subject.java:422)
                at org.apache.hadoop.security.UserGroupInformation.doAs(UserGroupInformation.java:1642)
               at org.apache.hadoop.mapred.YarnChild.main(YarnChild.java:163)</p>
  </blockquote>