nus-yam/ex-repair huggingface dataset:
Program: 90031
Project: 90031
Buggy source:
/** 
 * For retrieving the monitor username for the jmxremote.access file. This will have the rights 'readonly'.
 * @return The string for the jmxremote.access file for allowing the monitor user to readonly.
 */
protected String getMonitorUsername(){
  StringBuilder res=new StringBuilder();
  List<String> usernames=new ArrayList<String>();
  String[] tmpVals;
  for (  Application app : applications) {
    tmpVals=app.getSettingsValues(Constants.SETTINGS_MONITOR_JMX_NAME_LEAF);
    if (tmpVals != null && tmpVals.length > 0) {
      for (      String st : tmpVals) {
        usernames.add(st);
      }
    }
  }
  if (usernames.size() == 0) {
    String msg="String_Node_Str" + name + "String_Node_Str";
    log.warn(msg);
    throw new IllegalState(msg);
  }
  for (int i=1; i < usernames.size(); i++) {
    if (!usernames.get(0).equals(usernames.get(i))) {
      String msg="String_Node_Str" + "String_Node_Str" + name + "String_Node_Str";
      log.warn(msg);
      throw new IllegalState(msg);
    }
  }
  if (usernames.size() > 0) {
    res.append(usernames.get(0));
    res.append(Constants.SPACE);
    res.append(ScriptConstants.JMXREMOTE_ACCESS_MONITORROLE);
    res.append(Constants.NEWLINE);
  }
  return res.toString();
}

Fixed version (ground truth):
/** 
 * For retrieving the monitor username for the jmxremote.access file. This will have the rights 'readonly'.
 * @return The string for the jmxremote.access file for allowing the monitor user to readonly.
 */
protected String getMonitorUsername(){
  StringBuilder res=new StringBuilder();
  List<String> usernames=new ArrayList<String>();
  String[] tmpVals;
  for (  Application app : applications) {
    tmpVals=app.getSettingsValues(Constants.SETTINGS_MONITOR_JMX_NAME_LEAF);
    if (tmpVals != null && tmpVals.length > 0) {
      for (      String st : tmpVals) {
        usernames.add(st);
      }
    }
  }
  for (int i=1; i < usernames.size(); i++) {
    if (!usernames.get(0).equals(usernames.get(i))) {
      String msg="String_Node_Str" + "String_Node_Str" + name + "String_Node_Str";
      log.warn(msg);
      throw new IllegalState(msg);
    }
  }
  if (usernames.size() > 0) {
    res.append(usernames.get(0));
    res.append(Constants.SPACE);
    res.append(ScriptConstants.JMXREMOTE_ACCESS_MONITOR);
    res.append(Constants.NEWLINE);
  }
  return res.toString();
}
Program: 90032
Project: 90032
Buggy source:
/** 
 * For retrieving the hetrix username for the jmxremote.access file. This will have the rights 'readonly'.
 * @return The string for the jmxremote.access file for allowing the heritrix user to readonly.
 */
protected String getHeritrixUsername(){
  StringBuilder res=new StringBuilder();
  List<String> usernames=new ArrayList<String>();
  String[] tmpVals;
  for (  Application app : applications) {
    tmpVals=app.getSettingsValues(Constants.SETTINGS_HERITRIX_JMX_USERNAME_LEAF);
    if (tmpVals != null && tmpVals.length > 0) {
      for (      String st : tmpVals) {
        usernames.add(st);
      }
    }
  }
  if (usernames.size() == 0) {
    String msg="String_Node_Str" + name + "String_Node_Str";
    log.warn(msg);
    throw new IllegalState(msg);
  }
  for (int i=1; i < usernames.size(); i++) {
    if (!usernames.get(0).equals(usernames.get(i))) {
      String msg="String_Node_Str" + "String_Node_Str" + name + "String_Node_Str";
      log.warn(msg);
      throw new IllegalState(msg);
    }
  }
  if (usernames.size() > 0) {
    res.append(usernames.get(0));
    res.append(Constants.SPACE);
    res.append(ScriptConstants.JMXREMOTE_ACCESS_CONTROLROLE);
    res.append(Constants.NEWLINE);
  }
  return res.toString();
}

Fixed version (ground truth):
/** 
 * For retrieving the hetrix username for the jmxremote.access file. This will have the rights 'readonly'.
 * @return The string for the jmxremote.access file for allowing the heritrix user to readonly.
 */
protected String getHeritrixUsername(){
  StringBuilder res=new StringBuilder();
  List<String> usernames=new ArrayList<String>();
  String[] tmpVals;
  for (  Application app : applications) {
    tmpVals=app.getSettingsValues(Constants.SETTINGS_HERITRIX_JMX_USERNAME_LEAF);
    if (tmpVals != null && tmpVals.length > 0) {
      for (      String st : tmpVals) {
        usernames.add(st);
      }
    }
  }
  for (int i=1; i < usernames.size(); i++) {
    if (!usernames.get(0).equals(usernames.get(i))) {
      String msg="String_Node_Str" + "String_Node_Str" + name + "String_Node_Str";
      log.warn(msg);
      throw new IllegalState(msg);
    }
  }
  if (usernames.size() > 0) {
    res.append(usernames.get(0));
    res.append(Constants.SPACE);
    res.append(ScriptConstants.JMXREMOTE_ACCESS_CONTROL);
    res.append(Constants.NEWLINE);
  }
  return res.toString();
}
Program: 90034
Project: 90034
Buggy source:
/** 
 * Find the jobIds in the argumentList
 * @param argv
 * @return
 */
private static Set<Long> findJobIds(String[] argv){
  Set<Long> jobIds=new HashSet<Long>();
  for (  String arg : argv) {
    jobIds.add(Long.getLong(arg));
  }
  return jobIds;
}

Fixed version (ground truth):
/** 
 * Find the jobIds in the argumentList
 * @param argv
 * @return
 */
private static Set<Long> findJobIds(String[] argv){
  Set<Long> jobIds=new HashSet<Long>();
  for (  String arg : argv) {
    jobIds.add(Long.valueOf(arg));
  }
  return jobIds;
}
Program: 90036
Project: 90036
Buggy source:
/** 
 * Verify that batch jobs do not have to wait for each other. In particular, check that the postprocessing of one job can overtake the postprocessing of another.
 */
