Program: 52920
Project: 52920
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 {
  if ((level != 0) && (level != 1))   throw new IllegalArgumentException("String_Node_Str");
  File outputFile;
  Map map=new HashMap();
  HashMap<String,List<Geometry>> stateShape=new HashMap<String,List<Geometry>>();
  HashMap<String,String> stateCountry=new HashMap<String,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");
  ShapefileReader shpReader;
  GeometryFactory geometryFactory;
  SimpleFeatureTypeBuilder typeBuilder;
  SimpleFeatureBuilder featureBuilder;
  DataStore inputDataStore;
  List<SimpleFeature> features=new ArrayList<SimpleFeature>();
  try {
    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();
    if (level == 1) {
      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 (!stateShape.containsKey(state)) {
          stateShape.put(state,new ArrayList<Geometry>());
          stateCountry.put(state,country);
        }
        stateShape.get(state).add((Geometry)feature.getAttribute(0));
      }
    }
 else {
      LOG.log(Level.INFO,"String_Node_Str");
      while (inputFeatures.hasNext()) {
        SimpleFeature feature=inputFeatures.next();
        String country=((String)feature.getAttribute(4)).intern();
        if (!stateShape.containsKey(country))         stateShape.put(country,new ArrayList<Geometry>());
        stateShape.get(country).add((Geometry)feature.getAttribute(0));
      }
    }
    inputFeatures.close();
    inputDataStore.dispose();
    LOG.log(Level.INFO,"String_Node_Str");
    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);
    LOG.log(Level.INFO,"String_Node_Str");
    int count=0;
    if (level == 1) {
      int total=stateShape.keySet().size();
      for (      String state : stateCountry.keySet()) {
        try {
          count++;
          Geometry newGeom=geometryFactory.buildGeometry(stateShape.get(state)).union();
          featureBuilder.add(newGeom);
          featureBuilder.add(state);
          featureBuilder.add(state + "String_Node_Str" + stateCountry.get(state));
          SimpleFeature feature=featureBuilder.buildFeature(null);
          if (count % 10 == 0)           LOG.log(Level.INFO,count + "String_Node_Str" + total+ "String_Node_Str");
          features.add(feature);
          stateShape.remove(state);
          System.gc();
        }
 catch (        Exception e) {
          LOG.log(Level.INFO,"String_Node_Str" + state + "String_Node_Str"+ e.getMessage());
          stateShape.remove(state);
          System.gc();
          continue;
        }
      }
    }
 else {
      int total=stateShape.keySet().size();
      HashSet<String> countryList=new HashSet<String>();
      countryList.addAll(stateShape.keySet());
      for (      String country : countryList) {
        try {
          count++;
          LOG.log(Level.INFO,"String_Node_Str" + stateShape.get(country).size() + "String_Node_Str"+ country+ "String_Node_Str"+ count+ "String_Node_Str"+ total+ "String_Node_Str");
          Geometry newGeom=geometryFactory.buildGeometry(stateShape.get(country)).union();
          featureBuilder.add(newGeom);
          featureBuilder.add(country);
          SimpleFeature feature=featureBuilder.buildFeature(null);
          features.add(feature);
          stateShape.remove(country);
          System.gc();
        }
 catch (        Exception e) {
          LOG.log(Level.INFO,"String_Node_Str" + country + "String_Node_Str"+ e.getMessage());
          stateShape.remove(country);
          System.gc();
          continue;
        }
      }
    }
    if (level == 1) {
      LOG.log(Level.INFO,"String_Node_Str" + count + "String_Node_Str");
    }
 else {
      LOG.log(Level.INFO,"String_Node_Str" + count + "String_Node_Str");
    }
    stateCountry=null;
    stateShape=null;
    System.gc();
    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);
    SimpleFeatureType SHAPE_TYPE=outputFeatureSource.getSchema();
    LOG.log(Level.INFO,"String_Node_Str" + outputFile.getCanonicalPath());
    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();
      }
 finally {
        transaction.close();
      }
      LOG.log(Level.INFO,"String_Node_Str");
    }
 else {
      LOG.log(Level.INFO,typeName + "String_Node_Str");
    }
  }
 catch (  MalformedURLException e) {
    e.printStackTrace();
  }
