nus-yam/ex-repair huggingface dataset:
Program: 91358
Project: 91358
Buggy source:
@Override public int parseArguments(final Parameters params) throws CmdLineException {
  final String name=params.getParameter(0);
  if (new File(name).isDirectory()) {
    setter.addValue(new FileTreeIterator(new File(name),FS.DETECTED));
    return 1;
  }
  if (new File(name).isFile()) {
    final DirCache dirc;
    try {
      dirc=DirCache.read(new File(name));
    }
 catch (    IOException e) {
      throw new CmdLineException(MessageFormat.format(CLIText.get().notAnIndexFile,name),e);
    }
    setter.addValue(new DirCacheIterator(dirc));
    return 1;
  }
  final ObjectId id;
  try {
    id=clp.getRepository().resolve(name);
  }
 catch (  IOException e) {
    throw new CmdLineException(e.getMessage());
  }
  if (id == null)   throw new CmdLineException(MessageFormat.format(CLIText.get().notATree,name));
  final CanonicalTreeParser p=new CanonicalTreeParser();
  final ObjectReader curs=clp.getRepository().newObjectReader();
  try {
    p.reset(curs,clp.getRevWalk().parseTree(id));
  }
 catch (  MissingObjectException e) {
    throw new CmdLineException(MessageFormat.format(CLIText.get().notATree,name));
  }
catch (  IncorrectObjectTypeException e) {
    throw new CmdLineException(MessageFormat.format(CLIText.get().notATree,name));
  }
catch (  IOException e) {
    throw new CmdLineException(MessageFormat.format(CLIText.get().cannotReadBecause,name,e.getMessage()));
  }
 finally {
    curs.release();
  }
  setter.addValue(p);
  return 1;
}

Fixed version (ground truth):
@Override public int parseArguments(final Parameters params) throws CmdLineException {
  final String name=params.getParameter(0);
  if (new File(name).isDirectory()) {
    setter.addValue(new FileTreeIterator(new File(name),FS.DETECTED));
    return 1;
  }
  if (new File(name).isFile()) {
    final DirCache dirc;
    try {
      dirc=DirCache.read(new File(name),FS.DETECTED);
    }
 catch (    IOException e) {
      throw new CmdLineException(MessageFormat.format(CLIText.get().notAnIndexFile,name),e);
    }
    setter.addValue(new DirCacheIterator(dirc));
    return 1;
  }
  final ObjectId id;
  try {
    id=clp.getRepository().resolve(name);
  }
 catch (  IOException e) {
    throw new CmdLineException(e.getMessage());
  }
  if (id == null)   throw new CmdLineException(MessageFormat.format(CLIText.get().notATree,name));
  final CanonicalTreeParser p=new CanonicalTreeParser();
  final ObjectReader curs=clp.getRepository().newObjectReader();
  try {
    p.reset(curs,clp.getRevWalk().parseTree(id));
  }
 catch (  MissingObjectException e) {
    throw new CmdLineException(MessageFormat.format(CLIText.get().notATree,name));
  }
catch (  IncorrectObjectTypeException e) {
    throw new CmdLineException(MessageFormat.format(CLIText.get().notATree,name));
  }
catch (  IOException e) {
    throw new CmdLineException(MessageFormat.format(CLIText.get().cannotReadBecause,name,e.getMessage()));
  }
 finally {
    curs.release();
  }
  setter.addValue(p);
  return 1;
}
Program: 91359
Project: 91359
Buggy source:
public void testLockMissing_TempIndex() throws Exception {
  final File idx=new File(db.getDirectory(),"String_Node_Str");
  final File lck=new File(db.getDirectory(),"String_Node_Str");
  assertFalse(idx.exists());
  assertFalse(lck.exists());
  final DirCache dc=DirCache.lock(idx);
  assertNotNull(dc);
  assertFalse(idx.exists());
  assertTrue(lck.exists());
  assertEquals(0,dc.getEntryCount());
  dc.unlock();
  assertFalse(idx.exists());
  assertFalse(lck.exists());
}

Fixed version (ground truth):
public void testLockMissing_TempIndex() throws Exception {
  final File idx=new File(db.getDirectory(),"String_Node_Str");
  final File lck=new File(db.getDirectory(),"String_Node_Str");
  assertFalse(idx.exists());
  assertFalse(lck.exists());
  final DirCache dc=DirCache.lock(idx,db.getFS());
  assertNotNull(dc);
  assertFalse(idx.exists());
  assertTrue(lck.exists());
  assertEquals(0,dc.getEntryCount());
  dc.unlock();
  assertFalse(idx.exists());
  assertFalse(lck.exists());
}
Program: 91360
Project: 91360
Buggy source:
public void testReadMissing_TempIndex() throws Exception {
  final File idx=new File(db.getDirectory(),"String_Node_Str");
  assertFalse(idx.exists());
  final DirCache dc=DirCache.read(idx);
  assertNotNull(dc);
  assertEquals(0,dc.getEntryCount());
}

Fixed version (ground truth):
public void testReadMissing_TempIndex() throws Exception {
  final File idx=new File(db.getDirectory(),"String_Node_Str");
  assertFalse(idx.exists());
  final DirCache dc=DirCache.read(idx,db.getFS());
  assertNotNull(dc);
  assertEquals(0,dc.getEntryCount());
}
Program: 91361
Project: 91361
Buggy source:
public void testUnsupportedRequiredExtension() throws Exception {
  final DirCache dc=new DirCache(pathOf("String_Node_Str"));
  try {
    dc.read();
    fail("String_Node_Str");
  }
 catch (  CorruptObjectException err) {
    assertEquals("String_Node_Str" + "String_Node_Str",err.getMessage());
  }
}

Fixed version (ground truth):
public void testUnsupportedRequiredExtension() throws Exception {
  final DirCache dc=new DirCache(pathOf("String_Node_Str"),FS.DETECTED);
  try {
    dc.read();
    fail("String_Node_Str");
  }
 catch (  CorruptObjectException err) {
    assertEquals("String_Node_Str" + "String_Node_Str",err.getMessage());
  }
}
Program: 91362
Project: 91362
Buggy source:
public void testTreeWalk_LsFiles() throws Exception {
  final Repository db=createBareRepository();
  final Map<String,CGitIndexRecord> ls=readLsFiles();
  final DirCache dc=new DirCache(index);
  assertEquals(0,dc.getEntryCount());
  dc.read();
  assertEquals(ls.size(),dc.getEntryCount());
{
    final Iterator<CGitIndexRecord> rItr=ls.values().iterator();
    final TreeWalk tw=new TreeWalk(db);
    tw.reset();
    tw.setRecursive(true);
    tw.addTree(new DirCacheIterator(dc));
    while (rItr.hasNext()) {
      final DirCacheIterator dcItr;
      assertTrue(tw.next());
      dcItr=tw.getTree(0,DirCacheIterator.class);
      assertNotNull(dcItr);
      assertEqual(rItr.next(),dcItr.getDirCacheEntry());
    }
  }
}

