Program: 160678
Project: 160678
Buggy source:
private void setGeometry(JsWriter writer,IdEObject ifcRootObject,String id,String material) throws IfcEngineException, SerializerException {
  id=id.replace('$','-');
  boolean materialFound=false;
  if (ifcRootObject instanceof IfcProduct) {
    IfcProduct ifcProduct=(IfcProduct)ifcRootObject;
    EList<IfcRelDecomposes> isDecomposedBy=ifcProduct.getIsDecomposedBy();
    for (    IfcRelDecomposes dcmp : isDecomposedBy) {
      EList<IfcObjectDefinition> relatedObjects=dcmp.getRelatedObjects();
      for (      IfcObjectDefinition relatedObject : relatedObjects) {
        setGeometry(writer,relatedObject,relatedObject.getGlobalId().getWrappedValue(),material);
      }
    }
    if (isDecomposedBy != null && isDecomposedBy.size() > 0) {
      return;
    }
    Iterator<IfcRelAssociatesMaterial> ramIter=model.getAll(IfcRelAssociatesMaterial.class).iterator();
    boolean found=false;
    IfcMaterialSelect relatingMaterial=null;
    while (!found && ramIter.hasNext()) {
      IfcRelAssociatesMaterial ram=ramIter.next();
      if (ram.getRelatedObjects().contains(ifcProduct)) {
        found=true;
        relatingMaterial=ram.getRelatingMaterial();
      }
    }
    if (found && relatingMaterial instanceof IfcMaterialLayerSetUsage) {
      IfcMaterialLayerSetUsage mlsu=(IfcMaterialLayerSetUsage)relatingMaterial;
      IfcMaterialLayerSet forLayerSet=mlsu.getForLayerSet();
      if (forLayerSet != null) {
        EList<IfcMaterialLayer> materialLayers=forLayerSet.getMaterialLayers();
        for (        IfcMaterialLayer ml : materialLayers) {
          IfcMaterial ifcMaterial=ml.getMaterial();
          if (ifcMaterial != null) {
            String name=ifcMaterial.getName();
            String filterSpaces=fitNameForQualifiedName(name);
            materialFound=surfaceStyleIds.contains(filterSpaces);
            if (materialFound) {
              material=filterSpaces;
            }
          }
        }
      }
    }
 else     if (found && relatingMaterial instanceof IfcMaterial) {
      IfcMaterial ifcMaterial=(IfcMaterial)relatingMaterial;
      String name=ifcMaterial.getName();
      String filterSpaces=fitNameForQualifiedName(name);
      materialFound=surfaceStyleIds.contains(filterSpaces);
      if (materialFound) {
        material=filterSpaces;
      }
    }
    if (!materialFound) {
      IfcProductRepresentation representation=ifcProduct.getRepresentation();
      if (representation instanceof IfcProductDefinitionShape) {
        IfcProductDefinitionShape pds=(IfcProductDefinitionShape)representation;
        EList<IfcRepresentation> representations=pds.getRepresentations();
        for (        IfcRepresentation rep : representations) {
          if (rep instanceof IfcShapeRepresentation) {
            IfcShapeRepresentation sRep=(IfcShapeRepresentation)rep;
            EList<IfcRepresentationItem> items=sRep.getItems();
            for (            IfcRepresentationItem item : items) {
              EList<IfcStyledItem> styledByItem=item.getStyledByItem();
              for (              IfcStyledItem sItem : styledByItem) {
                EList<IfcPresentationStyleAssignment> styles=sItem.getStyles();
                for (                IfcPresentationStyleAssignment sa : styles) {
                  EList<IfcPresentationStyleSelect> styles2=sa.getStyles();
                  for (                  IfcPresentationStyleSelect pss : styles2) {
                    if (pss instanceof IfcSurfaceStyle) {
                      IfcSurfaceStyle ss=(IfcSurfaceStyle)pss;
                      String name=ss.getName();
                      String filterSpaces=fitNameForQualifiedName(name);
                      materialFound=surfaceStyleIds.contains(filterSpaces);
                      if (materialFound) {
                        material=filterSpaces;
                      }
                    }
                  }
                }
              }
            }
          }
        }
      }
    }
  }
  if (!converted.containsKey(material)) {
    converted.put(material,new HashSet<String>());
  }
  converted.get(material).add(id);
  IfcModelInterface ifcModel=new IfcModel();
  convertToSubset(ifcRootObject.eClass(),ifcRootObject,ifcModel,new HashMap<EObject,EObject>());
  EmfSerializer serializer=getPluginManager().requireIfcStepSerializer();
  serializer.init(ifcModel,getProjectInfo(),getPluginManager());
  try {
    IfcEngineModel model=ifcEngine.openModel(serializer.getBytes());
    try {
      model.setPostProcessing(true);
      IfcEngineGeometry geometry=model.finalizeModelling(model.initializeModelling());
      if (geometry != null) {
        writer.writeln("String_Node_Str");
        writer.indent();
        writer.writeln("String_Node_Str");
        writer.writeln("String_Node_Str" + id + "String_Node_Str");
        writer.writeln("String_Node_Str" + id + "String_Node_Str");
        writer.writeln("String_Node_Str");
        writer.writetab("String_Node_Str");
        for (int i=0; i < geometry.getNrVertices(); i+=1) {
          writer.print(geometry.getVertex(i) + "String_Node_Str");
        }
        writer.println("String_Node_Str");
        writer.writetab("String_Node_Str");
        for (int i=0; i < geometry.getNrNormals(); i++) {
          writer.print(geometry.getNormal(i) + "String_Node_Str");
        }
        writer.println("String_Node_Str");
        List<? extends IfcEngineInstance> instances=model.getInstances(ifcRootObject.eClass().getName().toUpperCase());
        if (instances.size() > 1)         writer.writeln("String_Node_Str");
        for (        IfcEngineInstance instance : instances) {
          IfcEngineInstanceVisualisationProperties instanceInModelling=instance.getVisualisationProperties();
          writer.writetab("String_Node_Str");
          for (int i=instanceInModelling.getStartIndex(); i < instanceInModelling.getPrimitiveCount() * 3 + instanceInModelling.getStartIndex(); i+=3) {
            writer.print(geometry.getIndex(i) + "String_Node_Str");
            writer.print(geometry.getIndex(i + 2) + "String_Node_Str");
            writer.print(geometry.getIndex(i + 1) + "String_Node_Str");
          }
          writer.println("String_Node_Str");
        }
        writer.unindent();
        writer.writeln("String_Node_Str");
      }
    }
  finally {
      model.close();
    }
  }
 catch (  IfcEngineException e) {
    throw e;
  }
catch (  Exception e) {
    LOGGER.error("String_Node_Str",e);
  }
}