public void testParallelBatchJobs() throws InterruptedException {
  bam_server=BitarchiveMonitorServer.getInstance();
  TestMessageListener client=new TestMessageListener();
  JMSConnectionFactory.getInstance().setListener(Channels.getThisReposClient(),client);
  final MockupBitarchiveBatch mockupBitarchiveBatch=new MockupBitarchiveBatch("String_Node_Str");
  final BlockingRF brf=new BlockingRF();
  mockupBitarchiveBatch.heartBeat(bam_server);
  bam_server.visit(noActionBatchMessage("String_Node_Str"));
  new Thread(){
    public void run(){
      bam_server.visit(mockupBitarchiveBatch.replyForLatestJob(brf));
    }
  }
.start();
synchronized (this) {
    wait(50);
  }
  bam_server.visit(noActionBatchMessage("String_Node_Str"));
  new Thread(){
    public void run(){
      bam_server.visit(mockupBitarchiveBatch.replyForLatestJob(brf.getWaker()));
    }
  }
.start();
synchronized (this) {
    wait(400);
  }
  TestMessageListener.waitForConcurrentTasksToFinish();
  assertEquals("String_Node_Str",null,brf.failed);
  assertEquals("String_Node_Str",2,client.getNumReceived());
  assertEquals("String_Node_Str",2,client.getNumOk());
  assertBatchResultIs(client,0,"String_Node_Str",BlockingRF.WAKER_CONTENT);
  assertBatchResultIs(client,1,"String_Node_Str",BlockingRF.STD_CONTENT);
}

Fixed version (ground truth):
/** 
 * Verify that batch jobs do not have to wait for each other. In particular, check that the postprocessing of one job can overtake the postprocessing of another.
 */
public void testParallelBatchJobs() throws InterruptedException {
  bam_server=BitarchiveMonitorServer.getInstance();
  TestMessageListener client=new TestMessageListener();
  JMSConnectionFactory.getInstance().setListener(Channels.getThisReposClient(),client);
  final MockupBitarchiveBatch mockupBitarchiveBatch=new MockupBitarchiveBatch("String_Node_Str");
  final BlockingRF brf=new BlockingRF();
  mockupBitarchiveBatch.heartBeat(bam_server);
  bam_server.visit(noActionBatchMessage("String_Node_Str"));
  new Thread(){
    public void run(){
      bam_server.visit(mockupBitarchiveBatch.replyForLatestJob(brf));
    }
  }
.start();
synchronized (this) {
    wait(50);
  }
  bam_server.visit(noActionBatchMessage("String_Node_Str"));
  new Thread(){
    public void run(){
      bam_server.visit(mockupBitarchiveBatch.replyForLatestJob(brf.getWaker()));
    }
  }
.start();
synchronized (this) {
    wait(400);
  }
  TestMessageListener.waitForConcurrentTasksToFinish();
  assertEquals("String_Node_Str",null,brf.failed);
  assertEquals("String_Node_Str",2,client.getNumReceived());
  assertEquals("String_Node_Str" + client.getNumNotOk(),0,client.getNumNotOk());
  assertEquals("String_Node_Str",2,client.getNumOk());
  assertBatchResultIs(client,0,"String_Node_Str",BlockingRF.WAKER_CONTENT);
  assertBatchResultIs(client,1,"String_Node_Str",BlockingRF.STD_CONTENT);
}
Program: 90038
Project: 90038
Buggy source:
/** 
 * Name a JMX object name as expected by our CachingLogRecordMBean.
 * @param index The index attribute - may be null, for all
 * @return An ObjectName.
 * @throws MalformedObjectNameException
 */
private static ObjectName getObjectName(int index) throws MalformedObjectNameException {
  return new ObjectName("String_Node_Str" + Settings.get(CommonSettings.THIS_PHYSICAL_LOCATION) + "String_Node_Str"+ Constants.PRIORITY_KEY_MACHINE+ "String_Node_Str"+ SystemUtils.getLocalHostName()+ "String_Node_Str"+ Settings.get(CommonSettings.HTTP_PORT_NUMBER)+ "String_Node_Str"+ Constants.PRIORITY_KEY_REPLICA+ "String_Node_Str"+ Constants.PRIORITY_KEY_PRIORITY+ "String_Node_Str"+ "String_Node_Str"+ Constants.PRIORITY_KEY_APPLICATIONNAME+ "String_Node_Str"+ Settings.get(CommonSettings.APPLICATION_NAME)+ "String_Node_Str"+ Constants.PRIORITY_KEY_APPLICATIONINSTANCEID+ "String_Node_Str"+ Settings.get(CommonSettings.APPLICATION_INSTANCE_ID)+ "String_Node_Str"+ (index == -1 ? "String_Node_Str" : "String_Node_Str" + index));
}

Fixed version (ground truth):
/** 
 * Name a JMX object name as expected by our CachingLogRecordMBean.
 * @param index The index attribute - may be null, for all
 * @return An ObjectName.
 * @throws MalformedObjectNameException
 */
private static ObjectName getObjectName(int index) throws MalformedObjectNameException {
  return new ObjectName("String_Node_Str" + Settings.get(CommonSettings.THIS_PHYSICAL_LOCATION) + "String_Node_Str"+ Constants.PRIORITY_KEY_MACHINE+ "String_Node_Str"+ SystemUtils.getLocalHostName()+ "String_Node_Str"+ Settings.get(CommonSettings.HTTP_PORT_NUMBER)+ "String_Node_Str"+ Constants.PRIORITY_KEY_REPLICANAME+ "String_Node_Str"+ Constants.PRIORITY_KEY_PRIORITY+ "String_Node_Str"+ "String_Node_Str"+ Constants.PRIORITY_KEY_APPLICATIONNAME+ "String_Node_Str"+ Settings.get(CommonSettings.APPLICATION_NAME)+ "String_Node_Str"+ Constants.PRIORITY_KEY_APPLICATIONINSTANCEID+ "String_Node_Str"+ Settings.get(CommonSettings.APPLICATION_INSTANCE_ID)+ "String_Node_Str"+ (index == -1 ? "String_Node_Str" : "String_Node_Str" + index));
}
Program: 90040
Project: 90040
Buggy source:
/** 
 * Returns a temporary place for the the file to be stored.
 * @param arcFile       The simple name (i.e. no dirs) of the ARC file.
 * @param requestedSize How large the file is in bytes.
 * @return The path where the arcFile should go.
 * @throws ArgumentNotValid If arcFile is null or empty, or requestedSize is negative.
 * @throws IOFailure if there is no more room left to store this file ofsize=requestedSize
 */
