Program: 52894
Project: 52894
Buggy source:
/** 
 * @param rawFile
 * @param outputFolder
 * @return //TODO: reduce memory usage Converts raw GADM shapefile into WikiBrain readable type Recommended JVM max heapsize = 4G
 */
public static void convertShpFile(File rawFile,SpatialDataFolder outputFolder,int level) throws IOException, WikiBrainException {
  if ((level != 0) && (level != 1))   throw new IllegalArgumentException("String_Node_Str");
  File outputFile;
  Map map=new HashMap();
  List<String> locList=new ArrayList<String>();
  List<Geometry> geoList=new ArrayList<Geometry>();
  List<String> visited=new ArrayList<String>();
  if (level == 1)   outputFile=new File(outputFolder.getRefSysFolder("String_Node_Str").getCanonicalPath() + "String_Node_Str" + "String_Node_Str");
 else   outputFile=new File(outputFolder.getRefSysFolder("String_Node_Str").getCanonicalPath() + "String_Node_Str" + "String_Node_Str");
  GeometryFactory geometryFactory;
  SimpleFeatureTypeBuilder typeBuilder;
  SimpleFeatureBuilder featureBuilder;
  DataStore inputDataStore;
  List<SimpleFeature> features=new ArrayList<SimpleFeature>();
  typeBuilder=new SimpleFeatureTypeBuilder();
  typeBuilder.setName("String_Node_Str");
  typeBuilder.setCRS(DefaultGeographicCRS.WGS84);
  typeBuilder.add("String_Node_Str",MultiPolygon.class);
  typeBuilder.add("String_Node_Str",String.class);
  if (level == 1)   typeBuilder.add("String_Node_Str",String.class);
  typeBuilder.setDefaultGeometry("String_Node_Str");
  final SimpleFeatureType WIKITYPE=typeBuilder.buildFeatureType();
  geometryFactory=JTSFactoryFinder.getGeometryFactory();
  featureBuilder=new SimpleFeatureBuilder(WIKITYPE);
  ShapefileDataStoreFactory dataStoreFactory=new ShapefileDataStoreFactory();
  Map<String,Serializable> outputParams=new HashMap<String,Serializable>();
  outputParams.put("String_Node_Str",outputFile.toURI().toURL());
  outputParams.put("String_Node_Str",Boolean.TRUE);
  ShapefileDataStore outputDataStore=(ShapefileDataStore)dataStoreFactory.createNewDataStore(outputParams);
  outputDataStore.createSchema(WIKITYPE);
  Transaction transaction=new DefaultTransaction("String_Node_Str");
  String typeName=outputDataStore.getTypeNames()[0];
  SimpleFeatureSource outputFeatureSource=outputDataStore.getFeatureSource(typeName);
  map.put("String_Node_Str",rawFile.toURI().toURL());
  inputDataStore=DataStoreFinder.getDataStore(map);
  SimpleFeatureSource inputFeatureSource=inputDataStore.getFeatureSource(inputDataStore.getTypeNames()[0]);
  SimpleFeatureCollection inputCollection=inputFeatureSource.getFeatures();
  SimpleFeatureIterator inputFeatures=inputCollection.features();
  try {
    int total=0;
    while (inputFeatures.hasNext()) {
      SimpleFeature feature=inputFeatures.next();
      String country=((String)feature.getAttribute(4)).intern();
      String state=((String)feature.getAttribute(6)).intern();
      if (!locList.contains(state + "String_Node_Str" + country))       locList.add(state + "String_Node_Str" + country);
    }
    inputFeatures.close();
    if (level == 1) {
      LOG.log(Level.INFO,"String_Node_Str");
      total=locList.size();
    }
 else {
      LOG.log(Level.INFO,"String_Node_Str");
      for (      String stateCountryPair : locList) {
        String country=stateCountryPair.split("String_Node_Str")[1];
        if (!visited.contains(country)) {
          visited.add(country);
          total++;
        }
 else         continue;
      }
    }
    visited.clear();
    int count=0;
    for (    String stateCountryPair : locList) {
      String state=stateCountryPair.split("String_Node_Str")[0];
      String country=stateCountryPair.split("String_Node_Str")[1];
      inputFeatures=inputCollection.features();
      if (level == 1) {
        count++;
        if (count % 10 == 0)         LOG.log(Level.INFO,count + "String_Node_Str" + total+ "String_Node_Str");
        while (inputFeatures.hasNext()) {
          SimpleFeature feature=inputFeatures.next();
          if (feature.getAttribute(6).equals(state) && feature.getAttribute(4).equals(country))           geoList.add((Geometry)feature.getAttribute(0));
        }
      }
 else {
        if (!visited.contains(country)) {
          visited.add(country);
        }
 else         continue;
        count++;
        LOG.log(Level.INFO,"String_Node_Str" + country + "String_Node_Str"+ count+ "String_Node_Str"+ total+ "String_Node_Str");
        while (inputFeatures.hasNext()) {
          SimpleFeature feature=inputFeatures.next();
          if (feature.getAttribute(4).equals(country))           geoList.add((Geometry)feature.getAttribute(0));
        }
      }
      inputFeatures.close();
      Geometry newGeom;
      try {
        newGeom=geometryFactory.buildGeometry(geoList).union();
      }
 catch (      Exception e) {
        if (level == 1)         LOG.log(Level.INFO,"String_Node_Str" + state + "String_Node_Str"+ e.getMessage()+ "String_Node_Str");
 else         LOG.log(Level.INFO,"String_Node_Str" + country + "String_Node_Str"+ e.getMessage()+ "String_Node_Str");
        newGeom=geometryFactory.buildGeometry(geoList).buffer(0);
      }
      featureBuilder.add(newGeom);
      if (level == 1) {
        featureBuilder.add(state);
        featureBuilder.add(state + "String_Node_Str" + country);
      }
 else       featureBuilder.add(country);
      SimpleFeature feature=featureBuilder.buildFeature(null);
      features.add(feature);
      if (outputFeatureSource instanceof SimpleFeatureStore) {
        SimpleFeatureStore featureStore=(SimpleFeatureStore)outputFeatureSource;
        SimpleFeatureCollection collection=new ListFeatureCollection(WIKITYPE,features);
        featureStore.setTransaction(transaction);
        try {
          featureStore.addFeatures(collection);
          transaction.commit();
          collection=null;
        }
 catch (        Exception e) {
          e.printStackTrace();
          transaction.rollback();
        }
      }
 else {
        LOG.log(Level.INFO,typeName + "String_Node_Str");
      }
      features.clear();
      System.gc();
    }
  }
 catch (  MalformedURLException e) {
    e.printStackTrace();
  }
catch (  IOException e) {
    e.printStackTrace();
  }
 finally {
    inputDataStore.dispose();
    transaction.close();
    outputFolder.deleteSpecificFile("String_Node_Str",RefSys.EARTH);
    outputFolder.deleteLayer("String_Node_Str",RefSys.EARTH);
  }
}