Fixed version (ground truth):
public void testTreeWalk_LsFiles() throws Exception {
  final Repository db=createBareRepository();
  final Map<String,CGitIndexRecord> ls=readLsFiles();
  final DirCache dc=new DirCache(index,db.getFS());
  assertEquals(0,dc.getEntryCount());
  dc.read();
  assertEquals(ls.size(),dc.getEntryCount());
{
    final Iterator<CGitIndexRecord> rItr=ls.values().iterator();
    final TreeWalk tw=new TreeWalk(db);
    tw.reset();
    tw.setRecursive(true);
    tw.addTree(new DirCacheIterator(dc));
    while (rItr.hasNext()) {
      final DirCacheIterator dcItr;
      assertTrue(tw.next());
      dcItr=tw.getTree(0,DirCacheIterator.class);
      assertNotNull(dcItr);
      assertEqual(rItr.next(),dcItr.getDirCacheEntry());
    }
  }
}
Program: 91363
Project: 91363
Buggy source:
public void testReadIndex_DirCacheTree() throws Exception {
  final Map<String,CGitIndexRecord> cList=readLsFiles();
  final Map<String,CGitLsTreeRecord> cTree=readLsTree();
  final DirCache dc=new DirCache(index);
  assertEquals(0,dc.getEntryCount());
  dc.read();
  assertEquals(cList.size(),dc.getEntryCount());
  final DirCacheTree jTree=dc.getCacheTree(false);
  assertNotNull(jTree);
  assertEquals("String_Node_Str",jTree.getNameString());
  assertEquals("String_Node_Str",jTree.getPathString());
  assertTrue(jTree.isValid());
  assertEquals(ObjectId.fromString("String_Node_Str"),jTree.getObjectId());
  assertEquals(cList.size(),jTree.getEntrySpan());
  final ArrayList<CGitLsTreeRecord> subtrees=new ArrayList<CGitLsTreeRecord>();
  for (  final CGitLsTreeRecord r : cTree.values()) {
    if (FileMode.TREE.equals(r.mode))     subtrees.add(r);
  }
  assertEquals(subtrees.size(),jTree.getChildCount());
  for (int i=0; i < jTree.getChildCount(); i++) {
    final DirCacheTree sj=jTree.getChild(i);
    final CGitLsTreeRecord sc=subtrees.get(i);
    assertEquals(sc.path,sj.getNameString());
    assertEquals(sc.path + "String_Node_Str",sj.getPathString());
    assertTrue(sj.isValid());
    assertEquals(sc.id,sj.getObjectId());
  }
}

Fixed version (ground truth):
public void testReadIndex_DirCacheTree() throws Exception {
  final Map<String,CGitIndexRecord> cList=readLsFiles();
  final Map<String,CGitLsTreeRecord> cTree=readLsTree();
  final DirCache dc=new DirCache(index,FS.DETECTED);
  assertEquals(0,dc.getEntryCount());
  dc.read();
  assertEquals(cList.size(),dc.getEntryCount());
  final DirCacheTree jTree=dc.getCacheTree(false);
  assertNotNull(jTree);
  assertEquals("String_Node_Str",jTree.getNameString());
  assertEquals("String_Node_Str",jTree.getPathString());
  assertTrue(jTree.isValid());
  assertEquals(ObjectId.fromString("String_Node_Str"),jTree.getObjectId());
  assertEquals(cList.size(),jTree.getEntrySpan());
  final ArrayList<CGitLsTreeRecord> subtrees=new ArrayList<CGitLsTreeRecord>();
  for (  final CGitLsTreeRecord r : cTree.values()) {
    if (FileMode.TREE.equals(r.mode))     subtrees.add(r);
  }
  assertEquals(subtrees.size(),jTree.getChildCount());
  for (int i=0; i < jTree.getChildCount(); i++) {
    final DirCacheTree sj=jTree.getChild(i);
    final CGitLsTreeRecord sc=subtrees.get(i);
    assertEquals(sc.path,sj.getNameString());
    assertEquals(sc.path + "String_Node_Str",sj.getPathString());
    assertTrue(sj.isValid());
    assertEquals(sc.id,sj.getObjectId());
  }
}
Program: 91364
Project: 91364
Buggy source:
public void testUnsupportedOptionalExtension() throws Exception {
  final DirCache dc=new DirCache(pathOf("String_Node_Str"));
  dc.read();
  assertEquals(1,dc.getEntryCount());
  assertEquals("String_Node_Str",dc.getEntry(0).getPathString());
}

Fixed version (ground truth):
public void testUnsupportedOptionalExtension() throws Exception {
  final DirCache dc=new DirCache(pathOf("String_Node_Str"),FS.DETECTED);
  dc.read();
  assertEquals(1,dc.getEntryCount());
  assertEquals("String_Node_Str",dc.getEntry(0).getPathString());
}
Program: 91365
Project: 91365
Buggy source:
public void testReadIndex_LsFiles() throws Exception {
  final Map<String,CGitIndexRecord> ls=readLsFiles();
  final DirCache dc=new DirCache(index);
  assertEquals(0,dc.getEntryCount());
  dc.read();
  assertEquals(ls.size(),dc.getEntryCount());
{
    final Iterator<CGitIndexRecord> rItr=ls.values().iterator();
    for (int i=0; rItr.hasNext(); i++)     assertEqual(rItr.next(),dc.getEntry(i));
  }
}

Fixed version (ground truth):
public void testReadIndex_LsFiles() throws Exception {
  final Map<String,CGitIndexRecord> ls=readLsFiles();
  final DirCache dc=new DirCache(index,FS.DETECTED);
  assertEquals(0,dc.getEntryCount());
  dc.read();
  assertEquals(ls.size(),dc.getEntryCount());
{
    final Iterator<CGitIndexRecord> rItr=ls.values().iterator();
    for (int i=0; rItr.hasNext(); i++)     assertEqual(rItr.next(),dc.getEntry(i));
  }
}
Program: 91366
Project: 91366
Buggy source:
public void testCorruptChecksumAtFooter() throws Exception {
  final DirCache dc=new DirCache(pathOf("String_Node_Str"));
  try {
    dc.read();
    fail("String_Node_Str");
  }
 catch (  CorruptObjectException err) {
    assertEquals("String_Node_Str",err.getMessage());
  }
}