public File getTemporaryPath(String arcFile,long requestedSize) throws ArgumentNotValid, IOFailure {
  ArgumentNotValid.checkNotNullOrEmpty(arcFile,"String_Node_Str");
  ArgumentNotValid.checkNotNegative(requestedSize,"String_Node_Str");
  for (Iterator<File> i=archivePaths.iterator(); i.hasNext(); ) {
    File dir=i.next();
    if (checkArchiveDir(dir)) {
      if (FileUtils.getBytesFree(dir) > requestedSize) {
        File filedir=new File(dir,Constants.TEMPORARY_DIRECTORY_NAME);
        return new File(filedir,arcFile);
      }
    }
  }
  String errMsg="String_Node_Str" + arcFile + "String_Node_Str"+ requestedSize;
  log.fatal(errMsg);
  throw new IOFailure(errMsg);
}

Fixed version (ground truth):
/** 
 * Returns a temporary place for the the file to be stored.
 * @param arcFileName The simple name (i.e. no dirs) of the ARC file.
 * @param requestedSize How large the file is in bytes.
 * @return The path where the arcFile should go.
 * @throws ArgumentNotValid If arcFileName is null or empty, or requestedSize is negative.
 * @throws IOFailure if there is no more room left to store this file ofsize=requestedSize
 */
public File getTemporaryPath(String arcFileName,long requestedSize) throws ArgumentNotValid, IOFailure {
  ArgumentNotValid.checkNotNullOrEmpty(arcFileName,"String_Node_Str");
  ArgumentNotValid.checkNotNegative(requestedSize,"String_Node_Str");
  for (Iterator<File> i=archivePaths.iterator(); i.hasNext(); ) {
    File dir=i.next();
    long bytesFreeInDir=FileUtils.getBytesFree(dir);
    if (checkArchiveDir(dir) && bytesFreeInDir > minSpaceLeft) {
      if (bytesFreeInDir > requestedSize) {
        File filedir=new File(dir,Constants.TEMPORARY_DIRECTORY_NAME);
        return new File(filedir,arcFileName);
      }
 else {
        log.warn("String_Node_Str" + dir.getAbsolutePath() + "String_Node_Str"+ arcFileName+ "String_Node_Str"+ requestedSize+ "String_Node_Str"+ bytesFreeInDir+ "String_Node_Str");
      }
    }
  }
  String errMsg="String_Node_Str" + arcFileName + "String_Node_Str"+ requestedSize;
  log.fatal(errMsg);
  throw new IOFailure(errMsg);
}
Program: 90041
Project: 90041
Buggy source:
/** 
 * Returns a String that identifies this bit archive application (within the bit archive, i.e. either with id ONE or TWO). The string has the following form: [hostaddress]_[port] fx. "10.0.0.1_80"
 * @return String with IP address of this host and, if specified, theHTTP_PORT_NUMBER from settings
 * @throws UnknownID - if InetAddress.getLocalHost() failed
 */
private String createBitarchiveAppId() throws UnknownID {
  String id;
  id=SystemUtils.getLocalIP();
  try {
    String port=Settings.get(CommonSettings.HTTP_PORT_NUMBER);
    id+="String_Node_Str" + port;
  }
 catch (  UnknownID e) {
    log.warn("String_Node_Str");
  }
  return id;
}

Fixed version (ground truth):
/** 
 * Returns a String that identifies this bit archive application (within the bit archive, i.e. either with id ONE or TWO). The string has the following form: hostaddress[_applicationinstanceid] fx. "10.0.0.1_appOne" or just "10.0.0.1", if no applicationinstanceid has been chosen. 
 * @return String with IP address of this host and, if specified, theAPPLICATION_INSTANCE_ID from settings
 * @throws UnknownID - if InetAddress.getLocalHost() failed
 */
private String createBitarchiveAppId() throws UnknownID {
  String id;
  id=SystemUtils.getLocalIP();
  try {
    String applicationInstanceId=Settings.get(CommonSettings.APPLICATION_INSTANCE_ID);
    if (!applicationInstanceId.isEmpty()) {
      id+="String_Node_Str" + applicationInstanceId;
    }
  }
 catch (  UnknownID e) {
    log.warn("String_Node_Str");
  }
  return id;
}
Program: 90042
Project: 90042
Buggy source:
/** 
 * Returns a String that identifies this bit archive application (within the bit archive, i.e. either with id ONE or TWO)
 * @return String with IP address of this host and, if specified, theHTTP_PORT_NUMBER from settings
 */
public String getBitarchiveAppId(){
  return bitarchiveAppId;
}

Fixed version (ground truth):
/** 
 * Returns a String that identifies this bit archive application (within the bit archive, i.e. either with id ONE or TWO)
 * @return String with IP address of this host and, if specified, theAPPLICATION_INSTANCE_ID from settings
 */
public String getBitarchiveAppId(){
  return bitarchiveAppId;
}
Program: 90043
Project: 90043
Buggy source:
/** 
 * Tests that register works, and cannot be called twice.
 * @throws Exception
 */
public void testRegister() throws Exception {
  SingleMBeanObject test=new SingleMBeanObject("String_Node_Str",new MyTestInterfaceObject(),MyTestInterface.class,ManagementFactory.getPlatformMBeanServer());
  assertFalse("String_Node_Str",platformMBeanServer.isRegistered(name));
  test.register();
  assertTrue("String_Node_Str",platformMBeanServer.isRegistered(name));
  Object attribute=platformMBeanServer.getAttribute(name,"String_Node_Str");
  assertEquals("String_Node_Str","String_Node_Str",attribute.toString());
  try {
    test.register();
    fail("String_Node_Str");
  }
 catch (  IllegalState e) {
  }
}

Fixed version (ground truth):
/** 
 * Tests that register works, and cannot be called twice.
 * @throws Exception
 */