Fixed version (ground truth):
/** 
 * @param outputFolder
 * @param level
 * @return //TODO: reduce memory usageConverts raw GADM shapefile into WikiBrain readable type Recommended JVM max heapsize = 4G
 */
public void convertShpFile(SpatialDataFolder outputFolder,int level) throws IOException, WikiBrainException {
  if ((level != 0) && (level != 1))   throw new IllegalArgumentException("String_Node_Str");
  File outputFile=new File(outputFolder.getRefSysFolder("String_Node_Str").getCanonicalPath() + "String_Node_Str" + "String_Node_Str"+ level+ "String_Node_Str");
  List<String> locList=new ArrayList<String>();
  List<Geometry> geoList;
  List<String> visited=new ArrayList<String>();
  GeometryFactory geometryFactory=JTSFactoryFinder.getGeometryFactory();
  ;
  SimpleFeatureBuilder featureBuilder;
  List<SimpleFeature> features;
  final SimpleFeatureType WIKITYPE=getOutputFeatureType(level);
  featureBuilder=new SimpleFeatureBuilder(WIKITYPE);
  SimpleFeatureSource outputFeatureSource=getOutputDataFeatureSource(outputFile,WIKITYPE);
  Transaction transaction=new DefaultTransaction("String_Node_Str");
  SimpleFeatureCollection inputCollection=getInputCollection();
  SimpleFeatureIterator inputFeatures=inputCollection.features();
  try {
    int total=0;
    while (inputFeatures.hasNext()) {
      SimpleFeature feature=inputFeatures.next();
      String country=((String)feature.getAttribute(4)).intern();
      String state=((String)feature.getAttribute(6)).intern();
      if (!locList.contains(state + "String_Node_Str" + country))       locList.add(state + "String_Node_Str" + country);
    }
    inputFeatures.close();
    if (level == 1) {
      LOG.log(Level.INFO,"String_Node_Str");
      total=locList.size();
    }
 else {
      LOG.log(Level.INFO,"String_Node_Str");
      for (      String stateCountryPair : locList) {
        String country=stateCountryPair.split("String_Node_Str")[1];
        if (!visited.contains(country)) {
          visited.add(country);
          total++;
        }
      }
    }
    visited.clear();
    int count=0;
    for (    String stateCountryPair : locList) {
      features=new ArrayList<SimpleFeature>();
      geoList=new ArrayList<Geometry>();
      String state=stateCountryPair.split("String_Node_Str")[0];
      String country=stateCountryPair.split("String_Node_Str")[1];
      inputFeatures=inputCollection.features();
      if (level == 1) {
        count++;
        if (count % 10 == 0)         LOG.log(Level.INFO,count + "String_Node_Str" + total+ "String_Node_Str");
        while (inputFeatures.hasNext()) {
          SimpleFeature feature=inputFeatures.next();
          if (feature.getAttribute(6).equals(state) && feature.getAttribute(4).equals(country))           geoList.add((Geometry)feature.getAttribute(0));
        }
      }
 else {
        if (!visited.contains(country)) {
          visited.add(country);
        }
 else         continue;
        count++;
        LOG.log(Level.INFO,"String_Node_Str" + country + "String_Node_Str"+ count+ "String_Node_Str"+ total+ "String_Node_Str");
        while (inputFeatures.hasNext()) {
          SimpleFeature feature=inputFeatures.next();
          if (feature.getAttribute(4).equals(country))           geoList.add((Geometry)feature.getAttribute(0));
        }
      }
      inputFeatures.close();
      Geometry newGeom;
      try {
        newGeom=geometryFactory.buildGeometry(geoList).union();
      }
 catch (      Exception e) {
        if (level == 1)         LOG.log(Level.INFO,"String_Node_Str" + state + "String_Node_Str"+ e.getMessage()+ "String_Node_Str");
 else         LOG.log(Level.INFO,"String_Node_Str" + country + "String_Node_Str"+ e.getMessage()+ "String_Node_Str");
        newGeom=geometryFactory.buildGeometry(geoList).buffer(0);
      }
      featureBuilder.add(newGeom);
      if (level == 1) {
        featureBuilder.add(state);
        featureBuilder.add(state + "String_Node_Str" + country);
      }
 else       featureBuilder.add(country);
      SimpleFeature feature=featureBuilder.buildFeature(null);
      features.add(feature);
      if (outputFeatureSource instanceof SimpleFeatureStore) {
        SimpleFeatureStore featureStore=(SimpleFeatureStore)outputFeatureSource;
        SimpleFeatureCollection collection=new ListFeatureCollection(WIKITYPE,features);
        featureStore.setTransaction(transaction);
        try {
          featureStore.addFeatures(collection);
          transaction.commit();
        }
 catch (        Exception e) {
          e.printStackTrace();
          transaction.rollback();
        }
      }
 else {
        LOG.log(Level.INFO,"String_Node_Str");
      }
    }
  }
 catch (  MalformedURLException e) {
    e.printStackTrace();
  }
catch (  IOException e) {
    e.printStackTrace();
  }
 finally {
    transaction.close();
    outputFolder.deleteSpecificFile("String_Node_Str",RefSys.EARTH);
    outputFolder.deleteLayer("String_Node_Str",RefSys.EARTH);
  }
}