Program: 90856
Project: 90856
Buggy source:
/** 
 * Imports the specified TrackMate file as a MaMuT   {@link Model}.
 * @param file the path to the TrackMate file.
 * @return a new model.
 * @throws JDOMException if an error happens while parsing the XML file.
 * @throws IOException if an IO error prevents the XML file to be parsed.
 */
public static Model importModel(final File file) throws JDOMException, IOException {
  final Model model=new Model();
  final ModelGraph graph=model.getGraph();
  final SAXBuilder sb=new SAXBuilder();
  final Document document=sb.build(file);
  final Element root=document.getRootElement();
  final Element modelEl=root.getChild(MODEL_TAG);
  if (null == modelEl) {
    return null;
  }
  final Element featureDeclarationEl=modelEl.getChild(FEATURE_DECLARATION_TAG);
  final Element spotFeatureDeclarationEl=featureDeclarationEl.getChild(SPOT_FEATURE_DECLARATION_TAG);
  final List<Element> spotFeatureEls=spotFeatureDeclarationEl.getChildren(FEATURE_TAG);
  final Map<String,DoubleFeature<Spot>> spotDoubleFeatureMap=new HashMap<>();
  final Map<String,IntFeature<Spot>> spotIntFeatureMap=new HashMap<>();
  for (  final Element featureEl : spotFeatureEls) {
    final String featureKey=featureEl.getAttributeValue(FEATURE_ATTRIBUTE_NAME);
    final boolean featureIsInt=Boolean.parseBoolean(featureEl.getAttributeValue(FEATURE_ISINT_ATTRIBUTE_NAME));
    if (featureIsInt) {
      final IntFeature<Spot> feature=new IntFeature<>(SPOT_FEATURE_PREFIX + featureKey,Integer.MIN_VALUE);
      spotIntFeatureMap.put(featureKey,feature);
    }
 else {
      final DoubleFeature<Spot> feature=new DoubleFeature<>(SPOT_FEATURE_PREFIX + featureKey,Double.NaN);
      spotDoubleFeatureMap.put(featureKey,feature);
    }
  }
  final Element edgeFeatureDeclarationEl=featureDeclarationEl.getChild(EDGE_FEATURE_DECLARATION_TAG);
  final List<Element> edgeFeatureEls=edgeFeatureDeclarationEl.getChildren(FEATURE_TAG);
  final Map<String,DoubleFeature<Link>> edgeDoubleFeatureMap=new HashMap<>();
  final Map<String,IntFeature<Link>> edgeIntFeatureMap=new HashMap<>();
  for (  final Element featureEl : edgeFeatureEls) {
    final String featureKey=featureEl.getAttributeValue(FEATURE_ATTRIBUTE_NAME);
    final boolean featureIsInt=Boolean.parseBoolean(featureEl.getAttributeValue(FEATURE_ISINT_ATTRIBUTE_NAME));
    if (featureIsInt) {
      final IntFeature<Link> feature=new IntFeature<>(EDGE_FEATURE_PREFIX + featureKey,Integer.MIN_VALUE);
      edgeIntFeatureMap.put(featureKey,feature);
    }
 else {
      final DoubleFeature<Link> feature=new DoubleFeature<>(EDGE_FEATURE_PREFIX + featureKey,Double.NaN);
      edgeDoubleFeatureMap.put(featureKey,feature);
    }
  }
  final Spot ref=graph.vertexRef();
  final Spot putRef=graph.vertexRef();
  final Spot sourceRef=graph.vertexRef();
  final Spot targetRef=graph.vertexRef();
  final Link edgeRef=graph.edgeRef();
  try {
    final double[] pos=new double[3];
    final IntRefMap<Spot> idToSpotIDmap=RefCollections.createIntRefMap(graph.vertices(),-1);
    final Element allSpotsEl=modelEl.getChild(SPOT_COLLECTION_TAG);
    final List<Element> allFramesEl=allSpotsEl.getChildren(SPOT_FRAME_COLLECTION_TAG);
    for (    final Element frameEl : allFramesEl) {
      final List<Element> frameSpotsEl=frameEl.getChildren(SPOT_ELEMENT_TAG);
      for (      final Element spotEl : frameSpotsEl) {
        final boolean visible=Integer.parseInt(spotEl.getAttributeValue(VISIBILITY_ATTRIBUTE_NAME)) != 0;
        if (!visible)         continue;
        pos[0]=Double.parseDouble(spotEl.getAttributeValue(X_ATTRIBUTE_NAME));
        pos[1]=Double.parseDouble(spotEl.getAttributeValue(Y_ATTRIBUTE_NAME));
        pos[2]=Double.parseDouble(spotEl.getAttributeValue(Z_ATTRIBUTE_NAME));
        final double radius=Double.parseDouble(spotEl.getAttributeValue(RADIUS_ATTRIBUTE_NAME));
        final int frame=Integer.parseInt(spotEl.getAttributeValue(FRAME_ATTRIBUTE_NAME));
        final int id=Integer.parseInt(spotEl.getAttributeValue(ID_ATTRIBUTE_NAME));
        final String label=spotEl.getAttributeValue(LABEL_ATTRIBUTE_NAME);
        final Spot spot=graph.addVertex(ref).init(frame,pos,radius);
        spot.setLabel(label);
        idToSpotIDmap.put(id,spot,putRef);
        for (        final String featureKey : spotDoubleFeatureMap.keySet()) {
          final String attributeValue=spotEl.getAttributeValue(featureKey);
          if (null != attributeValue) {
            final double val=Double.parseDouble(attributeValue);
            final DoubleFeature<Spot> feature=spotDoubleFeatureMap.get(featureKey);
            spot.feature(feature).set(val);
          }
        }
        for (        final String featureKey : spotIntFeatureMap.keySet()) {
          final String attributeValue=spotEl.getAttributeValue(featureKey);
          if (null != attributeValue) {
            final int val=Integer.parseInt(attributeValue);
            final IntFeature<Spot> feature=spotIntFeatureMap.get(featureKey);
            spot.feature(feature).set(val);
          }
        }
      }
    }
    final Element trackCollectionEl=modelEl.getChild(TRACK_COLLECTION_TAG);
    final List<Element> trakEls=trackCollectionEl.getChildren(TRACK_TAG);
    for (    final Element trackEl : trakEls) {
      final List<Element> edgeEls=trackEl.getChildren(EDGE_TAG);
      for (      final Element edgeEl : edgeEls) {
        final int sourceID=Integer.parseInt(edgeEl.getAttributeValue(EDGE_SOURCE_ATTRIBUTE_NAME));
        final Spot source=idToSpotIDmap.get(sourceID,sourceRef);
        final int targetID=Integer.parseInt(edgeEl.getAttributeValue(EDGE_TARGET_ATTRIBUTE_NAME));
        final Spot target=idToSpotIDmap.get(targetID,targetRef);
        final Link link=graph.addEdge(source,target,edgeRef).init();
        for (        final String featureKey : edgeDoubleFeatureMap.keySet()) {
          final String attributeValue=edgeEl.getAttributeValue(featureKey);
          if (null != attributeValue) {
            final double val=Double.parseDouble(attributeValue);
            final DoubleFeature<Link> feature=edgeDoubleFeatureMap.get(featureKey);
            link.feature(feature).set(val);
          }
        }
        for (        final String featureKey : edgeIntFeatureMap.keySet()) {
          final String attributeValue=edgeEl.getAttributeValue(featureKey);
          if (null != attributeValue) {
            final int val=Integer.parseInt(attributeValue);
            final IntFeature<Link> feature=edgeIntFeatureMap.get(featureKey);
            link.feature(feature).set(val);
          }
        }
      }
    }
    return model;
  }
  finally {
    graph.releaseRef(ref);
    graph.releaseRef(putRef);
    graph.releaseRef(sourceRef);
    graph.releaseRef(targetRef);
    graph.releaseRef(edgeRef);
  }
}