public void testRegister() throws Exception {
  SingleMBeanObject test=new SingleMBeanObject("String_Node_Str",new MyTestInterfaceObject(),MyTestInterface.class,ManagementFactory.getPlatformMBeanServer());
  assertFalse("String_Node_Str" + name + "String_Node_Str",platformMBeanServer.isRegistered(name));
  test.register();
  assertTrue("String_Node_Str" + name + "String_Node_Str",platformMBeanServer.isRegistered(name));
  Object attribute=platformMBeanServer.getAttribute(name,"String_Node_Str");
  assertEquals("String_Node_Str","String_Node_Str",attribute.toString());
  try {
    test.register();
    fail("String_Node_Str");
  }
 catch (  IllegalState e) {
  }
}
Program: 90044
Project: 90044
Buggy source:
public void setUp(){
  rs.setUp();
  mBeanServer=ManagementFactory.getPlatformMBeanServer();
  Settings.set(CommonSettings.APPLICATION_NAME,"String_Node_Str");
  Settings.set(MonitorSettings.LOGGING_HISTORY_SIZE,Integer.toString(LOG_HISTORY_SIZE));
  Settings.set(CommonSettings.HTTP_PORT_NUMBER,"String_Node_Str");
  Settings.set(HarvesterSettings.HARVEST_CONTROLLER_PRIORITY,"String_Node_Str");
  Settings.set(CommonSettings.USE_REPLICA_ID,"String_Node_Str");
}

Fixed version (ground truth):
public void setUp(){
  rs.setUp();
  mBeanServer=ManagementFactory.getPlatformMBeanServer();
  Settings.set(CommonSettings.THIS_PHYSICAL_LOCATION,"String_Node_Str");
  Settings.set(CommonSettings.APPLICATION_NAME,"String_Node_Str");
  Settings.set(MonitorSettings.LOGGING_HISTORY_SIZE,Integer.toString(LOG_HISTORY_SIZE));
  Settings.set(CommonSettings.HTTP_PORT_NUMBER,"String_Node_Str");
  Settings.set(HarvesterSettings.HARVEST_CONTROLLER_PRIORITY,"String_Node_Str");
  Settings.set(CommonSettings.USE_REPLICA_ID,"String_Node_Str");
}
Program: 90046
Project: 90046
Buggy source:
/** 
 * Get the unique index request server instance.
 * @return The index request server.
 */
public static IndexRequestServer getInstance(){
synchronized (instance) {
    if (instance == null) {
      instance=new IndexRequestServer();
    }
  }
  return instance;
}

Fixed version (ground truth):
/** 
 * Get the unique index request server instance.
 * @return The index request server.
 */
public static IndexRequestServer getInstance(){
  if (instance == null) {
    instance=new IndexRequestServer();
  }
  return instance;
}
Program: 90047
Project: 90047
Buggy source:
/** 
 * Get a JMXConnector to a given host and port, using login and password.
 * @param hostName The host to attempt to connect to.
 * @param jmxPort The port on the host to connect to (a non-negative number)
 * @param login The login name to authenticate as (typically "controlRole"or "monitorRole".
 * @param password The password for JMX access
 * @return A JMX connector to the given host and port, using default RMI
 */
public static JMXConnector getJMXConnector(String hostName,int jmxPort,final String login,final String password){
  ArgumentNotValid.checkNotNullOrEmpty(hostName,"String_Node_Str");
  ArgumentNotValid.checkNotNegative(jmxPort,"String_Node_Str");
  ArgumentNotValid.checkNotNullOrEmpty(login,"String_Node_Str");
  ArgumentNotValid.checkNotNullOrEmpty(password,"String_Node_Str");
  JMXServiceURL rmiurl=getUrl(hostName,jmxPort,-1);
  Map<String,?> environment=(Map<String,?>)packageCredentials(login,password);
  Throwable lastException;
  int retries=0;
  do {
    try {
      return JMXConnectorFactory.connect(rmiurl,environment);
    }
 catch (    IOException e) {
      lastException=e;
      if (retries < MAX_TRIES && e.getCause() != null && e.getCause() instanceof ServiceUnavailableException) {
        TimeUtils.exponentialBackoffSleep(retries);
        continue;
      }
      break;
    }
  }
 while (retries++ < MAX_TRIES);
  throw new IOFailure("String_Node_Str" + rmiurl + "String_Node_Str"+ retries+ "String_Node_Str",lastException);
}

Fixed version (ground truth):
/** 
 * Get a JMXConnector to a given host and port, using login and password.
 * @param hostName The host to attempt to connect to.
 * @param jmxPort The port on the host to connect to (a non-negative number)
 * @param login The login name to authenticate as (typically "controlRole"or "monitorRole".
 * @param password The password for JMX access
 * @return A JMX connector to the given host and port, using default RMI
 */
public static JMXConnector getJMXConnector(String hostName,int jmxPort,final String login,final String password){
  ArgumentNotValid.checkNotNullOrEmpty(hostName,"String_Node_Str");
  ArgumentNotValid.checkNotNegative(jmxPort,"String_Node_Str");
  ArgumentNotValid.checkNotNullOrEmpty(login,"String_Node_Str");
  ArgumentNotValid.checkNotNullOrEmpty(password,"String_Node_Str");
  JMXServiceURL rmiurl=getUrl(hostName,jmxPort,-1);
  Map<String,?> environment=(Map<String,?>)packageCredentials(login,password);
  Throwable lastException;
  int retries=0;
  do {
    try {
      return JMXConnectorFactory.connect(rmiurl,environment);
    }
 catch (    IOException e) {
      lastException=e;
      if (retries < MAX_TRIES && e.getCause() != null && (e.getCause() instanceof ServiceUnavailableException || e.getCause() instanceof SocketTimeoutException)) {
        TimeUtils.exponentialBackoffSleep(retries);
        continue;
      }
      break;
    }
  }
 while (retries++ < MAX_TRIES);
  throw new IOFailure("String_Node_Str" + rmiurl + "String_Node_Str"+ retries+ "String_Node_Str",lastException);
}
Program: 90048
Project: 90048
Buggy source:
/** 
 * If a column is not active, this function generates the link  to showing a specific column again.
 * @param starredRequest A request to take parameters from.
 * @param parameter Reference to the column to show again.
 * @return The link to show the parameter again.
 */
