Program: 52926
Project: 52926
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 file=rawFile;
  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",file.toURI().toURL());
    inputDataStore=DataStoreFinder.getDataStore(map);
    SimpleFeatureSource inputFeatureSource=inputDataStore.getFeatureSource(inputDataStore.getTypeNames()[0]);
    SimpleFeatureCollection inputCollection=inputFeatureSource.getFeatures();
    SimpleFeatureIterator inputFeatures=inputCollection.features();
    LOG.log(Level.INFO,"String_Node_Str");
    if (level == 1) {
      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 {
      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++;
        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 % 50 == 0)         LOG.log(Level.INFO,count + "String_Node_Str" + total+ "String_Node_Str");
        features.add(feature);
        stateShape.remove(state);
        System.gc();
      }
    }
 else {
      int total=stateShape.keySet().size();
      for (      String country : stateShape.keySet()) {
        count++;
        Geometry newGeom=geometryFactory.buildGeometry(stateShape.get(country)).union();
        featureBuilder.add(newGeom);
        featureBuilder.add(country);
        SimpleFeature feature=featureBuilder.buildFeature(null);
        if (count % 50 == 0)         LOG.log(Level.INFO,count + "String_Node_Str" + total+ "String_Node_Str");
        features.add(feature);
        stateShape.remove(country);
        System.gc();
      }
    }
    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();
    LOG.log(Level.INFO,"String_Node_Str");
    if (level == 1) {
      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 {
      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++;
        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 % 50 == 0)         LOG.log(Level.INFO,count + "String_Node_Str" + total+ "String_Node_Str");
        features.add(feature);
        stateShape.remove(state);
        System.gc();
      }
    }
 else {
      int total=stateShape.keySet().size();
      for (      String country : stateShape.keySet()) {
        count++;
        Geometry newGeom=geometryFactory.buildGeometry(stateShape.get(country)).union();
        featureBuilder.add(newGeom);
        featureBuilder.add(country);
        SimpleFeature feature=featureBuilder.buildFeature(null);
        if (count % 50 == 0)         LOG.log(Level.INFO,count + "String_Node_Str" + total+ "String_Node_Str");
        features.add(feature);
        stateShape.remove(country);
        System.gc();
      }
    }
    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();
  }
}