Fixed version (ground truth):
public void testCorruptChecksumAtFooter() throws Exception {
  final DirCache dc=new DirCache(pathOf("String_Node_Str"),FS.DETECTED);
  try {
    dc.read();
    fail("String_Node_Str");
  }
 catch (  CorruptObjectException err) {
    assertEquals("String_Node_Str",err.getMessage());
  }
}
Program: 91368
Project: 91368
Buggy source:
/** 
 * Try modify a ref that is locked
 * @throws IOException
 */
public void testUpdateRefLockFailureLocked() throws IOException {
  ObjectId opid=db.resolve("String_Node_Str");
  ObjectId pid=db.resolve("String_Node_Str");
  RefUpdate updateRef=db.updateRef("String_Node_Str");
  updateRef.setNewObjectId(pid);
  LockFile lockFile1=new LockFile(new File(db.getDirectory(),"String_Node_Str"));
  try {
    assertTrue(lockFile1.lock());
    Result update=updateRef.update();
    assertEquals(Result.LOCK_FAILURE,update);
    assertEquals(opid,db.resolve("String_Node_Str"));
    LockFile lockFile2=new LockFile(new File(db.getDirectory(),"String_Node_Str"));
    assertFalse(lockFile2.lock());
  }
  finally {
    lockFile1.unlock();
  }
}

Fixed version (ground truth):
/** 
 * Try modify a ref that is locked
 * @throws IOException
 */
public void testUpdateRefLockFailureLocked() throws IOException {
  ObjectId opid=db.resolve("String_Node_Str");
  ObjectId pid=db.resolve("String_Node_Str");
  RefUpdate updateRef=db.updateRef("String_Node_Str");
  updateRef.setNewObjectId(pid);
  LockFile lockFile1=new LockFile(new File(db.getDirectory(),"String_Node_Str"),db.getFS());
  try {
    assertTrue(lockFile1.lock());
    Result update=updateRef.update();
    assertEquals(Result.LOCK_FAILURE,update);
    assertEquals(opid,db.resolve("String_Node_Str"));
    LockFile lockFile2=new LockFile(new File(db.getDirectory(),"String_Node_Str"),db.getFS());
    assertFalse(lockFile2.lock());
  }
  finally {
    lockFile1.unlock();
  }
}
Program: 91369
Project: 91369
Buggy source:
private FileBasedConfig configFor(File gitDir) throws IOException, ConfigInvalidException {
  FileBasedConfig cfg=new FileBasedConfig(new File(gitDir,"String_Node_Str"));
  cfg.load();
  return cfg;
}

Fixed version (ground truth):
private FileBasedConfig configFor(File gitDir) throws IOException, ConfigInvalidException {
  File configPath=new File(gitDir,"String_Node_Str");
  FileBasedConfig cfg=new FileBasedConfig(configPath,FS.DETECTED);
  cfg.load();
  return cfg;
}
Program: 91370
Project: 91370
Buggy source:
public void test006_ReadUglyConfig() throws IOException, ConfigInvalidException {
  final File cfg=new File(db.getDirectory(),"String_Node_Str");
  final FileBasedConfig c=new FileBasedConfig(cfg);
  final FileWriter pw=new FileWriter(cfg);
  final String configStr="String_Node_Str" + "String_Node_Str" + "String_Node_Str"+ "String_Node_Str"+ "String_Node_Str"+ "String_Node_Str";
  pw.write(configStr);
  pw.close();
  c.load();
  assertEquals("String_Node_Str",c.getString("String_Node_Str",null,"String_Node_Str"));
  assertEquals("String_Node_Str",c.getString("String_Node_Str",null,"String_Node_Str"));
  assertEquals("String_Node_Str",c.getString("String_Node_Str",null,"String_Node_Str"));
  assertEquals("String_Node_Str",c.getString("String_Node_Str",null,"String_Node_Str"));
  c.save();
  final FileReader fr=new FileReader(cfg);
  final char[] cbuf=new char[configStr.length()];
  fr.read(cbuf);
  fr.close();
  assertEquals(configStr,new String(cbuf));
}

Fixed version (ground truth):
public void test006_ReadUglyConfig() throws IOException, ConfigInvalidException {
  final File cfg=new File(db.getDirectory(),"String_Node_Str");
  final FileBasedConfig c=new FileBasedConfig(cfg,db.getFS());
  final FileWriter pw=new FileWriter(cfg);
  final String configStr="String_Node_Str" + "String_Node_Str" + "String_Node_Str"+ "String_Node_Str"+ "String_Node_Str"+ "String_Node_Str";
  pw.write(configStr);
  pw.close();
  c.load();
  assertEquals("String_Node_Str",c.getString("String_Node_Str",null,"String_Node_Str"));
  assertEquals("String_Node_Str",c.getString("String_Node_Str",null,"String_Node_Str"));
  assertEquals("String_Node_Str",c.getString("String_Node_Str",null,"String_Node_Str"));
  assertEquals("String_Node_Str",c.getString("String_Node_Str",null,"String_Node_Str"));
  c.save();
  final FileReader fr=new FileReader(cfg);
  final char[] cbuf=new char[configStr.length()];
  fr.read(cbuf);
  fr.close();
  assertEquals(configStr,new String(cbuf));
}
Program: 91371
Project: 91371
Buggy source:
/** 
 * Try to establish an update lock on the cache file.
 * @return true if the lock is now held by the caller; false if it is heldby someone else.
 * @throws IOException the output file could not be created. The caller does not hold the lock.
 */
public boolean lock() throws IOException {
  if (liveFile == null)   throw new IOException(JGitText.get().dirCacheDoesNotHaveABackingFile);
  final LockFile tmp=new LockFile(liveFile);
  if (tmp.lock()) {
    tmp.setNeedStatInformation(true);
    myLock=tmp;
    return true;
  }
  return false;
}

Fixed version (ground truth):
/** 
 * Try to establish an update lock on the cache file.
 * @return true if the lock is now held by the caller; false if it is heldby someone else.
 * @throws IOException the output file could not be created. The caller does not hold the lock.
 */
public boolean lock() throws IOException {
  if (liveFile == null)   throw new IOException(JGitText.get().dirCacheDoesNotHaveABackingFile);
  final LockFile tmp=new LockFile(liveFile,fs);
  if (tmp.lock()) {
    tmp.setNeedStatInformation(true);
    myLock=tmp;
    return true;
  }
  return false;
}
Program: 91372
Project: 91372
Buggy source:
/** 
 * Create a new empty index which is never stored on disk.
 * @return an empty cache which has no backing store file. The cache may notbe read or written, but it may be queried and updated (in memory).
 */