public static String generateShowColumn(StarredRequest starredRequest,String parameter){
  ArgumentNotValid.checkNotNull(starredRequest,"String_Node_Str");
  ArgumentNotValid.checkNotNull(parameter,"String_Node_Str");
  if ("String_Node_Str".equals(starredRequest.getParameter(parameter))) {
    return "String_Node_Str";
  }
  return generateLink(starredRequest,parameter,"String_Node_Str",parameter) + "String_Node_Str";
}

Fixed version (ground truth):
/** 
 * If a column is not active, this function generates the link  to showing a specific column again.
 * @param starredRequest A request to take parameters from.
 * @param parameter Reference to the column to show again.
 * @return The link to show the parameter again.
 */
public static String generateShowColumn(StarredRequest starredRequest,String parameter){
  ArgumentNotValid.checkNotNull(starredRequest,"String_Node_Str");
  ArgumentNotValid.checkNotNull(parameter,"String_Node_Str");
  if (!"String_Node_Str".equals(starredRequest.getParameter(parameter))) {
    return "String_Node_Str";
  }
  return generateLink(starredRequest,parameter,"String_Node_Str",parameter) + "String_Node_Str";
}
Program: 90049
Project: 90049
Buggy source:
/** 
 * Execute an SQL statement and return the single long in the result set. This variant takes a query string and a single string arg and combines them to form a normal query.
 * @param query a query with ? for parameters
 * @param args parameters of type string, int, long or boolean
 * @return The long result
 * @throws IOFailure if the statement didn't result in exactly one long value
 */
public static Long selectLongValue(String query,Object... args){
  Connection c=DBConnect.getDBConnection();
  PreparedStatement s=null;
  try {
    s=DBUtils.prepareStatement(c,query,args);
    return selectLongValue(s);
  }
 catch (  SQLException e) {
    throw new IOFailure("String_Node_Str" + query + "String_Node_Str"+ args,e);
  }
 finally {
    DBUtils.closeStatementIfOpen(s);
  }
}

Fixed version (ground truth):
/** 
 * Execute an SQL statement and return the single long in the result set. This variant takes a query string and a single string arg and combines them to form a normal query.
 * @param query a query with ? for parameters
 * @param args parameters of type string, int, long or boolean
 * @return The long result
 * @throws IOFailure if the statement didn't result in exactly one long value
 */
public static Long selectLongValue(String query,Object... args){
  Connection c=DBConnect.getDBConnection();
  PreparedStatement s=null;
  try {
    s=DBUtils.prepareStatement(c,query,args);
    return selectLongValue(s);
  }
 catch (  SQLException e) {
    throw new IOFailure("String_Node_Str" + query + "String_Node_Str"+ args+ "String_Node_Str"+ ExceptionUtils.getSQLExceptionCause(e),e);
  }
 finally {
    DBUtils.closeStatementIfOpen(s);
  }
}
Program: 90050
Project: 90050
Buggy source:
/** 
 * Method to perform a rollback of complex DB updates.  If no commit has been performed, this will undo the entire transaction, otherwise nothing will happen.  This should be called in a finally block with no DB updates after the last commit. Thus exceptions while closing are ignored, but logged as warnings.
 * @param c the db-connection
 * @param action The action going on, before calling this method
 * @param o The being acted upon by this action
 */
public static void rollbackIfNeeded(Connection c,String action,Object o){
  try {
    c.rollback();
    c.setAutoCommit(true);
  }
 catch (  SQLException e) {
    log.warn("String_Node_Str" + action + "String_Node_Str"+ o,e);
  }
}

Fixed version (ground truth):
/** 
 * Method to perform a rollback of complex DB updates.  If no commit has been performed, this will undo the entire transaction, otherwise nothing will happen.  This should be called in a finally block with no DB updates after the last commit. Thus exceptions while closing are ignored, but logged as warnings.
 * @param c the db-connection
 * @param action The action going on, before calling this method
 * @param o The being acted upon by this action
 */
public static void rollbackIfNeeded(Connection c,String action,Object o){
  try {
    c.rollback();
    c.setAutoCommit(true);
  }
 catch (  SQLException e) {
    log.warn("String_Node_Str" + action + "String_Node_Str"+ o+ "String_Node_Str"+ ExceptionUtils.getSQLExceptionCause(e),e);
  }
}
Program: 90051
Project: 90051
Buggy source:
/** 
 * Execute an SQL query and return whether the result contains any rows.
 * @param query a query with ? for parameters
 * @param args parameters of type string, int, long or boolean
 * @return True if executing the query resulted in at least one row.
 * @throws IOFailure if there were problems with the SQL query
 */
public static boolean selectAny(String query,Object... args){
  Connection c=DBConnect.getDBConnection();
  PreparedStatement s=null;
  try {
    s=prepareStatement(c,query,args);
    return s.executeQuery().next();
  }
 catch (  SQLException e) {
    throw new IOFailure("String_Node_Str" + query + "String_Node_Str"+ args,e);
  }
 finally {
    closeStatementIfOpen(s);
  }
}

Fixed version (ground truth):
/** 
 * Execute an SQL query and return whether the result contains any rows.
 * @param query a query with ? for parameters
 * @param args parameters of type string, int, long or boolean
 * @return True if executing the query resulted in at least one row.
 * @throws IOFailure if there were problems with the SQL query
 */
public static boolean selectAny(String query,Object... args){
  Connection c=DBConnect.getDBConnection();
  PreparedStatement s=null;
  try {
    s=prepareStatement(c,query,args);
    return s.executeQuery().next();
  }
 catch (  SQLException e) {
    throw new IOFailure("String_Node_Str" + query + "String_Node_Str"+ args+ "String_Node_Str"+ ExceptionUtils.getSQLExceptionCause(e),e);
  }
 finally {
    closeStatementIfOpen(s);
  }
}
Program: 90052
Project: 90052
Buggy source:
/** 
 * Return a description of where an object is used elsewhere in the database, or null.
 * @param select A select statement finding the names of other uses.  Thestatement should result in exactly one column of string values.
 * @param victim The object being used.
 * @param args Any objects that may be used to prepare the select statement.
 * @return A string describing the usages, or null if no usages were found.
 */
