Program: 56627
Project: 56627
Buggy source:
/** 
 * Issues UPnP commands to a GatewayDevice that can be reached at the specified <tt>url</tt> The command is identified by a <tt>service</tt> and an <tt>action</tt> and can receive arguments
 * @param url the url to use to contact the device
 * @param service the service to invoke
 * @param action the specific action to perform
 * @param args the command arguments
 * @return the response to the performed command, as a name-vale map
 * @throws IOException on communication errors
 * @throws SAXException if errors occur while parsing the response
 */
public static Map<String,String> simpleUPnPcommand(String url,String service,String action,Map<String,String> args) throws IOException, SAXException {
  String soapAction=service + "String_Node_Str" + action;
  StringBuffer soapBody=new StringBuffer();
  soapBody.append("String_Node_Str" + "String_Node_Str" + "String_Node_Str"+ "String_Node_Str"+ "String_Node_Str"+ "String_Node_Str" + action + "String_Node_Str"+ service+ "String_Node_Str");
  if (args != null && args.size() > 0) {
    Set<Map.Entry<String,String>> entrySet=args.entrySet();
    for (    Map.Entry<String,String> entry : entrySet) {
      soapBody.append("String_Node_Str" + entry.getKey() + "String_Node_Str"+ entry.getValue()+ "String_Node_Str"+ entry.getKey()+ "String_Node_Str");
    }
  }
  soapBody.append("String_Node_Str" + action + "String_Node_Str");
  soapBody.append("String_Node_Str");
  URL postUrl=new URL(url);
  HttpURLConnection conn=(HttpURLConnection)postUrl.openConnection();
  conn.setRequestMethod("String_Node_Str");
  conn.setDoOutput(true);
  conn.setRequestProperty("String_Node_Str","String_Node_Str");
  conn.setRequestProperty("String_Node_Str",soapAction);
  conn.setRequestProperty("String_Node_Str","String_Node_Str");
  byte[] soapBodyBytes=soapBody.toString().getBytes();
  conn.setRequestProperty("String_Node_Str",String.valueOf(soapBodyBytes.length));
  conn.getOutputStream().write(soapBodyBytes);
  Map<String,String> nameValue=new HashMap<String,String>();
  XMLReader parser=XMLReaderFactory.createXMLReader();
  parser.setContentHandler(new NameValueHandler(nameValue));
  if (conn.getResponseCode() == HttpURLConnection.HTTP_INTERNAL_ERROR) {
    parser.parse(new InputSource(conn.getErrorStream()));
    conn.disconnect();
    return nameValue;
  }
 else {
    parser.parse(new InputSource(conn.getInputStream()));
    conn.disconnect();
    return nameValue;
  }
}

Fixed version (ground truth):
/** 
 * Issues UPnP commands to a GatewayDevice that can be reached at the specified <tt>url</tt> The command is identified by a <tt>service</tt> and an <tt>action</tt> and can receive arguments
 * @param url the url to use to contact the device
 * @param service the service to invoke
 * @param action the specific action to perform
 * @param args the command arguments
 * @return the response to the performed command, as a name-value map.In case errors occur, the returned map will be <i>empty.</i>
 * @throws IOException on communication errors
 * @throws SAXException if errors occur while parsing the response
 */
public static Map<String,String> simpleUPnPcommand(String url,String service,String action,Map<String,String> args) throws IOException, SAXException {
  String soapAction=service + "String_Node_Str" + action;
  StringBuffer soapBody=new StringBuffer();
  soapBody.append("String_Node_Str" + "String_Node_Str" + "String_Node_Str"+ "String_Node_Str"+ "String_Node_Str"+ "String_Node_Str" + action + "String_Node_Str"+ service+ "String_Node_Str");
  if (args != null && args.size() > 0) {
    Set<Map.Entry<String,String>> entrySet=args.entrySet();
    for (    Map.Entry<String,String> entry : entrySet) {
      soapBody.append("String_Node_Str" + entry.getKey() + "String_Node_Str"+ entry.getValue()+ "String_Node_Str"+ entry.getKey()+ "String_Node_Str");
    }
  }
  soapBody.append("String_Node_Str" + action + "String_Node_Str");
  soapBody.append("String_Node_Str");
  URL postUrl=new URL(url);
  HttpURLConnection conn=(HttpURLConnection)postUrl.openConnection();
  conn.setRequestMethod("String_Node_Str");
  conn.setDoOutput(true);
  conn.setRequestProperty("String_Node_Str","String_Node_Str");
  conn.setRequestProperty("String_Node_Str",soapAction);
  conn.setRequestProperty("String_Node_Str","String_Node_Str");
  byte[] soapBodyBytes=soapBody.toString().getBytes();
  conn.setRequestProperty("String_Node_Str",String.valueOf(soapBodyBytes.length));
  conn.getOutputStream().write(soapBodyBytes);
  Map<String,String> nameValue=new HashMap<String,String>();
  XMLReader parser=XMLReaderFactory.createXMLReader();
  parser.setContentHandler(new NameValueHandler(nameValue));
  if (conn.getResponseCode() == HttpURLConnection.HTTP_INTERNAL_ERROR) {
    try {
      parser.parse(new InputSource(conn.getErrorStream()));
    }
 catch (    SAXException e) {
    }
    conn.disconnect();
    return nameValue;
  }
 else {
    parser.parse(new InputSource(conn.getInputStream()));
    conn.disconnect();
    return nameValue;
  }
}