Program: 187108
Project: 187108
Buggy source:
@Test public void testGrib() throws FileNotFoundException, IOException {
  GribFile gribFile1=null;
  final File test_dir=TestData.file(GriBTest.class,"String_Node_Str");
  final File files[]=test_dir.listFiles(new FilenameFilter(){
    public boolean accept(    File dir,    String name){
      if (!new File(dir.getAbsolutePath() + File.separator + name).isDirectory() && (name.toLowerCase().endsWith("String_Node_Str") || name.toLowerCase().endsWith("String_Node_Str")))       return true;
      return false;
    }
  }
);
  final int length=files.length;
  for (int i=0; i < length; i++) {
    final StringBuilder buffer=new StringBuilder("String_Node_Str").append(files[i]).append("String_Node_Str");
    gribFile=GribFile.open(files[i],AccessType.R);
    gribFile.parseGribFile();
    final GribFile file=GribFile.open(null,AccessType.RW);
    final int recordCount=gribFile.getRecordCount();
    buffer.append("String_Node_Str").append(recordCount).append("String_Node_Str");
    LOGGER.info(buffer.toString());
    for (int j=1; j <= recordCount; j++) {
      LOGGER.info("String_Node_Str" + j);
      final GribRecord oldRecord=gribFile.getRecord(j);
      Assert.assertNotNull((oldRecord));
      final GribRecord record=new GribRecord();
      final GribRecordPDS oldPDS=oldRecord.getPDS();
      record.setPDS(new GribRecordPDS(oldPDS.getTableVersion(),oldPDS.getOriginatingCenterID(),oldPDS.getGeneratingProcessID(),oldPDS.getGridID(),true,oldPDS.bmsExists(),oldPDS.getParameter().getNumber(),oldPDS.getLevel().getIndex(),oldPDS.getLevel().getValue1(),oldPDS.getLevel().getValue2(),oldPDS.getGMTBaseTime(),oldPDS.getForecastTimeUnit(),oldPDS.getP1(),oldPDS.getP2(),oldPDS.getTimeRangeIndicator(),0,0,oldPDS.getSubcenterID(),oldPDS.getDecimalScale()));
      Assert.assertTrue(record.getPDS().equals(gribFile.getRecord(j).getPDS()));
      final GribRecordGDS oldGDS=oldRecord.getGDS();
      final GribRecordGDS gds=GribGDSFactory.getGDS(oldGDS.getGridType());
      gds.setGridType(oldGDS.getGridType());
      gds.setGridMode(oldGDS.getGridMode());
      gds.setLength(oldGDS.getLength());
      gds.setGridNX(oldGDS.getGridNX());
      gds.setGridNY(oldGDS.getGridNY());
      gds.setGridLat2(oldGDS.getGridLat2());
      gds.setGridLat1(oldGDS.getGridLat1());
      gds.setGridLon1(oldGDS.getGridLon1());
      gds.setGridLon2(oldGDS.getGridLon2());
      gds.setGridScanmode(oldGDS.getGridDX() > 0,oldGDS.getGridDY() > 0,oldGDS.isAdiacent_i_Or_j());
      gds.setGridDX(oldGDS.getGridDX());
      gds.setGridDY(oldGDS.getGridDY());
      gds.setGridMode(oldGDS.getGridMode());
      gds.setGridLatSP(oldGDS.getGridLatSP());
      gds.setGridLonSP(oldGDS.getGridLonSP());
      gds.setGridRotAngle(oldGDS.getGridRotAngle());
switch (oldGDS.getGridType()) {
case GribGDSRotatedLatLon.ROTATED_LATLON_GRID_TYPE:
        ((GribGDSRotatedLatLon)gds).setGridLatSPST(((GribGDSRotatedLatLon)oldGDS).getGridLatSPST());
      ((GribGDSRotatedLatLon)gds).setGridLonSPST(((GribGDSRotatedLatLon)oldGDS).getGridLonSPST());
    ((GribGDSRotatedLatLon)gds).setGridStretchingFactor(((GribGDSRotatedLatLon)oldGDS).getGridStretchingFactor());
  break;
case GribGDSPolarStereo.POLAR_STEREO_GRID_TYPE:
break;
case GribGDSLambert.LAMBERT_GRID_TYPE:
((GribGDSLambert)gds).setGridLatin1(((GribGDSLambert)oldGDS).getGridLatin1());
((GribGDSLambert)gds).setGridLatin2(((GribGDSLambert)oldGDS).getGridLatin2());
((GribGDSLambert)gds).setProjCenter(((GribGDSLambert)oldGDS).getProjCenter());
((GribGDSLambert)gds).setRhoRef(((GribGDSLambert)oldGDS).getRhoRef());
break;
default :
break;
}
record.setGDS(gds);
Assert.assertTrue(record.getGDS().equals(oldGDS));
final GribRecordBMS oldBMS=gribFile.getRecord(j).getBMS();
if (oldPDS.bmsExists()) {
record.setBMS(new GribRecordBMS(oldBMS.getBitmap()));
Assert.assertTrue(record.getBMS().equals(oldBMS));
}
final GribRecordBDS oldBDS=oldRecord.getBDS();
record.setBDS(new GribRecordBDS(oldPDS.getDecimalScale(),oldBDS.getNumBits(),oldBDS.getValues(),oldBDS.getIsConstant(),oldBDS.getMaxValue(),oldBDS.getMinValue(),oldBDS.getNumValidValues(),oldGDS,oldBMS));
Assert.assertTrue("String_Node_Str",record.getBDS().equals(gribFile.getRecord(j).getBDS()));
final GribRecordIS oldIS=oldRecord.getIS();
record.setIS(new GribRecordIS(oldIS.getGribEdition(),oldPDS.getLength(),oldGDS.getLength(),oldBMS == null ? 0 : oldBMS.getLength(),oldBDS.getLength()));
file.addRecord(record);
}
Assert.assertTrue(file.equals(gribFile));
final File tempFile=File.createTempFile("String_Node_Str","String_Node_Str");
tempFile.deleteOnExit();
final BufferedOutputStream out=new BufferedOutputStream(new FileOutputStream(tempFile),4096);
file.writeTo(out);
out.flush();
out.close();
gribFile1=GribFile.open(tempFile,AccessType.R);
gribFile1.parseGribFile();
if (!gribFile1.equals(gribFile)) {
LOGGER.severe("String_Node_Str" + files[i].getName());
throw new RuntimeException("String_Node_Str" + files[i].getName());
}
gribFile1.dispose();
gribFile1=null;
gribFile.dispose();
gribFile=null;
}
}