public static String getUsages(String select,Object victim,Object... args){
  Connection c=DBConnect.getDBConnection();
  PreparedStatement s=null;
  try {
    s=prepareStatement(c,select,args);
    ResultSet res=s.executeQuery();
    if (res.next()) {
      List<String> usedIn=new ArrayList<String>();
      do {
        usedIn.add(res.getString(1));
      }
 while (res.next());
      return usedIn.toString();
    }
    return null;
  }
 catch (  SQLException e) {
    final String message="String_Node_Str" + victim;
    log.warn(message,e);
    throw new IOFailure(message,e);
  }
 finally {
    closeStatementIfOpen(s);
  }
}

Fixed version (ground truth):
/** 
 * Return a description of where an object is used elsewhere in the database, or null.
 * @param select A select statement finding the names of other uses.  Thestatement should result in exactly one column of string values.
 * @param victim The object being used.
 * @param args Any objects that may be used to prepare the select statement.
 * @return A string describing the usages, or null if no usages were found.
 */
public static String getUsages(String select,Object victim,Object... args){
  Connection c=DBConnect.getDBConnection();
  PreparedStatement s=null;
  try {
    s=prepareStatement(c,select,args);
    ResultSet res=s.executeQuery();
    if (res.next()) {
      List<String> usedIn=new ArrayList<String>();
      do {
        usedIn.add(res.getString(1));
      }
 while (res.next());
      return usedIn.toString();
    }
    return null;
  }
 catch (  SQLException e) {
    final String message="String_Node_Str" + victim + "String_Node_Str"+ ExceptionUtils.getSQLExceptionCause(e);
    log.warn(message,e);
    throw new IOFailure(message,e);
  }
 finally {
    closeStatementIfOpen(s);
  }
}
Program: 90053
Project: 90053
Buggy source:
/** 
 * Execute an SQL statement and return the first long in the result set, or null if resultset is empty.
 * @param query a query with ? for parameters
 * @param args parameters of type string, int, long or boolean
 * @return The long result, or will return null in one of the two followingcases: There is no results, or the first result is a null-value.
 * @throws IOFailure on SQL errors.
 */
public static Long selectFirstLongValueIfAny(String query,Object... args){
  Connection c=DBConnect.getDBConnection();
  PreparedStatement s=null;
  try {
    s=DBUtils.prepareStatement(c,query,args);
    ResultSet rs=s.executeQuery();
    if (rs.next()) {
      return DBUtils.getLongMaybeNull(rs,1);
    }
 else {
      return null;
    }
  }
 catch (  SQLException e) {
    String message="String_Node_Str" + query + "String_Node_Str";
    log.warn(message,e);
    throw new IOFailure(message,e);
  }
 finally {
    DBUtils.closeStatementIfOpen(s);
  }
}

Fixed version (ground truth):
/** 
 * Execute an SQL statement and return the first long in the result set, or null if resultset is empty.
 * @param query a query with ? for parameters
 * @param args parameters of type string, int, long or boolean
 * @return The long result, or will return null in one of the two followingcases: There is no results, or the first result is a null-value.
 * @throws IOFailure on SQL errors.
 */
public static Long selectFirstLongValueIfAny(String query,Object... args){
  Connection c=DBConnect.getDBConnection();
  PreparedStatement s=null;
  try {
    s=DBUtils.prepareStatement(c,query,args);
    ResultSet rs=s.executeQuery();
    if (rs.next()) {
      return DBUtils.getLongMaybeNull(rs,1);
    }
 else {
      return null;
    }
  }
 catch (  SQLException e) {
    String message="String_Node_Str" + query + "String_Node_Str"+ "String_Node_Str"+ ExceptionUtils.getSQLExceptionCause(e);
    log.warn(message,e);
    throw new IOFailure(message,e);
  }
 finally {
    DBUtils.closeStatementIfOpen(s);
  }
}
Program: 90054
Project: 90054
Buggy source:
/** 
 * Execute an SQL statement and return the single string in the result set.
 * @param s A prepared statement
 * @return The string result, or null if the result was a null valueNote that a null value is not the same as no result rows.
 * @throws IOFailure if the statement didn't result in exactly one row witha string or null value
 */
public static String selectStringValue(PreparedStatement s){
  try {
    ResultSet res=s.executeQuery();
    if (!res.next()) {
      throw new IOFailure("String_Node_Str" + s);
    }
    String resultString=res.getString(1);
    if (res.wasNull()) {
      resultString=null;
    }
    if (res.next()) {
      throw new IOFailure("String_Node_Str" + s);
    }
    return resultString;
  }
 catch (  SQLException e) {
    throw new IOFailure("String_Node_Str" + s,e);
  }
}

Fixed version (ground truth):
/** 
 * Execute an SQL statement and return the single string in the result set.
 * @param s A prepared statement
 * @return The string result, or null if the result was a null valueNote that a null value is not the same as no result rows.
 * @throws IOFailure if the statement didn't result in exactly one row witha string or null value
 */
public static String selectStringValue(PreparedStatement s){
  try {
    ResultSet res=s.executeQuery();
    if (!res.next()) {
      throw new IOFailure("String_Node_Str" + s);
    }
    String resultString=res.getString(1);
    if (res.wasNull()) {
      resultString=null;
    }
    if (res.next()) {
      throw new IOFailure("String_Node_Str" + s);
    }
    return resultString;
  }
 catch (  SQLException e) {
    throw new IOFailure("String_Node_Str" + s + "String_Node_Str"+ ExceptionUtils.getSQLExceptionCause(e),e);
  }
}
Program: 90055
Project: 90055
Buggy source:
/** 
 * Execute an SQL statement and return the single int in the result set. This variant takes a query string and a single string arg and combines them to form a normal query.
 * @param query a query with ? for parameters
 * @param args parameters of type string, int, long or boolean
 * @return The integer result
 * @throws IOFailure if the statement didn't result in exactly one integer
 */
public static Integer selectIntValue(String query,Object... args){
  Connection c=DBConnect.getDBConnection();
  PreparedStatement s=null;
  try {
    s=DBUtils.prepareStatement(c,query,args);
    return selectIntValue(s);
  }
 catch (  SQLException e) {
    throw new IOFailure("String_Node_Str" + query + "String_Node_Str"+ args,e);
  }
 finally {
    DBUtils.closeStatementIfOpen(s);
  }
}

