Program: 52903
Project: 52903
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>();
  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 {
    if (level == 1) {
      LOG.log(Level.INFO,"String_Node_Str");
    }
 else {
      LOG.log(Level.INFO,"String_Node_Str");
    }
    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();
    int total=locList.size();
    int count=0;
    for (    String stateCountryPair : locList) {
      String state=stateCountryPair.split("String_Node_Str")[0];
      String country=stateCountryPair.split("String_Node_Str")[1];
      count++;
      inputFeatures=inputCollection.features();
      if (level == 1) {
        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 {
        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);
      featureBuilder.add(state);
      featureBuilder.add(state + "String_Node_Str" + 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 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);
  }
}