Fixed version (ground truth):
@Test public void testGrib() throws FileNotFoundException, IOException {
  GribFile gribFile1=null;
  final File test_dir=new File("String_Node_Str");
  final File files[]=test_dir.listFiles(new FilenameFilter(){
    public boolean accept(    File dir,    String name){
      if (!new File(dir.getAbsolutePath() + File.separator + name).isDirectory() && (name.toLowerCase().endsWith("String_Node_Str") || name.toLowerCase().endsWith("String_Node_Str")))       return true;
      return false;
    }
  }
);
  final int length=files.length;
  for (int i=0; i < length; i++) {
    final StringBuilder buffer=new StringBuilder("String_Node_Str").append(files[i]).append("String_Node_Str");
    gribFile=GribFile.open(files[i],AccessType.R);
    gribFile.parseGribFile();
    final GribFile file=GribFile.open(null,AccessType.RW);
    final int recordCount=gribFile.getRecordCount();
    buffer.append("String_Node_Str").append(recordCount).append("String_Node_Str");
    LOGGER.info(buffer.toString());
    for (int j=1; j <= recordCount; j++) {
      LOGGER.info("String_Node_Str" + j);
      final GribRecord oldRecord=gribFile.getRecord(j);
      Assert.assertNotNull((oldRecord));
      final GribRecord record=new GribRecord();
      final GribRecordPDS oldPDS=oldRecord.getPDS();
      record.setPDS(new GribRecordPDS(oldPDS.getTableVersion(),oldPDS.getOriginatingCenterID(),oldPDS.getGeneratingProcessID(),oldPDS.getGridID(),true,oldPDS.bmsExists(),oldPDS.getParameter().getNumber(),oldPDS.getLevel().getIndex(),oldPDS.getLevel().getValue1(),oldPDS.getLevel().getValue2(),oldPDS.getGMTBaseTime(),oldPDS.getForecastTimeUnit(),oldPDS.getP1(),oldPDS.getP2(),oldPDS.getTimeRangeIndicator(),0,0,oldPDS.getSubcenterID(),oldPDS.getDecimalScale()));
      Assert.assertTrue(record.getPDS().equals(gribFile.getRecord(j).getPDS()));
      final GribRecordGDS oldGDS=oldRecord.getGDS();
      final GribRecordGDS gds=GribGDSFactory.getGDS(oldGDS.getGridType());
      gds.setGridType(oldGDS.getGridType());
      gds.setGridMode(oldGDS.getGridMode());
      gds.setLength(oldGDS.getLength());
      gds.setGridNX(oldGDS.getGridNX());
      gds.setGridNY(oldGDS.getGridNY());
      gds.setGridLat2(oldGDS.getGridLat2());
      gds.setGridLat1(oldGDS.getGridLat1());
      gds.setGridLon1(oldGDS.getGridLon1());
      gds.setGridLon2(oldGDS.getGridLon2());
      gds.setGridScanmode(oldGDS.getGridDX() > 0,oldGDS.getGridDY() > 0,oldGDS.isAdiacent_i_Or_j());
      gds.setGridDX(oldGDS.getGridDX());
      gds.setGridDY(oldGDS.getGridDY());
      gds.setGridMode(oldGDS.getGridMode());
      gds.setGridLatSP(oldGDS.getGridLatSP());
      gds.setGridLonSP(oldGDS.getGridLonSP());
      gds.setGridRotAngle(oldGDS.getGridRotAngle());
switch (oldGDS.getGridType()) {
case GribGDSRotatedLatLon.ROTATED_LATLON_GRID_TYPE:
        ((GribGDSRotatedLatLon)gds).setGridLatSPST(((GribGDSRotatedLatLon)oldGDS).getGridLatSPST());
      ((GribGDSRotatedLatLon)gds).setGridLonSPST(((GribGDSRotatedLatLon)oldGDS).getGridLonSPST());
    ((GribGDSRotatedLatLon)gds).setGridStretchingFactor(((GribGDSRotatedLatLon)oldGDS).getGridStretchingFactor());
  break;
case GribGDSPolarStereo.POLAR_STEREO_GRID_TYPE:
break;
case GribGDSLambert.LAMBERT_GRID_TYPE:
((GribGDSLambert)gds).setGridLatin1(((GribGDSLambert)oldGDS).getGridLatin1());
((GribGDSLambert)gds).setGridLatin2(((GribGDSLambert)oldGDS).getGridLatin2());
((GribGDSLambert)gds).setProjCenter(((GribGDSLambert)oldGDS).getProjCenter());
((GribGDSLambert)gds).setRhoRef(((GribGDSLambert)oldGDS).getRhoRef());
break;
default :
break;
}
record.setGDS(gds);
Assert.assertTrue(record.getGDS().equals(oldGDS));
final GribRecordBMS oldBMS=gribFile.getRecord(j).getBMS();
if (oldPDS.bmsExists()) {
record.setBMS(new GribRecordBMS(oldBMS.getBitmap()));
Assert.assertTrue(record.getBMS().equals(oldBMS));
}
final GribRecordBDS oldBDS=oldRecord.getBDS();
record.setBDS(new GribRecordBDS(oldPDS.getDecimalScale(),oldBDS.getNumBits(),oldBDS.getValues(),oldBDS.getIsConstant(),oldBDS.getMaxValue(),oldBDS.getMinValue(),oldBDS.getNumValidValues(),oldGDS,oldBMS));
Assert.assertTrue("String_Node_Str",record.getBDS().equals(gribFile.getRecord(j).getBDS()));
final GribRecordIS oldIS=oldRecord.getIS();
record.setIS(new GribRecordIS(oldIS.getGribEdition(),oldPDS.getLength(),oldGDS.getLength(),oldBMS == null ? 0 : oldBMS.getLength(),oldBDS.getLength()));
file.addRecord(record);
}
Assert.assertTrue(file.equals(gribFile));
final File tempFile=File.createTempFile("String_Node_Str","String_Node_Str");
tempFile.deleteOnExit();
final BufferedOutputStream out=new BufferedOutputStream(new FileOutputStream(tempFile),4096);
file.writeTo(out);
out.flush();
out.close();
gribFile1=GribFile.open(tempFile,AccessType.R);
gribFile1.parseGribFile();
if (!gribFile1.equals(gribFile)) {
LOGGER.severe("String_Node_Str" + files[i].getName());
throw new RuntimeException("String_Node_Str" + files[i].getName());
}
gribFile1.dispose();
gribFile1=null;
gribFile.dispose();
gribFile=null;
}
}