Changeset 2478 in josm


Ignore:
Timestamp:
Nov 19, 2009 10:12:31 AM (4 years ago)
Author:
Gubaer
Message:

see #3887: java.lang.NullPointerException while uploading (OsmTransferException)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/io/OsmApi.java

    r2273 r2478  
    473473     *    but including any object ids (e.g. "/way/1234/history"). 
    474474     * @param requestBody the body of the HTTP request, if any. 
     475     * @param monitor the progress monitor 
     476     * @param doAuthenticate  set to true, if the request sent to the server shall include authentication 
     477     * credentials; 
    475478     * 
    476479     * @return the body of the HTTP response, if and only if the response code was "200 OK". 
     
    499502 
    500503                    // It seems that certain bits of the Ruby API are very unhappy upon 
    501                     // receipt of a PUT/POST message withtout a Content-length header, 
     504                    // receipt of a PUT/POST message without a Content-length header, 
    502505                    // even if the request has no payload. 
    503506                    // Since Java will not generate a Content-length header unless 
     
    535538                    i = activeConnection.getErrorStream(); 
    536539                } 
    537                 BufferedReader in = new BufferedReader(new InputStreamReader(i)); 
    538  
    539                 String s; 
    540                 while((s = in.readLine()) != null) { 
    541                     responseBody.append(s); 
    542                     responseBody.append("\n"); 
     540                if (i != null) { 
     541                    // the input stream can be null if both the input and the error stream 
     542                    // are null. Seems to be the case if the OSM server replies a 401 
     543                    // Unauthorized, see #3887. 
     544                    // 
     545                    BufferedReader in = new BufferedReader(new InputStreamReader(i)); 
     546                    String s; 
     547                    while((s = in.readLine()) != null) { 
     548                        responseBody.append(s); 
     549                        responseBody.append("\n"); 
     550                    } 
    543551                } 
    544552                String errorHeader = null; 
     
    553561 
    554562                errorHeader = errorHeader == null? null : errorHeader.trim(); 
    555                 String errorBody = responseBody == null ? null : responseBody.toString().trim(); 
     563                String errorBody = responseBody.length() == 0? null : responseBody.toString().trim(); 
    556564                switch(retCode) { 
    557565                case HttpURLConnection.HTTP_OK: 
    558                     break; // do nothing 
     566                    return responseBody.toString(); 
    559567                case HttpURLConnection.HTTP_GONE: 
    560568                    throw new OsmApiPrimitiveGoneException(errorHeader, errorBody); 
    561569                default: 
    562570                    throw new OsmApiException(retCode, errorHeader, errorBody); 
    563  
    564                 } 
    565                 return responseBody.toString(); 
     571                } 
    566572            } catch (UnknownHostException e) { 
    567573                throw new OsmTransferException(e); 
Note: See TracChangeset for help on using the changeset viewer.