Fixed version (ground truth):
private void setGeometry(JsWriter writer,IdEObject ifcRootObject,String id,String material) throws IfcEngineException, SerializerException {
  id=id.replace('$','-');
  boolean materialFound=false;
  if (ifcRootObject instanceof IfcProduct) {
    IfcProduct ifcProduct=(IfcProduct)ifcRootObject;
    EList<IfcRelDecomposes> isDecomposedBy=ifcProduct.getIsDecomposedBy();
    for (    IfcRelDecomposes dcmp : isDecomposedBy) {
      EList<IfcObjectDefinition> relatedObjects=dcmp.getRelatedObjects();
      for (      IfcObjectDefinition relatedObject : relatedObjects) {
        setGeometry(writer,relatedObject,relatedObject.getGlobalId().getWrappedValue(),material);
      }
    }
    if (isDecomposedBy != null && isDecomposedBy.size() > 0) {
      return;
    }
    Iterator<IfcRelAssociatesMaterial> ramIter=model.getAll(IfcRelAssociatesMaterial.class).iterator();
    boolean found=false;
    IfcMaterialSelect relatingMaterial=null;
    while (!found && ramIter.hasNext()) {
      IfcRelAssociatesMaterial ram=ramIter.next();
      if (ram.getRelatedObjects().contains(ifcProduct)) {
        found=true;
        relatingMaterial=ram.getRelatingMaterial();
      }
    }
    if (found && relatingMaterial instanceof IfcMaterialLayerSetUsage) {
      IfcMaterialLayerSetUsage mlsu=(IfcMaterialLayerSetUsage)relatingMaterial;
      IfcMaterialLayerSet forLayerSet=mlsu.getForLayerSet();
      if (forLayerSet != null) {
        EList<IfcMaterialLayer> materialLayers=forLayerSet.getMaterialLayers();
        for (        IfcMaterialLayer ml : materialLayers) {
          IfcMaterial ifcMaterial=ml.getMaterial();
          if (ifcMaterial != null) {
            String name=ifcMaterial.getName();
            String filterSpaces=fitNameForQualifiedName(name);
            materialFound=surfaceStyleIds.contains(filterSpaces);
            if (materialFound) {
              material=filterSpaces;
            }
          }
        }
      }
    }
 else     if (found && relatingMaterial instanceof IfcMaterial) {
      IfcMaterial ifcMaterial=(IfcMaterial)relatingMaterial;
      String name=ifcMaterial.getName();
      String filterSpaces=fitNameForQualifiedName(name);
      materialFound=surfaceStyleIds.contains(filterSpaces);
      if (materialFound) {
        material=filterSpaces;
      }
    }
    if (!materialFound) {
      IfcProductRepresentation representation=ifcProduct.getRepresentation();
      if (representation instanceof IfcProductDefinitionShape) {
        IfcProductDefinitionShape pds=(IfcProductDefinitionShape)representation;
        EList<IfcRepresentation> representations=pds.getRepresentations();
        for (        IfcRepresentation rep : representations) {
          if (rep instanceof IfcShapeRepresentation) {
            IfcShapeRepresentation sRep=(IfcShapeRepresentation)rep;
            EList<IfcRepresentationItem> items=sRep.getItems();
            for (            IfcRepresentationItem item : items) {
              EList<IfcStyledItem> styledByItem=item.getStyledByItem();
              for (              IfcStyledItem sItem : styledByItem) {
                EList<IfcPresentationStyleAssignment> styles=sItem.getStyles();
                for (                IfcPresentationStyleAssignment sa : styles) {
                  EList<IfcPresentationStyleSelect> styles2=sa.getStyles();
                  for (                  IfcPresentationStyleSelect pss : styles2) {
                    if (pss instanceof IfcSurfaceStyle) {
                      IfcSurfaceStyle ss=(IfcSurfaceStyle)pss;
                      String name=ss.getName();
                      String filterSpaces=fitNameForQualifiedName(name);
                      materialFound=surfaceStyleIds.contains(filterSpaces);
                      if (materialFound) {
                        material=filterSpaces;
                      }
                    }
                  }
                }
              }
            }
          }
        }
      }
    }
  }
  if (!converted.containsKey(material)) {
    converted.put(material,new HashSet<String>());
  }
  converted.get(material).add(id);
  IfcModelInterface ifcModel=new IfcModel();
  convertToSubset(ifcRootObject.eClass(),ifcRootObject,ifcModel,new HashMap<EObject,EObject>());
  EmfSerializer serializer=getPluginManager().requireIfcStepSerializer();
  serializer.init(ifcModel,getProjectInfo(),getPluginManager());
  try {
    IfcEngineModel model=ifcEngine.openModel(serializer.getBytes());
    try {
      model.setPostProcessing(true);
      IfcEngineGeometry geometry=model.finalizeModelling(model.initializeModelling());
      if (geometry != null) {
        writer.writeln("String_Node_Str");
        writer.indent();
        writer.writeln("String_Node_Str");
        writer.writeln("String_Node_Str" + id + "String_Node_Str");
        writer.writeln("String_Node_Str");
        writer.writetab("String_Node_Str");
        for (int i=0; i < geometry.getNrVertices(); i+=1) {
          writer.print(geometry.getVertex(i) + "String_Node_Str");
        }
        writer.println("String_Node_Str");
        writer.writetab("String_Node_Str");
        for (int i=0; i < geometry.getNrNormals(); i++) {
          writer.print(geometry.getNormal(i) + "String_Node_Str");
        }
        writer.println("String_Node_Str");
        List<? extends IfcEngineInstance> instances=model.getInstances(ifcRootObject.eClass().getName().toUpperCase());
        if (instances.size() > 1)         writer.writeln("String_Node_Str");
        for (        IfcEngineInstance instance : instances) {
          IfcEngineInstanceVisualisationProperties instanceInModelling=instance.getVisualisationProperties();
          writer.writetab("String_Node_Str");
          for (int i=instanceInModelling.getStartIndex(); i < instanceInModelling.getPrimitiveCount() * 3 + instanceInModelling.getStartIndex(); i+=3) {
            writer.print(geometry.getIndex(i) + "String_Node_Str");
            writer.print(geometry.getIndex(i + 2) + "String_Node_Str");
            writer.print(geometry.getIndex(i + 1) + "String_Node_Str");
          }
          writer.println("String_Node_Str");
        }
        writer.unindent();
        writer.writeln("String_Node_Str");
      }
    }
  finally {
      model.close();
    }
  }
 catch (  IfcEngineException e) {
    throw e;
  }
catch (  Exception e) {
    LOGGER.error("String_Node_Str",e);
  }
}