Program: 16013
Project: 16013
Buggy source:
private void lockSocket(){
  method=SOCKET;
  properties=new SortedProperties();
  properties.setProperty("String_Node_Str",String.valueOf(method));
  setUniqueId();
  ipAddress=NetUtils.getLocalAddress();
  fs.createDirs(fileName);
  if (!fs.createNewFile(fileName)) {
    waitUntilOld();
    long read=fs.getLastModified(fileName);
    Properties p2=load();
    String m2=p2.getProperty("String_Node_Str",SOCKET);
    if (m2.equals(FILE)) {
      lockFile();
      return;
    }
 else     if (!m2.equals(SOCKET)) {
      throw getExceptionFatal("String_Node_Str" + m2,null);
    }
    String ip=p2.getProperty("String_Node_Str",ipAddress);
    if (!ipAddress.equals(ip)) {
      throw getExceptionAlreadyInUse("String_Node_Str" + ip);
    }
    String port=p2.getProperty("String_Node_Str","String_Node_Str");
    int portId=Integer.parseInt(port);
    InetAddress address;
    try {
      address=InetAddress.getByName(ip);
    }
 catch (    UnknownHostException e) {
      throw getExceptionFatal("String_Node_Str" + ip,e);
    }
    for (int i=0; i < 3; i++) {
      try {
        Socket s=new Socket(address,portId);
        s.close();
        throw getExceptionAlreadyInUse("String_Node_Str");
      }
 catch (      BindException e) {
        throw getExceptionFatal("String_Node_Str",null);
      }
catch (      ConnectException e) {
        trace.debug(e,"String_Node_Str" + port);
      }
catch (      IOException e) {
        throw getExceptionFatal("String_Node_Str",null);
      }
    }
    if (read != fs.getLastModified(fileName)) {
      throw getExceptionFatal("String_Node_Str",null);
    }
    fs.delete(fileName);
    if (!fs.createNewFile(fileName)) {
      throw getExceptionFatal("String_Node_Str",null);
    }
  }
  try {
    serverSocket=NetUtils.createServerSocket(0,false);
    int port=serverSocket.getLocalPort();
    properties.setProperty("String_Node_Str",ipAddress);
    properties.setProperty("String_Node_Str",String.valueOf(port));
  }
 catch (  Exception e) {
    trace.debug(e,"String_Node_Str");
    serverSocket=null;
    lockFile();
    return;
  }
  save();
  watchdog=new Thread(this);
  watchdog.setDaemon(true);
  watchdog.setName("String_Node_Str" + fileName);
  watchdog.start();
}

Fixed version (ground truth):
private void lockSocket(){
  method=SOCKET;
  properties=new SortedProperties();
  properties.setProperty("String_Node_Str",String.valueOf(method));
  setUniqueId();
  ipAddress=NetUtils.getLocalAddress();
  fs.createDirs(fileName);
  if (!fs.createNewFile(fileName)) {
    waitUntilOld();
    long read=fs.getLastModified(fileName);
    Properties p2=load();
    String m2=p2.getProperty("String_Node_Str",SOCKET);
    if (m2.equals(FILE)) {
      lockFile();
      return;
    }
 else     if (!m2.equals(SOCKET)) {
      throw getExceptionFatal("String_Node_Str" + m2,null);
    }
    String ip=p2.getProperty("String_Node_Str",ipAddress);
    if (!ipAddress.equals(ip)) {
      throw getExceptionAlreadyInUse("String_Node_Str" + ip);
    }
    String port=p2.getProperty("String_Node_Str","String_Node_Str");
    int portId=Integer.parseInt(port);
    InetAddress address;
    try {
      address=InetAddress.getByName(ip);
    }
 catch (    UnknownHostException e) {
      throw getExceptionFatal("String_Node_Str" + ip,e);
    }
    for (int i=0; i < 3; i++) {
      try {
        Socket s=new Socket(address,portId);
        s.close();
        throw getExceptionAlreadyInUse("String_Node_Str");
      }
 catch (      BindException e) {
        throw getExceptionFatal("String_Node_Str",null);
      }
catch (      ConnectException e) {
        trace.debug(e,"String_Node_Str" + port);
      }
catch (      IOException e) {
        throw getExceptionFatal("String_Node_Str",null);
      }
    }
    if (read != fs.getLastModified(fileName)) {
      throw getExceptionFatal("String_Node_Str",null);
    }
    fs.delete(fileName);
    if (!fs.createNewFile(fileName)) {
      throw getExceptionFatal("String_Node_Str",null);
    }
  }
  try {
    serverSocket=NetUtils.createServerSocket(0,false);
    int port=serverSocket.getLocalPort();
    properties.setProperty("String_Node_Str",ipAddress);
    properties.setProperty("String_Node_Str",String.valueOf(port));
  }
 catch (  Exception e) {
    trace.debug(e,"String_Node_Str");
    serverSocket=null;
    lockFile();
    return;
  }
  save();
  watchdog=new Thread(this,"String_Node_Str" + fileName);
  watchdog.setDaemon(true);
  watchdog.start();
}