Fixed version (ground truth):
/** 
 * Imports the specified TrackMate file as a MaMuT   {@link Model}.
 * @param file the path to the TrackMate file.
 * @return a new model.
 * @throws JDOMException if an error happens while parsing the XML file.
 * @throws IOException if an IO error prevents the XML file to be parsed.
 */
public static TrackMateModel importModel(final File file) throws JDOMException, IOException {
  final Model model=new Model();
  final ModelGraph graph=model.getGraph();
  final SAXBuilder sb=new SAXBuilder();
  final Document document=sb.build(file);
  final Element root=document.getRootElement();
  final Element modelEl=root.getChild(MODEL_TAG);
  if (null == modelEl) {
    return null;
  }
  final Element featureDeclarationEl=modelEl.getChild(FEATURE_DECLARATION_TAG);
  final Element spotFeatureDeclarationEl=featureDeclarationEl.getChild(SPOT_FEATURE_DECLARATION_TAG);
  final List<Element> spotFeatureEls=spotFeatureDeclarationEl.getChildren(FEATURE_TAG);
  final Map<String,DoublePropertyMap<Spot>> spotDoubleFeatureMap=new HashMap<>();
  final Map<String,IntPropertyMap<Spot>> spotIntFeatureMap=new HashMap<>();
  for (  final Element featureEl : spotFeatureEls) {
    final String featureKey=featureEl.getAttributeValue(FEATURE_ATTRIBUTE_NAME);
    final boolean featureIsInt=Boolean.parseBoolean(featureEl.getAttributeValue(FEATURE_ISINT_ATTRIBUTE_NAME));
    if (featureIsInt) {
      final IntPropertyMap<Spot> feature=new IntPropertyMap<>(graph.vertices(),Integer.MIN_VALUE);
      spotIntFeatureMap.put(featureKey,feature);
    }
 else {
      final DoublePropertyMap<Spot> feature=new DoublePropertyMap<>(graph.vertices(),Double.NaN);
      spotDoubleFeatureMap.put(featureKey,feature);
    }
  }
  final Element edgeFeatureDeclarationEl=featureDeclarationEl.getChild(EDGE_FEATURE_DECLARATION_TAG);
  final List<Element> edgeFeatureEls=edgeFeatureDeclarationEl.getChildren(FEATURE_TAG);
  final Map<String,DoublePropertyMap<Link>> edgeDoubleFeatureMap=new HashMap<>();
  final Map<String,IntPropertyMap<Link>> edgeIntFeatureMap=new HashMap<>();
  for (  final Element featureEl : edgeFeatureEls) {
    final String featureKey=featureEl.getAttributeValue(FEATURE_ATTRIBUTE_NAME);
    final boolean featureIsInt=Boolean.parseBoolean(featureEl.getAttributeValue(FEATURE_ISINT_ATTRIBUTE_NAME));
    if (featureIsInt) {
      final IntPropertyMap<Link> feature=new IntPropertyMap<>(graph.edges(),Integer.MIN_VALUE);
      edgeIntFeatureMap.put(featureKey,feature);
    }
 else {
      final DoublePropertyMap<Link> feature=new DoublePropertyMap<>(graph.edges(),Double.NaN);
      edgeDoubleFeatureMap.put(featureKey,feature);
    }
  }
  final Spot ref=graph.vertexRef();
  final Spot putRef=graph.vertexRef();
  final Spot sourceRef=graph.vertexRef();
  final Spot targetRef=graph.vertexRef();
  final Link edgeRef=graph.edgeRef();
  try {
    final double[] pos=new double[3];
    final IntRefMap<Spot> idToSpotIDmap=RefCollections.createIntRefMap(graph.vertices(),-1);
    final Element allSpotsEl=modelEl.getChild(SPOT_COLLECTION_TAG);
    final List<Element> allFramesEl=allSpotsEl.getChildren(SPOT_FRAME_COLLECTION_TAG);
    for (    final Element frameEl : allFramesEl) {
      final List<Element> frameSpotsEl=frameEl.getChildren(SPOT_ELEMENT_TAG);
      for (      final Element spotEl : frameSpotsEl) {
        final boolean visible=Integer.parseInt(spotEl.getAttributeValue(VISIBILITY_ATTRIBUTE_NAME)) != 0;
        if (!visible)         continue;
        pos[0]=Double.parseDouble(spotEl.getAttributeValue(X_ATTRIBUTE_NAME));
        pos[1]=Double.parseDouble(spotEl.getAttributeValue(Y_ATTRIBUTE_NAME));
        pos[2]=Double.parseDouble(spotEl.getAttributeValue(Z_ATTRIBUTE_NAME));
        final double radius=Double.parseDouble(spotEl.getAttributeValue(RADIUS_ATTRIBUTE_NAME));
        final int frame=Integer.parseInt(spotEl.getAttributeValue(FRAME_ATTRIBUTE_NAME));
        final int id=Integer.parseInt(spotEl.getAttributeValue(ID_ATTRIBUTE_NAME));
        final String label=spotEl.getAttributeValue(LABEL_ATTRIBUTE_NAME);
        final Spot spot=graph.addVertex(ref).init(frame,pos,radius);
        spot.setLabel(label);
        idToSpotIDmap.put(id,spot,putRef);
        for (        final String featureKey : spotDoubleFeatureMap.keySet()) {
          final String attributeValue=spotEl.getAttributeValue(featureKey);
          if (null != attributeValue) {
            final double val=Double.parseDouble(attributeValue);
            final DoublePropertyMap<Spot> feature=spotDoubleFeatureMap.get(featureKey);
            feature.set(spot,val);
          }
        }
        for (        final String featureKey : spotIntFeatureMap.keySet()) {
          final String attributeValue=spotEl.getAttributeValue(featureKey);
          if (null != attributeValue) {
            final int val=Integer.parseInt(attributeValue);
            final IntPropertyMap<Spot> feature=spotIntFeatureMap.get(featureKey);
            feature.set(spot,val);
          }
        }
      }
    }
    final Element trackCollectionEl=modelEl.getChild(TRACK_COLLECTION_TAG);
    final List<Element> trakEls=trackCollectionEl.getChildren(TRACK_TAG);
    for (    final Element trackEl : trakEls) {
      final List<Element> edgeEls=trackEl.getChildren(EDGE_TAG);
      for (      final Element edgeEl : edgeEls) {
        final int sourceID=Integer.parseInt(edgeEl.getAttributeValue(EDGE_SOURCE_ATTRIBUTE_NAME));
        final Spot source=idToSpotIDmap.get(sourceID,sourceRef);
        final int targetID=Integer.parseInt(edgeEl.getAttributeValue(EDGE_TARGET_ATTRIBUTE_NAME));
        final Spot target=idToSpotIDmap.get(targetID,targetRef);
        final Link link=graph.addEdge(source,target,edgeRef).init();
        for (        final String featureKey : edgeDoubleFeatureMap.keySet()) {
          final String attributeValue=edgeEl.getAttributeValue(featureKey);
          if (null != attributeValue) {
            final double val=Double.parseDouble(attributeValue);
            final DoublePropertyMap<Link> feature=edgeDoubleFeatureMap.get(featureKey);
            feature.set(link,val);
          }
        }
        for (        final String featureKey : edgeIntFeatureMap.keySet()) {
          final String attributeValue=edgeEl.getAttributeValue(featureKey);
          if (null != attributeValue) {
            final int val=Integer.parseInt(attributeValue);
            final IntPropertyMap<Link> feature=edgeIntFeatureMap.get(featureKey);
            feature.set(link,val);
          }
        }
      }
    }
    return new TrackMateModel(model,spotDoubleFeatureMap,spotIntFeatureMap,edgeDoubleFeatureMap,edgeIntFeatureMap);
  }
  finally {
    graph.releaseRef(ref);
    graph.releaseRef(putRef);
    graph.releaseRef(sourceRef);
    graph.releaseRef(targetRef);
    graph.releaseRef(edgeRef);
  }
}