public static DirCache newInCore(){
  return new DirCache(null);
}

Fixed version (ground truth):
/** 
 * Create a new empty index which is never stored on disk.
 * @return an empty cache which has no backing store file. The cache may notbe read or written, but it may be queried and updated (in memory).
 */
public static DirCache newInCore(){
  return new DirCache(null,null);
}
Program: 91373
Project: 91373
Buggy source:
/** 
 * Create a new in-core index representation. <p> The new index will be empty. Callers may wish to read from the on disk file first with   {@link #read()}.
 * @param indexLocation location of the index file on disk.
 */
public DirCache(final File indexLocation){
  liveFile=indexLocation;
  clear();
}

Fixed version (ground truth):
/** 
 * Create a new in-core index representation. <p> The new index will be empty. Callers may wish to read from the on disk file first with   {@link #read()}.
 * @param indexLocation location of the index file on disk.
 * @param fs the file system abstraction which will be necessary to perform certain file system operations.
 */
public DirCache(final File indexLocation,final FS fs){
  liveFile=indexLocation;
  this.fs=fs;
  clear();
}
Program: 91374
Project: 91374
Buggy source:
/** 
 * Parse and load the repository specific configuration. <p> The default implementation reads   {@code gitDir/config}, or returns an empty configuration if gitDir was not set.
 * @return the repository's configuration.
 * @throws IOException the configuration is not available.
 */
protected Config loadConfig() throws IOException {
  if (getGitDir() != null) {
    File path=safeFS().resolve(getGitDir(),"String_Node_Str");
    FileBasedConfig cfg=new FileBasedConfig(path);
    try {
      cfg.load();
    }
 catch (    ConfigInvalidException err) {
      throw new IllegalArgumentException(MessageFormat.format(JGitText.get().repositoryConfigFileInvalid,path.getAbsolutePath(),err.getMessage()));
    }
    return cfg;
  }
 else {
    return new Config();
  }
}

Fixed version (ground truth):
/** 
 * Parse and load the repository specific configuration. <p> The default implementation reads   {@code gitDir/config}, or returns an empty configuration if gitDir was not set.
 * @return the repository's configuration.
 * @throws IOException the configuration is not available.
 */
protected Config loadConfig() throws IOException {
  if (getGitDir() != null) {
    File path=safeFS().resolve(getGitDir(),"String_Node_Str");
    FileBasedConfig cfg=new FileBasedConfig(path,safeFS());
    try {
      cfg.load();
    }
 catch (    ConfigInvalidException err) {
      throw new IllegalArgumentException(MessageFormat.format(JGitText.get().repositoryConfigFileInvalid,path.getAbsolutePath(),err.getMessage()));
    }
    return cfg;
  }
 else {
    return new Config();
  }
}
Program: 91375
Project: 91375
Buggy source:
/** 
 * Create a new in-core index representation, lock it, and read from disk. <p> The new index will be locked and then read before it is returned to the caller. Read failures are reported as exceptions and therefore prevent the method from returning a partially populated index.
 * @return a cache representing the contents of the specified index file (ifit exists) or an empty cache if the file does not exist.
 * @throws NoWorkTreeException if this is bare, which implies it has no working directory. See  {@link #isBare()}.
 * @throws IOException the index file is present but could not be read, or the lock could not be obtained.
 * @throws CorruptObjectException the index file is using a format or extension that this library does not support.
 */
public DirCache lockDirCache() throws NoWorkTreeException, CorruptObjectException, IOException {
  return DirCache.lock(getIndexFile());
}

Fixed version (ground truth):
/** 
 * Create a new in-core index representation, lock it, and read from disk. <p> The new index will be locked and then read before it is returned to the caller. Read failures are reported as exceptions and therefore prevent the method from returning a partially populated index.
 * @return a cache representing the contents of the specified index file (ifit exists) or an empty cache if the file does not exist.
 * @throws NoWorkTreeException if this is bare, which implies it has no working directory. See  {@link #isBare()}.
 * @throws IOException the index file is present but could not be read, or the lock could not be obtained.
 * @throws CorruptObjectException the index file is using a format or extension that this library does not support.
 */
public DirCache lockDirCache() throws NoWorkTreeException, CorruptObjectException, IOException {
  return DirCache.lock(getIndexFile(),getFS());
}
Program: 91376
Project: 91376
Buggy source:
/** 
 * Create a new in-core index representation and read an index from disk. <p> The new index will be read before it is returned to the caller. Read failures are reported as exceptions and therefore prevent the method from returning a partially populated index.
 * @return a cache representing the contents of the specified index file (ifit exists) or an empty cache if the file does not exist.
 * @throws NoWorkTreeException if this is bare, which implies it has no working directory. See  {@link #isBare()}.
 * @throws IOException the index file is present but could not be read.
 * @throws CorruptObjectException the index file is using a format or extension that this library does not support.
 */
public DirCache readDirCache() throws NoWorkTreeException, CorruptObjectException, IOException {
  return DirCache.read(getIndexFile());
}

Fixed version (ground truth):
/** 
 * Create a new in-core index representation and read an index from disk. <p> The new index will be read before it is returned to the caller. Read failures are reported as exceptions and therefore prevent the method from returning a partially populated index.
 * @return a cache representing the contents of the specified index file (ifit exists) or an empty cache if the file does not exist.
 * @throws NoWorkTreeException if this is bare, which implies it has no working directory. See  {@link #isBare()}.
 * @throws IOException the index file is present but could not be read.
 * @throws CorruptObjectException the index file is using a format or extension that this library does not support.
 */
public DirCache readDirCache() throws NoWorkTreeException, CorruptObjectException, IOException {
  return DirCache.read(getIndexFile(),getFS());
}
Program: 91377
Project: 91377
Buggy source:
int score(SimilarityIndex dst){
  long max=Math.max(fileSize,dst.fileSize);
  return (int)((common(dst) * 100L) / max);
}

