Program: 5811
Project: 5811
Buggy source:
/** 
 * Updates the TTL in the   {@link co.cask.cdap.data2.datafabric.dataset.service.mds.DatasetInstanceMDS}table for CDAP versions prior to 3.3. <p> The TTL for   {@link DatasetSpecification} was stored in milliseconds.Since the spec (as of CDAP version 3.3) is in seconds, the instance MDS entries must be updated. This is to be called only if the current CDAP version is < 3.3. </p>
 * @throws Exception
 */
public void upgrade() throws Exception {
  TableId datasetSpecId=TableId.from(Id.Namespace.SYSTEM.getId(),DatasetMetaTableUtil.INSTANCE_TABLE_NAME);
  HBaseAdmin hBaseAdmin=new HBaseAdmin(conf);
  if (!tableUtil.tableExists(hBaseAdmin,datasetSpecId)) {
    LOG.error("String_Node_Str",datasetSpecId);
    return;
  }
  HTable specTable=tableUtil.createHTable(conf,datasetSpecId);
  try {
    ScanBuilder scanBuilder=tableUtil.buildScan();
    scanBuilder.setTimeRange(0,HConstants.LATEST_TIMESTAMP);
    scanBuilder.setMaxVersions();
    try (ResultScanner resultScanner=specTable.getScanner(scanBuilder.build())){
      Result result;
      while ((result=resultScanner.next()) != null) {
        Put put=new Put(result.getRow());
        for (        Map.Entry<byte[],NavigableMap<byte[],NavigableMap<Long,byte[]>>> familyMap : result.getMap().entrySet()) {
          for (          Map.Entry<byte[],NavigableMap<Long,byte[]>> columnMap : familyMap.getValue().entrySet()) {
            for (            Map.Entry<Long,byte[]> columnEntry : columnMap.getValue().entrySet()) {
              Long timeStamp=columnEntry.getKey();
              byte[] colVal=columnEntry.getValue();
              if (colVal == null || colVal.length == 0) {
                continue;
              }
              String specEntry=Bytes.toString(colVal);
              DatasetSpecification specification=GSON.fromJson(specEntry,DatasetSpecification.class);
              DatasetSpecification updatedSpec=updateTTLInSpecification(specification,null);
              colVal=Bytes.toBytes(GSON.toJson(updatedSpec));
              put.add(familyMap.getKey(),columnMap.getKey(),timeStamp,colVal);
            }
          }
        }
        if (put.size() > 0) {
          specTable.put(put);
        }
      }
    }
   }
  finally {
    specTable.flushCommits();
    specTable.close();
  }
}

Fixed version (ground truth):
/** 
 * Updates the TTL in the   {@link co.cask.cdap.data2.datafabric.dataset.service.mds.DatasetInstanceMDS}table for CDAP versions prior to 3.3. <p> The TTL for   {@link DatasetSpecification} was stored in milliseconds.Since the spec (as of CDAP version 3.3) is in seconds, the instance MDS entries must be updated. This is to be called only if the current CDAP version is < 3.3. </p>
 * @throws Exception
 */
public void upgrade() throws Exception {
  TableId datasetSpecId=tableUtil.createHTableId(NamespaceId.SYSTEM,DatasetMetaTableUtil.INSTANCE_TABLE_NAME);
  HBaseAdmin hBaseAdmin=new HBaseAdmin(conf);
  if (!tableUtil.tableExists(hBaseAdmin,datasetSpecId)) {
    LOG.error("String_Node_Str",datasetSpecId);
    return;
  }
  HTable specTable=tableUtil.createHTable(conf,datasetSpecId);
  try {
    ScanBuilder scanBuilder=tableUtil.buildScan();
    scanBuilder.setTimeRange(0,HConstants.LATEST_TIMESTAMP);
    scanBuilder.setMaxVersions();
    try (ResultScanner resultScanner=specTable.getScanner(scanBuilder.build())){
      Result result;
      while ((result=resultScanner.next()) != null) {
        Put put=new Put(result.getRow());
        for (        Map.Entry<byte[],NavigableMap<byte[],NavigableMap<Long,byte[]>>> familyMap : result.getMap().entrySet()) {
          for (          Map.Entry<byte[],NavigableMap<Long,byte[]>> columnMap : familyMap.getValue().entrySet()) {
            for (            Map.Entry<Long,byte[]> columnEntry : columnMap.getValue().entrySet()) {
              Long timeStamp=columnEntry.getKey();
              byte[] colVal=columnEntry.getValue();
              if (colVal == null || colVal.length == 0) {
                continue;
              }
              String specEntry=Bytes.toString(colVal);
              DatasetSpecification specification=GSON.fromJson(specEntry,DatasetSpecification.class);
              DatasetSpecification updatedSpec=updateTTLInSpecification(specification,null);
              colVal=Bytes.toBytes(GSON.toJson(updatedSpec));
              put.add(familyMap.getKey(),columnMap.getKey(),timeStamp,colVal);
            }
          }
        }
        if (put.size() > 0) {
          specTable.put(put);
        }
      }
    }
   }
  finally {
    specTable.flushCommits();
    specTable.close();
  }
}