Review Board 1.7.22


SQOOP-855 pg_bulkload: NullPointerException will be thrown if user specified invalid path the binary

Review Request #9168 - Created Jan. 30, 2013 and submitted

Jarek Cecho
SQOOP-855
Reviewers
Sqoop
sqoop-trunk
The NPE was caused by calling cleanup from catch block in setup method. I've added conditions to check each variable before closing.
Tested on real cluster.

Diff revision 1 (Latest)

  1. src/java/org/apache/sqoop/mapreduce/PGBulkloadExportMapper.java: Loading...
src/java/org/apache/sqoop/mapreduce/PGBulkloadExportMapper.java
Revision 14d064a51725b23fe79990df8288554b4a22556a New Change
[20] 167 lines
[+20] [+] protected void setup(Context context)
168
      out = process.getOutputStream();
168
      out = process.getOutputStream();
169
      writer = new BufferedWriter(new OutputStreamWriter(out));
169
      writer = new BufferedWriter(new OutputStreamWriter(out));
170
      thread = new ReadThread(process.getErrorStream());
170
      thread = new ReadThread(process.getErrorStream());
171
      thread.start();
171
      thread.start();
172
    } catch (Exception e) {
172
    } catch (Exception e) {

    
   
173
      LOG.error("Can't start up pg_bulkload process", e);
173
      cleanup(context);
174
      cleanup(context);
174
      doExecuteUpdate("DROP TABLE " + tmpTableName);
175
      doExecuteUpdate("DROP TABLE " + tmpTableName);
175
      throw new IOException(e);
176
      throw new IOException(e);
176
    }
177
    }
177
  }
178
  }
[+20] [20] 20 lines
[+20] [+] public void map(LongWritable key, Writable value, Context context)
198
  protected void cleanup(Context context)
199
  protected void cleanup(Context context)
199
    throws IOException, InterruptedException {
200
    throws IOException, InterruptedException {
200
    LongWritable taskid =
201
    LongWritable taskid =
201
      new LongWritable(context.getTaskAttemptID().getTaskID().getId());
202
      new LongWritable(context.getTaskAttemptID().getTaskID().getId());
202
    context.write(taskid, new Text(tmpTableName));
203
    context.write(taskid, new Text(tmpTableName));

    
   
204

   

    
   
205
    if (writer != null) {
203
    writer.close();
206
      writer.close();

    
   
207
    }

    
   
208
    if (out != null) {
204
    out.close();
209
      out.close();

    
   
210
    }
205
    try {
211
    try {

    
   
212
      if (thread != null) {
206
      thread.join();
213
        thread.join();

    
   
214
      }
207
    } finally {
215
    } finally {
208
      // block until the process is done.
216
      // block until the process is done.
209
      int result = 0;
217
      int result = 0;
210
      if (null != process) {
218
      if (null != process) {
211
        while (true) {
219
        while (true) {
[+20] [20] 79 lines
  1. src/java/org/apache/sqoop/mapreduce/PGBulkloadExportMapper.java: Loading...