Fixed version (ground truth):
int score(SimilarityIndex dst){
  long max=Math.max(fileSize,dst.fileSize);
  if (max == 0)   return 100;
  return (int)((common(dst) * 100L) / max);
}
Program: 91378
Project: 91378
Buggy source:
private void sendPack() throws IOException {
  final boolean thin=options.contains(OPTION_THIN_PACK);
  final boolean progress=!options.contains(OPTION_NO_PROGRESS);
  final boolean sideband=options.contains(OPTION_SIDE_BAND) || options.contains(OPTION_SIDE_BAND_64K);
  ProgressMonitor pm=NullProgressMonitor.INSTANCE;
  OutputStream packOut=rawOut;
  if (sideband) {
    int bufsz=SideBandOutputStream.SMALL_BUF;
    if (options.contains(OPTION_SIDE_BAND_64K))     bufsz=SideBandOutputStream.MAX_BUF;
    packOut=new SideBandOutputStream(SideBandOutputStream.CH_DATA,bufsz,rawOut);
    if (progress)     pm=new SideBandProgressMonitor(new SideBandOutputStream(SideBandOutputStream.CH_PROGRESS,bufsz,rawOut));
  }
  final PackWriter pw;
  pw=new PackWriter(db);
  try {
    pw.setDeltaBaseAsOffset(options.contains(OPTION_OFS_DELTA));
    pw.setThin(thin);
    pw.preparePack(pm,wantAll,commonBase);
    if (options.contains(OPTION_INCLUDE_TAG)) {
      for (      final Ref r : refs.values()) {
        final RevObject o;
        try {
          o=walk.parseAny(r.getObjectId());
        }
 catch (        IOException e) {
          continue;
        }
        if (o.has(WANT) || !(o instanceof RevTag))         continue;
        final RevTag t=(RevTag)o;
        if (!pw.willInclude(t) && pw.willInclude(t.getObject()))         pw.addObject(t);
      }
    }
    pw.writePack(pm,NullProgressMonitor.INSTANCE,packOut);
  }
  finally {
    pw.release();
  }
  packOut.flush();
  if (sideband)   pckOut.end();
}

Fixed version (ground truth):
private void sendPack() throws IOException {
  final boolean thin=options.contains(OPTION_THIN_PACK);
  final boolean progress=!options.contains(OPTION_NO_PROGRESS);
  final boolean sideband=options.contains(OPTION_SIDE_BAND) || options.contains(OPTION_SIDE_BAND_64K);
  ProgressMonitor pm=NullProgressMonitor.INSTANCE;
  OutputStream packOut=rawOut;
  if (sideband) {
    int bufsz=SideBandOutputStream.SMALL_BUF;
    if (options.contains(OPTION_SIDE_BAND_64K))     bufsz=SideBandOutputStream.MAX_BUF;
    packOut=new SideBandOutputStream(SideBandOutputStream.CH_DATA,bufsz,rawOut);
    if (progress)     pm=new SideBandProgressMonitor(new SideBandOutputStream(SideBandOutputStream.CH_PROGRESS,bufsz,rawOut));
  }
  final PackWriter pw=new PackWriter(db);
  try {
    pw.setDeltaBaseAsOffset(options.contains(OPTION_OFS_DELTA));
    pw.setThin(thin);
    pw.preparePack(pm,wantAll,commonBase);
    if (options.contains(OPTION_INCLUDE_TAG)) {
      for (      final Ref r : refs.values()) {
        final RevObject o;
        try {
          o=walk.parseAny(r.getObjectId());
        }
 catch (        IOException e) {
          continue;
        }
        if (o.has(WANT) || !(o instanceof RevTag))         continue;
        final RevTag t=(RevTag)o;
        if (!pw.willInclude(t) && pw.willInclude(t.getObject()))         pw.addObject(t);
      }
    }
    pw.writePack(pm,NullProgressMonitor.INSTANCE,packOut);
  }
  finally {
    pw.release();
  }
  packOut.flush();
  if (sideband)   pckOut.end();
}
Program: 91379
Project: 91379
Buggy source:
@Override public void close(){
  endOut();
  if (errorThread != null) {
    try {
      errorThread.join();
    }
 catch (    InterruptedException e) {
    }
 finally {
      errorThread=null;
    }
  }
  super.close();
  if (channel != null) {
    try {
      exitStatus=channel.getExitStatus();
      if (channel.isConnected())       channel.disconnect();
    }
  finally {
      channel=null;
    }
  }
}

Fixed version (ground truth):
@Override public void close(){
  endOut();
  if (errorThread != null) {
    try {
      errorThread.halt();
    }
 catch (    InterruptedException e) {
    }
 finally {
      errorThread=null;
    }
  }
  super.close();
  if (channel != null) {
    try {
      exitStatus=channel.getExitStatus();
      if (channel.isConnected())       channel.disconnect();
    }
  finally {
      channel=null;
    }
  }
}
Program: 91380
Project: 91380
Buggy source:
@Override public void run(){
  try {
    final byte[] buf=new byte[BUFFER_SIZE];
    for (; ; ) {
      try {
        if (needFlush())         dst.flush();
        final int n;
        try {
          n=src.read(buf);
        }
 catch (        InterruptedIOException wakey) {
          continue;
        }
        if (n < 0)         break;
        for (; ; ) {
          try {
            dst.write(buf,0,n);
          }
 catch (          InterruptedIOException wakey) {
            continue;
          }
          break;
        }
      }
 catch (      IOException e) {
        break;
      }
    }
  }
  finally {
    try {
      src.close();
    }
 catch (    IOException e) {
    }
    try {
      dst.close();
    }
 catch (    IOException e) {
    }
  }
}

Fixed version (ground truth):
@Override public void run(){
  try {
    final byte[] buf=new byte[BUFFER_SIZE];
    for (; ; ) {
      try {
        if (needFlush())         dst.flush();
        if (done)         break;
        final int n;
        try {
          n=src.read(buf);
        }
 catch (        InterruptedIOException wakey) {
          continue;
        }
        if (n < 0)         break;
        for (; ; ) {
          try {
            dst.write(buf,0,n);
          }
 catch (          InterruptedIOException wakey) {
            continue;
          }
          break;
        }
      }
 catch (      IOException e) {
        break;
      }
    }
  }
  finally {
    try {
      src.close();
    }
 catch (    IOException e) {
    }
    try {
      dst.close();
    }
 catch (    IOException e) {
    }
  }
}
Program: 91381
Project: 91381
Buggy source:
@SuppressWarnings("String_Node_Str") @Override public <T>T generateValue(){
  return (T)dateFormat.format(dateFunction.generateValue());
}

Fixed version (ground truth):
@SuppressWarnings("String_Node_Str") @Override public <T>T generateValue(){
  Calendar date=dateFunction.generateValue();
  return (T)dateFormat.format(date.getTime());
}
Program: 91382
Project: 91382
Buggy source:
public DateAsStringFunction(DateFunction dateFunction,String pattern){
  this.dateFunction=dateFunction;
  dateFormat=new SimpleDateFormat(pattern);
}