catch (  IOException e) {
    e.printStackTrace();
  }
}

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 {
  if ((level != 0) && (level != 1))   throw new IllegalArgumentException("String_Node_Str");
  File outputFile;
  Map map=new HashMap();
  HashMap<String,List<Geometry>> stateShape=new HashMap<String,List<Geometry>>();
  HashMap<String,String> stateCountry=new HashMap<String,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");
  ShapefileReader shpReader;
  GeometryFactory geometryFactory;
  SimpleFeatureTypeBuilder typeBuilder;
  SimpleFeatureBuilder featureBuilder;
  DataStore inputDataStore;
  List<SimpleFeature> features=new ArrayList<SimpleFeature>();
  try {
    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();
    if (level == 1) {
      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 (!stateShape.containsKey(state)) {
          stateShape.put(state,new ArrayList<Geometry>());
          stateCountry.put(state,country);
        }
        stateShape.get(state).add((Geometry)feature.getAttribute(0));
      }
    }
 else {
      LOG.log(Level.INFO,"String_Node_Str");
      while (inputFeatures.hasNext()) {
        SimpleFeature feature=inputFeatures.next();
        String country=((String)feature.getAttribute(4)).intern();
        if (!stateShape.containsKey(country))         stateShape.put(country,new ArrayList<Geometry>());
        stateShape.get(country).add((Geometry)feature.getAttribute(0));
      }
    }
    inputFeatures.close();
    inputDataStore.dispose();
    LOG.log(Level.INFO,"String_Node_Str");
    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);
    LOG.log(Level.INFO,"String_Node_Str");
    int count=0;
    if (level == 1) {
      int total=stateShape.keySet().size();
      for (      String state : stateCountry.keySet()) {
        count++;
        try {
          Geometry newGeom=geometryFactory.buildGeometry(stateShape.get(state)).union();
          featureBuilder.add(newGeom);
          featureBuilder.add(state);
          featureBuilder.add(state + "String_Node_Str" + stateCountry.get(state));
          SimpleFeature feature=featureBuilder.buildFeature(null);
          if (count % 10 == 0)           LOG.log(Level.INFO,count + "String_Node_Str" + total+ "String_Node_Str");
          features.add(feature);
          stateShape.remove(state);
          System.gc();
        }
 catch (        Exception e) {
          Geometry newGeom=geometryFactory.buildGeometry(stateShape.get(state)).buffer(0);
          featureBuilder.add(newGeom);
          featureBuilder.add(state);
          featureBuilder.add(state + "String_Node_Str" + stateCountry.get(state));
          SimpleFeature feature=featureBuilder.buildFeature(null);
          if (count % 10 == 0)           LOG.log(Level.INFO,count + "String_Node_Str" + total+ "String_Node_Str");
          features.add(feature);
          LOG.log(Level.INFO,"String_Node_Str" + state + "String_Node_Str"+ e.getMessage()+ "String_Node_Str");
          stateShape.remove(state);
          System.gc();
          continue;
        }
      }
    }
 else {
      int total=stateShape.keySet().size();
      HashSet<String> countryList=new HashSet<String>();
      countryList.addAll(stateShape.keySet());
      for (      String country : countryList) {
        count++;
        try {
          LOG.log(Level.INFO,"String_Node_Str" + stateShape.get(country).size() + "String_Node_Str"+ country+ "String_Node_Str"+ count+ "String_Node_Str"+ total+ "String_Node_Str");
          Geometry newGeom=geometryFactory.buildGeometry(stateShape.get(country)).union();
          featureBuilder.add(newGeom);
          featureBuilder.add(country);
          SimpleFeature feature=featureBuilder.buildFeature(null);
          features.add(feature);
          stateShape.remove(country);
          System.gc();
        }
 catch (        Exception e) {
          LOG.log(Level.INFO,"String_Node_Str" + country + "String_Node_Str"+ e.getMessage()+ "String_Node_Str");
          Geometry newGeom=geometryFactory.buildGeometry(stateShape.get(country)).buffer(0);
          featureBuilder.add(newGeom);
          featureBuilder.add(country);
          SimpleFeature feature=featureBuilder.buildFeature(null);
          features.add(feature);
          stateShape.remove(country);
          System.gc();
          continue;
        }
      }
    }
    if (level == 1) {
      LOG.log(Level.INFO,"String_Node_Str" + count + "String_Node_Str");
    }
 else {
      LOG.log(Level.INFO,"String_Node_Str" + count + "String_Node_Str");
    }
    stateCountry=null;
    stateShape=null;
    System.gc();
    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);
    SimpleFeatureType SHAPE_TYPE=outputFeatureSource.getSchema();
    LOG.log(Level.INFO,"String_Node_Str" + outputFile.getCanonicalPath());
    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();
      }
 finally {
        transaction.close();
      }
      LOG.log(Level.INFO,"String_Node_Str");
    }
 else {
      LOG.log(Level.INFO,typeName + "String_Node_Str");
    }
  }
 catch (  MalformedURLException e) {
    e.printStackTrace();
  }
catch (  IOException e) {
    e.printStackTrace();
  }
}