Fixed version (ground truth):
/** 
 * Execute an SQL statement and return the single int in the result set. This variant takes a query string and a single string arg and combines them to form a normal query.
 * @param query a query with ? for parameters
 * @param args parameters of type string, int, long or boolean
 * @return The integer result
 * @throws IOFailure if the statement didn't result in exactly one integer
 */
public static Integer selectIntValue(String query,Object... args){
  Connection c=DBConnect.getDBConnection();
  PreparedStatement s=null;
  try {
    s=DBUtils.prepareStatement(c,query,args);
    return selectIntValue(s);
  }
 catch (  SQLException e) {
    throw new IOFailure("String_Node_Str" + query + "String_Node_Str"+ args+ "String_Node_Str"+ ExceptionUtils.getSQLExceptionCause(e),e);
  }
 finally {
    DBUtils.closeStatementIfOpen(s);
  }
}
Program: 90056
Project: 90056
Buggy source:
/** 
 * Returns the version of a table according to schemaversions, or 0 for the initial, unnumbered version.
 * @param tablename The name of a table in the database.
 * @return Version of the given table.
 * @throws IOFailure if DB table schemaversions does not exist
 */
public static int getTableVersion(String tablename) throws IOFailure {
  Connection c=DBConnect.getDBConnection();
  PreparedStatement s=null;
  int version=0;
  try {
    s=c.prepareStatement("String_Node_Str" + "String_Node_Str");
    s.setString(1,tablename);
    ResultSet res=s.executeQuery();
    if (!res.next()) {
      log.warn("String_Node_Str" + tablename + "String_Node_Str");
    }
 else {
      version=res.getInt(1);
      if (res.wasNull()) {
        log.warn("String_Node_Str" + tablename + "String_Node_Str");
      }
    }
    return version;
  }
 catch (  SQLException e) {
    String msg="String_Node_Str" + tablename;
    log.warn(msg,e);
    throw new IOFailure(msg,e);
  }
 finally {
    DBUtils.closeStatementIfOpen(s);
  }
}

Fixed version (ground truth):
/** 
 * Returns the version of a table according to schemaversions, or 0 for the initial, unnumbered version.
 * @param tablename The name of a table in the database.
 * @return Version of the given table.
 * @throws IOFailure if DB table schemaversions does not exist
 */
public static int getTableVersion(String tablename) throws IOFailure {
  Connection c=DBConnect.getDBConnection();
  PreparedStatement s=null;
  int version=0;
  try {
    s=c.prepareStatement("String_Node_Str" + "String_Node_Str");
    s.setString(1,tablename);
    ResultSet res=s.executeQuery();
    if (!res.next()) {
      log.warn("String_Node_Str" + tablename + "String_Node_Str");
    }
 else {
      version=res.getInt(1);
      if (res.wasNull()) {
        log.warn("String_Node_Str" + tablename + "String_Node_Str");
      }
    }
    return version;
  }
 catch (  SQLException e) {
    String msg="String_Node_Str" + tablename + "String_Node_Str"+ ExceptionUtils.getSQLExceptionCause(e);
    log.warn(msg,e);
    throw new IOFailure(msg,e);
  }
 finally {
    DBUtils.closeStatementIfOpen(s);
  }
}
Program: 90057
Project: 90057
Buggy source:
/** 
 * Check whether an object is used elsewhere in the database.
 * @param select A select statement finding the names of other uses.  Thestatement should result in exactly one column of string values.
 * @param victim The object being used.
 * @param args Any objects that may be used to prepare the select statement.
 * @throws PermissionDenied if the object has usages.
 */
public static void checkForUses(String select,Object victim,Object... args){
  String usages=DBUtils.getUsages(select,victim,args);
  if (usages != null) {
    String message="String_Node_Str" + victim + "String_Node_Str"+ usages;
    throw new PermissionDenied(message);
  }
  Connection c=DBConnect.getDBConnection();
  PreparedStatement s=null;
  try {
    s=prepareStatement(c,select,args);
    ResultSet res=s.executeQuery();
    if (res.next()) {
      List<String> usedIn=new ArrayList<String>();
      do {
        usedIn.add(res.getString(1));
      }
 while (res.next());
    }
  }
 catch (  SQLException e) {
    final String message="String_Node_Str" + victim;
    log.warn(message,e);
    throw new IOFailure(message,e);
  }
 finally {
    closeStatementIfOpen(s);
  }
}

Fixed version (ground truth):
/** 
 * Check whether an object is used elsewhere in the database.
 * @param select A select statement finding the names of other uses.  Thestatement should result in exactly one column of string values.
 * @param victim The object being used.
 * @param args Any objects that may be used to prepare the select statement.
 * @throws PermissionDenied if the object has usages.
 */
public static void checkForUses(String select,Object victim,Object... args){
  String usages=DBUtils.getUsages(select,victim,args);
  if (usages != null) {
    String message="String_Node_Str" + victim + "String_Node_Str"+ usages;
    throw new PermissionDenied(message);
  }
  Connection c=DBConnect.getDBConnection();
  PreparedStatement s=null;
  try {
    s=prepareStatement(c,select,args);
    ResultSet res=s.executeQuery();
    if (res.next()) {
      List<String> usedIn=new ArrayList<String>();
      do {
        usedIn.add(res.getString(1));
      }
 while (res.next());
    }
  }
 catch (  SQLException e) {
    final String message="String_Node_Str" + victim;
    log.warn(message + "String_Node_Str" + ExceptionUtils.getSQLExceptionCause(e),e);
    throw new IOFailure(message + "String_Node_Str" + ExceptionUtils.getSQLExceptionCause(e),e);
  }
 finally {
    closeStatementIfOpen(s);
  }
}
Program: 90058
Project: 90058
Buggy source:
/** 
 * Close a statement, if not closed already Note: This does not throw any a SQLException, because it is always called inside a finally-clause. Exceptions are logged as warnings, though.
 * @param s a statement
 */
public static void closeStatementIfOpen(PreparedStatement s){
  if (s != null) {
    try {
      s.close();
    }
 catch (    SQLException e) {
      log.warn("String_Node_Str" + s,e);
    }
  }
}