Fixed version (ground truth):
public DateAsStringFunction(AtomicFunction dateFunction,String pattern){
  this.dateFunction=dateFunction;
  dateFormat=new SimpleDateFormat(pattern);
}
Program: 91383
Project: 91383
Buggy source:
@Test public void shouldFormatDateWithGivenPattern() throws ParseException {
  String dateString="String_Node_Str";
  String pattern="String_Node_Str";
  SimpleDateFormat dateFormat=new SimpleDateFormat(pattern);
  Date date=dateFormat.parse(dateString);
  DateFunction dateFunction=mock(DateFunction.class);
  when(dateFunction.generateValue()).thenReturn(date);
  DateAsStringFunction dateAsStringFunction=new DateAsStringFunction(dateFunction,pattern);
  assertEquals(dateString,dateAsStringFunction.generateValue());
}

Fixed version (ground truth):
@Test public void shouldFormatDateWithGivenPattern() throws ParseException {
  String dateString="String_Node_Str";
  String pattern="String_Node_Str";
  SimpleDateFormat dateFormat=new SimpleDateFormat(pattern);
  Calendar date=Calendar.getInstance();
  date.setTime(dateFormat.parse(dateString));
  DateFunction dateFunction=mock(DateFunction.class);
  when(dateFunction.generateValue()).thenReturn(date);
  DateAsStringFunction dateAsStringFunction=new DateAsStringFunction(dateFunction,pattern);
  assertEquals(dateString,dateAsStringFunction.generateValue());
}
Program: 91384
Project: 91384
Buggy source:
public static Field invokeRecursiveField(Class<?> clazz,String attribute){
  Field field=null;
  Class<?> superClass=null;
  Class<?> targetBeanClass=getTargetClass(clazz);
  for (  String propertyItem : attribute.split("String_Node_Str")) {
    do {
      superClass=targetBeanClass.getSuperclass();
      try {
        field=targetBeanClass.getDeclaredField(propertyItem);
        targetBeanClass=field.getType();
      }
 catch (      NoSuchFieldException e) {
        targetBeanClass=superClass;
      }
    }
 while (superClass != null && !superClass.equals(Object.class));
  }
  if (field == null) {
    throw new IllegalArgumentException(String.format("String_Node_Str",clazz.getName(),attribute));
  }
  return field;
}

Fixed version (ground truth):
public static Field invokeRecursiveField(Class<?> clazz,String attribute){
  Field field=null;
  Class<?> targetBeanClass=getTargetClass(clazz);
  for (  String propertyItem : attribute.split("String_Node_Str")) {
    field=new Mirror().on(targetBeanClass).reflect().field(propertyItem);
    if (field == null)     throw new IllegalArgumentException(String.format("String_Node_Str",clazz.getName(),attribute));
    targetBeanClass=field.getType();
  }
  return field;
}
Program: 91385
Project: 91385
Buggy source:
@Override @SuppressWarnings("String_Node_Str") public <T>T generateValue(){
  RandomFunction random=new RandomFunction(Integer.class,new Range(1,9));
  int a=random.generateValue();
  int b=random.generateValue();
  int c=random.generateValue();
  int d=random.generateValue();
  int e=random.generateValue();
  int f=random.generateValue();
  int g=random.generateValue();
  int h=random.generateValue();
  int i=random.generateValue();
  int j=(a * 10 + b * 9 + c * 8 + d * 7 + e * 6 + f * 5 + g * 4 + h * 3 + i * 2);
  j=j % 11;
  j=j <= 1 ? 0 : 11 - j;
  int m=(a * 11 + b * 10 + c * 9 + d * 8 + e * 7 + f * 6 + g * 5 + h * 4 + i * 3 + j * 2);
  m=m % 11;
  m=m <= 1 ? 0 : 11 - m;
  return (T)String.format(formatted ? "String_Node_Str" : "String_Node_Str",a,b,c,d,e,f,g,h,i,j,m);
}

Fixed version (ground truth):
@Override @SuppressWarnings("String_Node_Str") public <T>T generateValue(){
  RandomFunction random=new RandomFunction(Integer.class,new Range(1,9));
  Integer a=random.generateValue();
  Integer b=random.generateValue();
  Integer c=random.generateValue();
  Integer d=random.generateValue();
  Integer e=random.generateValue();
  Integer f=random.generateValue();
  Integer g=random.generateValue();
  Integer h=random.generateValue();
  Integer i=random.generateValue();
  Integer j=(a * 10 + b * 9 + c * 8 + d * 7 + e * 6 + f * 5 + g * 4 + h * 3 + i * 2);
  j=j % 11;
  j=j <= 1 ? 0 : 11 - j;
  Integer m=(a * 11 + b * 10 + c * 9 + d * 8 + e * 7 + f * 6 + g * 5 + h * 4 + i * 3 + j * 2);
  m=m % 11;
  m=m <= 1 ? 0 : 11 - m;
  return (T)String.format(formatted ? "String_Node_Str" : "String_Node_Str",a,b,c,d,e,f,g,h,i,j,m);
}
Program: 91386
Project: 91386
Buggy source:
public static Class<?> invokeRecursiveType(Object bean,String attribute){
  return invokeRecursiveType(getTargetClass(bean.getClass()),attribute);
}

Fixed version (ground truth):
public static Class<?> invokeRecursiveType(Object bean,String attribute){
  Field field=invokeRecursiveField(bean,attribute);
  return field.getType();
}
Program: 91387
Project: 91387
Buggy source:
private static Object prepareInvokeRecursiveSetter(Object bean,String attribute,Object value){
  Object targetBean=bean;
  Object lastBean=null;
  int lastAttributeIdx=attribute.lastIndexOf("String_Node_Str");
  String path=null;
  if (lastAttributeIdx > 0) {
    path=StringUtils.defaultIfEmpty(attribute.substring(0,lastAttributeIdx),null);
  }
  if (path != null) {
    for (    String propertyItem : path.split("String_Node_Str")) {
      lastBean=targetBean;
      targetBean=ReflectionUtils.invokeGetter(targetBean,propertyItem);
      if (targetBean == null) {
        try {
          targetBean=newInstance(invokeRecursiveType(lastBean.getClass(),propertyItem));
          ReflectionUtils.invokeSetter(lastBean,propertyItem,targetBean,true);
        }
 catch (        Exception e) {
          throw new IllegalArgumentException("String_Node_Str" + propertyItem + "String_Node_Str"+ lastBean.getClass().getCanonicalName());
        }
      }
    }
  }
  return targetBean;
}

Fixed version (ground truth):
private static Object prepareInvokeRecursiveSetter(Object bean,String attribute,Object value){
  Object targetBean=bean;
  Object lastBean=null;
  int lastAttributeIdx=attribute.lastIndexOf("String_Node_Str");
  String path=null;
  if (lastAttributeIdx > 0) {
    path=StringUtils.defaultIfEmpty(attribute.substring(0,lastAttributeIdx),null);
  }
  if (path != null) {
    for (    String propertyItem : path.split("String_Node_Str")) {
      lastBean=targetBean;
      targetBean=ReflectionUtils.invokeGetter(targetBean,propertyItem);
      if (targetBean == null) {
        try {
          targetBean=newInstance(invokeRecursiveType(lastBean,propertyItem));
          ReflectionUtils.invokeSetter(lastBean,propertyItem,targetBean,true);
        }
 catch (        Exception e) {
          throw new IllegalArgumentException("String_Node_Str" + propertyItem + "String_Node_Str"+ lastBean.getClass().getCanonicalName());
        }
      }
    }
  }
  return targetBean;
}
Program: 91388
Project: 91388
Buggy source:
/** 
 * @param resource  the resource to request
 * @param args      optional string expansion arguments (passed to String#format(String, Object...)
 * @throws java.util.IllegalFormatException - If a format string contains an illegal syntax,
 * @return the request
 * @see String#format(String,Object)
 */
public static Request to(String resource,Object... args){
  if (args != null && args.length > 0) {
    resource=String.format(resource,args);
  }
  return new Request(resource);
}

Fixed version (ground truth):
/** 
 * @param resource  the resource to request
 * @param args      optional string expansion arguments (passed to String#format(String, Object...)
 * @throws java.util.IllegalFormatException - If a format string contains an illegal syntax,
 * @return the request
 * @see String#format(String,Object)
 */
public static Request to(String resource,Object... args){
  if (args != null && args.length > 0) {
    resource=String.format(Locale.ENGLISH,resource,args);
  }
  return new Request(resource);
}
Program: 91389
Project: 91389
Buggy source:
@Override public void resourceChanged(IResourceChangeEvent event){
  Set<IResource> resources=new HashSet<>();
  IMarkerDelta[] markerDeltas=event.findMarkerDeltas(IMarker.PROBLEM,true);
  for (  IMarkerDelta delta : markerDeltas) {
    IResource resource=delta.getResource();
    while (resource.getType() != IResource.ROOT && resources.add(resource)) {
      resource=resource.getParent();
    }
  }
  if (!resources.isEmpty()) {
    updateLabels(resources);
  }
}

Fixed version (ground truth):
@Override public void resourceChanged(IResourceChangeEvent event){
  Set<IPath> paths=new HashSet<>();
  IMarkerDelta[] markerDeltas=event.findMarkerDeltas(IMarker.PROBLEM,true);
  for (  IMarkerDelta delta : markerDeltas) {
    IResource resource=delta.getResource();
    if (resource == null) {
      continue;
    }
    RepositoryMapping mapping=RepositoryMapping.getMapping(resource);
    if (mapping == null || mapping.getRepository().isBare()) {
      continue;
    }
    IPath path=resource.getLocation();
    if (path == null) {
      continue;
    }
    File workTree=mapping.getWorkTree();
    if (workTree == null) {
      continue;
    }
    int n=new Path(workTree.getAbsolutePath()).segmentCount();
    for (int i=path.segmentCount(); i > n; i--) {
      paths.add(path);
      path=path.removeLastSegments(1);
    }
  }
  if (!paths.isEmpty()) {
    updateLabels(paths);
  }
}
Program: 91390
Project: 91390
Buggy source:
private void updateLabels(Set<IResource> changedResources){
  List<Object> elements=getAffectedElements(changedResources);
  if (!elements.isEmpty()) {
    final Object[] updateElements=elements.toArray(new Object[elements.size()]);
    Display display=viewer.getControl().getDisplay();
    display.asyncExec(new Runnable(){
      @Override public void run(){
        fireLabelProviderChanged(new LabelProviderChangedEvent(ProblemLabelDecorator.this,updateElements));
      }
    }
);
  }
}

Fixed version (ground truth):
private void updateLabels(Set<IPath> changedPaths){
  List<Object> elements=getAffectedElements(changedPaths);
  if (!elements.isEmpty()) {
    final Object[] updateElements=elements.toArray(new Object[elements.size()]);
    Display display=viewer.getControl().getDisplay();
    display.asyncExec(new Runnable(){
      @Override public void run(){
        fireLabelProviderChanged(new LabelProviderChangedEvent(ProblemLabelDecorator.this,updateElements));
      }
    }
);
  }
}
Program: 91391
Project: 91391
Buggy source:
private void getAffectedElements(Set<IResource> resources,Object[] elements,IStructuredContentProvider contentProvider,List<Object> result){
  for (  Object element : elements) {
    IResource resource=AdapterUtils.adapt(element,IResource.class);
    if (resource != null && resources.contains(resource)) {
      result.add(element);
      if (contentProvider instanceof ITreeContentProvider) {
        getAffectedElements(resources,((ITreeContentProvider)contentProvider).getChildren(element),contentProvider,result);
      }
    }
  }
}

Fixed version (ground truth):
private void getAffectedElements(Set<IPath> paths,Object[] elements,IStructuredContentProvider contentProvider,List<Object> result){
  for (  Object element : elements) {
    IPath path=AdapterUtils.adapt(element,IPath.class);
    if (path == null) {
      IResource resource=AdapterUtils.adapt(element,IResource.class);
      if (resource != null) {
        path=resource.getLocation();
      }
    }
    if (path != null && paths.contains(path)) {
      result.add(element);
      if (contentProvider instanceof ITreeContentProvider) {
        getAffectedElements(paths,((ITreeContentProvider)contentProvider).getChildren(element),contentProvider,result);
      }
    }
  }
}
Program: 91393
Project: 91393
Buggy source:
@Override public IStatus runInWorkspace(IProgressMonitor monitor){
  try {
    SubMonitor progress=SubMonitor.convert(monitor,UIText.FetchGerritChangePage_GetChangeTaskName,getTotalWork(mode));
    RevCommit commit=fetchChange(uri,spec,progress.newChild(1));
switch (mode) {
case CHECKOUT_FETCH_HEAD:
      checkout(commit.name(),progress.newChild(1));
    break;
case CREATE_TAG:
  createTag(spec,textForTag,commit,progress.newChild(1));
checkout(commit.name(),progress.newChild(1));
break;
case CREATE_BRANCH:
createBranch(textForBranch,doCheckoutNewBranch,commit,progress.newChild(1));
break;
default :
}
if (doActivateAdditionalRefs) {
activateAdditionalRefs();
}
if (mode == CheckoutMode.NOCHECKOUT) {
repository.fireEvent(new FetchHeadChangedEvent());
}
storeLastUsedUri(uri);
}
 catch (CoreException ce) {
return ce.getStatus();
}
catch (Exception e) {
return Activator.createErrorStatus(e.getLocalizedMessage(),e);
}
 finally {
monitor.done();
}
return Status.OK_STATUS;
}