Fixed version (ground truth):
/** 
 * Close a statement, if not closed already Note: This does not throw any a SQLException, because it is always called inside a finally-clause. Exceptions are logged as warnings, though.
 * @param s a statement
 */
public static void closeStatementIfOpen(PreparedStatement s){
  if (s != null) {
    try {
      s.close();
    }
 catch (    SQLException e) {
      log.warn("String_Node_Str" + s + "String_Node_Str"+ ExceptionUtils.getSQLExceptionCause(e),e);
    }
  }
}
Program: 90059
Project: 90059
Buggy source:
/** 
 * Update a database by executing all the statements in the updates String array. NOTE: this must NOT be used for tables under version control It must only be used in connection with temporary tables e.g. used for backup.
 * @param updates The SQL statements that makes the necessaryupdates.
 * @throws IOFailure in case of problems in interacting with the database
 */
public static void executeSQL(final String... updates){
  Connection c=DBConnect.getDBConnection();
  PreparedStatement st=null;
  String s="String_Node_Str";
  try {
    c.setAutoCommit(false);
    for (    String update : updates) {
      s=update;
      log.debug("String_Node_Str" + update);
      st=prepareStatement(c,update);
      st.executeUpdate();
      st.close();
    }
    c.setAutoCommit(true);
    log.debug("String_Node_Str" + StringUtils.conjoin("String_Node_Str",updates) + "String_Node_Str");
  }
 catch (  SQLException e) {
    String msg="String_Node_Str" + s;
    log.warn(msg,e);
    throw new IOFailure(msg,e);
  }
 finally {
    rollbackIfNeeded(c,"String_Node_Str",StringUtils.conjoin("String_Node_Str",updates) + "String_Node_Str");
    closeStatementIfOpen(st);
  }
}

Fixed version (ground truth):
/** 
 * Update a database by executing all the statements in the updates String array. NOTE: this must NOT be used for tables under version control It must only be used in connection with temporary tables e.g. used for backup.
 * @param updates The SQL statements that makes the necessaryupdates.
 * @throws IOFailure in case of problems in interacting with the database
 */
public static void executeSQL(final String... updates){
  Connection c=DBConnect.getDBConnection();
  PreparedStatement st=null;
  String s="String_Node_Str";
  try {
    c.setAutoCommit(false);
    for (    String update : updates) {
      s=update;
      log.debug("String_Node_Str" + update);
      st=prepareStatement(c,update);
      st.executeUpdate();
      st.close();
    }
    c.setAutoCommit(true);
    log.debug("String_Node_Str" + StringUtils.conjoin("String_Node_Str",updates) + "String_Node_Str");
  }
 catch (  SQLException e) {
    String msg="String_Node_Str" + s + "String_Node_Str"+ ExceptionUtils.getSQLExceptionCause(e);
    log.warn(msg,e);
    throw new IOFailure(msg,e);
  }
 finally {
    rollbackIfNeeded(c,"String_Node_Str",StringUtils.conjoin("String_Node_Str",updates) + "String_Node_Str");
    closeStatementIfOpen(st);
  }
}
Program: 90060
Project: 90060
Buggy source:
/** 
 * Returns <tt>true</tt> if the iteration has more elements. (In other words, returns <tt>true</tt> if <tt>next</tt> would return an element rather than throwing an exception.)
 * @return <tt>true</tt> if the iterator has more elements.
 */
public boolean hasNext(){
  if (objectCache == null) {
    try {
      if (!isClosed && res.next()) {
        objectCache=filter(res);
      }
 else {
        isClosed=true;
        res.close();
      }
    }
 catch (    SQLException e) {
      throw new IOFailure("String_Node_Str" + res,e);
    }
  }
  return objectCache != null;
}

Fixed version (ground truth):
/** 
 * Returns <tt>true</tt> if the iteration has more elements. (In other words, returns <tt>true</tt> if <tt>next</tt> would return an element rather than throwing an exception.)
 * @return <tt>true</tt> if the iterator has more elements.
 */
public boolean hasNext(){
  if (objectCache == null) {
    try {
      if (!isClosed && res.next()) {
        objectCache=filter(res);
      }
 else {
        isClosed=true;
        res.close();
      }
    }
 catch (    SQLException e) {
      throw new IOFailure("String_Node_Str" + res + "String_Node_Str"+ ExceptionUtils.getSQLExceptionCause(e),e);
    }
  }
  return objectCache != null;
}
Program: 90061
Project: 90061
Buggy source:
/** 
 * this test confirms that the message generated by getSQLExceptionCause() contains all the information in the original SQLException
 */
public void testGetSQLExceptionCause(){
  SQLException ex1=new SQLException("String_Node_Str","String_Node_Str",101);
  SQLException ex2=new SQLException("String_Node_Str","String_Node_Str",102);
  SQLException ex3=new SQLException("String_Node_Str","String_Node_Str",103);
  ex1.setNextException(ex2);
  ex2.setNextException(ex3);
  String message=ExceptionUtils.getSQLExceptionCause(ex1);
  System.out.println(message);
  StringAsserts.assertStringContains("String_Node_Str" + "String_Node_Str" + "String_Node_Str",message,"String_Node_Str","String_Node_Str","String_Node_Str","String_Node_Str","String_Node_Str","String_Node_Str","String_Node_Str","String_Node_Str","String_Node_Str");
}

Fixed version (ground truth):
/** 
 * this test confirms that the message generated by getSQLExceptionCause() contains all the information in the original SQLException
 */
public void testGetSQLExceptionCause(){
  SQLException ex1=new SQLException("String_Node_Str","String_Node_Str",101);
  SQLException ex2=new SQLException("String_Node_Str","String_Node_Str",102);
  SQLException ex3=new SQLException("String_Node_Str","String_Node_Str",103);
  ex1.setNextException(ex2);
  ex2.setNextException(ex3);
  String message=dk.netarkivet.common.utils.ExceptionUtils.getSQLExceptionCause(ex1);
  System.out.println(message);
  StringAsserts.assertStringContains("String_Node_Str" + "String_Node_Str" + "String_Node_Str",message,"String_Node_Str","String_Node_Str","String_Node_Str","String_Node_Str","String_Node_Str","String_Node_Str","String_Node_Str","String_Node_Str","String_Node_Str");
}