Fixed version (ground truth):
@Override public IStatus runInWorkspace(IProgressMonitor monitor){
  try {
    SubMonitor progress=SubMonitor.convert(monitor,UIText.FetchGerritChangePage_GetChangeTaskName,getTotalWork(mode));
    RevCommit commit=fetchChange(uri,spec,progress.newChild(1));
switch (mode) {
case CHECKOUT_FETCH_HEAD:
      checkout(commit.name(),progress.newChild(1));
    break;
case CREATE_TAG:
  createTag(spec,textForTag,commit,progress.newChild(1));
checkout(commit.name(),progress.newChild(1));
break;
case CREATE_BRANCH:
createBranch(textForBranch,doCheckoutNewBranch,commit,progress.newChild(1));
break;
default :
break;
}
if (doActivateAdditionalRefs) {
activateAdditionalRefs();
}
if (mode == CheckoutMode.NOCHECKOUT) {
repository.fireEvent(new FetchHeadChangedEvent());
}
storeLastUsedUri(uri);
}
 catch (CoreException ce) {
return ce.getStatus();
}
catch (Exception e) {
return Activator.createErrorStatus(e.getLocalizedMessage(),e);
}
 finally {
monitor.done();
}
return Status.OK_STATUS;
}
Program: 91394
Project: 91394
Buggy source:
@Test public void testRebaseFailOnDirtyWorkingDirectory() throws Exception {
  ErrorDialog.AUTOMATED_MODE=false;
  Git git=Git.wrap(repository);
  init();
  setContentAddAndCommit("String_Node_Str");
  createFeature(FEATURE_NAME);
  setContentAddAndCommit("String_Node_Str");
  setTestFileContent("String_Node_Str");
  rebaseFeature();
  acceptError(RebaseResult.Status.UNCOMMITTED_CHANGES);
  Status status=git.status().call();
  Object[] uncommitted=status.getUncommittedChanges().toArray();
  assertEquals(1,uncommitted.length);
  assertEquals(FILE1_PATH,uncommitted[0]);
}

Fixed version (ground truth):
@Test public void testRebaseFailOnDirtyWorkingDirectory() throws Exception {
  disableAutomatedMode();
  Git git=Git.wrap(repository);
  init();
  setContentAddAndCommit("String_Node_Str");
  createFeature(FEATURE_NAME);
  setContentAddAndCommit("String_Node_Str");
  setTestFileContent("String_Node_Str");
  rebaseFeature();
  acceptError(RebaseResult.Status.UNCOMMITTED_CHANGES);
  Status status=git.status().call();
  Object[] uncommitted=status.getUncommittedChanges().toArray();
  assertEquals(1,uncommitted.length);
  assertEquals(FILE1_PATH,uncommitted[0]);
}
Program: 91395
Project: 91395
Buggy source:
@Test public void testRebaseFailOnConflict() throws Exception {
  ErrorDialog.AUTOMATED_MODE=false;
  Git git=Git.wrap(repository);
  init();
  createFeature(FEATURE_NAME);
  setContentAddAndCommit("String_Node_Str");
  checkoutBranch(DEVELOP);
  setContentAddAndCommit("String_Node_Str");
  checkoutFeature(FEATURE_NAME);
  rebaseFeature();
  acceptError(RebaseResult.Status.STOPPED);
  Status status=git.status().call();
  Object[] conflicting=status.getConflicting().toArray();
  assertEquals(1,conflicting.length);
  assertEquals(FILE1_PATH,conflicting[0]);
  assertEquals("String_Node_Str",bot.activeView().getReference().getId());
}

Fixed version (ground truth):
@Test public void testRebaseFailOnConflict() throws Exception {
  disableAutomatedMode();
  Git git=Git.wrap(repository);
  init();
  createFeature(FEATURE_NAME);
  setContentAddAndCommit("String_Node_Str");
  checkoutBranch(DEVELOP);
  setContentAddAndCommit("String_Node_Str");
  checkoutFeature(FEATURE_NAME);
  rebaseFeature();
  acceptError(RebaseResult.Status.STOPPED);
  Status status=git.status().call();
  Object[] conflicting=status.getConflicting().toArray();
  assertEquals(1,conflicting.length);
  assertEquals(FILE1_PATH,conflicting[0]);
  assertEquals("String_Node_Str",bot.activeView().getReference().getId());
}
Program: 91396
Project: 91396
Buggy source:
/** 
 * Draw the overlays for the receiver.
 * @param overlaysArray
 */
private void drawOverlays(ImageDescriptor[] overlaysArray){
  for (int i=0; i < overlays.length; i++) {
    ImageDescriptor overlay=overlaysArray[i];
    if (overlay == null)     continue;
    ImageData overlayData=overlay.getImageData();
    if (overlayData == null)     overlayData=ImageDescriptor.getMissingImageDescriptor().getImageData();
switch (i) {
case IDecoration.TOP_LEFT:
      drawImage(overlayData,0,0);
    break;
case IDecoration.TOP_RIGHT:
  drawImage(overlayData,size.x - overlayData.width,0);
break;
case IDecoration.BOTTOM_LEFT:
drawImage(overlayData,0,size.y - overlayData.height);
break;
case IDecoration.BOTTOM_RIGHT:
drawImage(overlayData,size.x - overlayData.width,size.y - overlayData.height);
break;
}
}
}

Fixed version (ground truth):
/** 
 * Draw the overlays for the receiver.
 * @param overlaysArray
 */
private void drawOverlays(ImageDescriptor[] overlaysArray){
  for (int i=0; i < overlays.length; i++) {
    ImageDescriptor overlay=overlaysArray[i];
    if (overlay == null)     continue;
    ImageData overlayData=overlay.getImageData();
    if (overlayData == null)     overlayData=ImageDescriptor.getMissingImageDescriptor().getImageData();
switch (i) {
case IDecoration.TOP_LEFT:
      drawImage(overlayData,0,0);
    break;
case IDecoration.TOP_RIGHT:
  drawImage(overlayData,size.x - overlayData.width,0);
break;
case IDecoration.BOTTOM_LEFT:
drawImage(overlayData,0,size.y - overlayData.height);
break;
case IDecoration.BOTTOM_RIGHT:
drawImage(overlayData,size.x - overlayData.width,size.y - overlayData.height);
break;
default :
break;
}
}
}