Program: 147130
Project: 147130
Buggy source:
/** 
 * update Method is called whenever a model is added, removed and/or moved in the GUI Observable should be of type OpenSimDB.
 */
public void update(Observable o,Object arg){
  if (arg instanceof JSONObject) {
    handleJson((JSONObject)arg);
  }
  if (o instanceof VisWebSocket) {
    getInstance().sync((VisWebSocket)o);
    if (currentJson == null)     setCurrentJson();
    return;
  }
  if (o instanceof OpenSimDB) {
    if (arg instanceof ObjectsAddedEvent) {
      ObjectsAddedEvent ev=(ObjectsAddedEvent)arg;
      Vector<OpenSimObject> objs=ev.getObjects();
      for (int i=0; i < objs.size(); i++) {
        if (objs.get(i) instanceof Model) {
          assert(false);
        }
        if (objs.get(i) instanceof Marker) {
          SingleModelVisuals vis=mapModelsToVisuals.get(ev.getModel());
          repaintAll();
        }
      }
    }
 else     if (arg instanceof ObjectSetCurrentEvent) {
      clearSelectedObjects();
      ObjectSetCurrentEvent ev=(ObjectSetCurrentEvent)arg;
      Vector<OpenSimObject> objs=ev.getObjects();
      for (int i=0; i < objs.size(); i++) {
        if (objs.get(i) instanceof Model) {
          Model currentModel=(Model)objs.get(i);
          Enumeration<Model> models=mapModelsToVisuals.keys();
          while (models.hasMoreElements()) {
            Model next=models.nextElement();
            double nominalOpacity=modelOpacities.get(next);
            SingleModelVisuals vis=mapModelsToVisuals.get(next);
            if (next == currentModel) {
              setObjectOpacity(next,nominalOpacity);
              vis.setPickable(true);
            }
 else {
              setObjectOpacity(next,getNonCurrentModelOpacity() * nominalOpacity);
              vis.setPickable(false);
            }
          }
          setCurrentJson();
          break;
        }
      }
    }
 else     if (arg instanceof ObjectsDeletedEvent) {
      handleObjectsDeletedEvent(arg);
    }
 else     if (arg instanceof ObjectEnabledStateChangeEvent) {
      handleObjectsEnabledStateChangeEvent(arg);
    }
 else     if (arg instanceof ObjectsRenamedEvent) {
      ObjectsRenamedEvent ev=(ObjectsRenamedEvent)arg;
      statusDisplaySelectedObjects();
      repaintAll();
      Vector<OpenSimObject> objs=ev.getObjects();
      for (int i=0; i < objs.size(); i++) {
        if (objs.get(i) instanceof Actuator) {
        }
 else         if (objs.get(i) instanceof Marker) {
        }
      }
    }
 else     if (arg instanceof ModelEvent) {
      ModelEvent ev=(ModelEvent)arg;
      if (ev.getOperation() == ModelEvent.Operation.Open) {
        Model evModel=ev.getModel();
        processSavedSettings(evModel);
        try {
          createNewViewWindowIfNeeded();
        }
 catch (        UnsatisfiedLinkError e) {
          setGraphicsAvailable(false);
        }
        if (isVtkGraphicsAvailable()) {
          SingleModelVisuals newModelVisual=(evModel instanceof ModelForExperimentalData) ? new ExperimentalDataVisuals(evModel) : new SingleModelVisuals(evModel);
          mapModelsToVisuals.put(evModel,newModelVisual);
          getModelVisuals().add(newModelVisual);
          modelOpacities.put(evModel,1.0);
          addVisObjectToAllViews();
          vtkMatrix4x4 m=(evModel instanceof ModelForExperimentalData) ? new vtkMatrix4x4() : getInitialTransform(newModelVisual);
          newModelVisual.getModelDisplayAssembly().SetUserMatrix(m);
          sceneAssembly.AddPart(newModelVisual.getModelDisplayAssembly());
        }
        if (websocketdb != null) {
          ModelVisualizationJson vizJson=new ModelVisualizationJson(jsondb,evModel);
          getInstance().addModelVisuals(evModel,vizJson);
          exportModelJsonToVisualizer(vizJson,null);
          mapModelsToJsons.put(evModel,vizJson);
        }
 else {
          VisualizerWindowAction.openVisualizerWindow();
        }
        if (OpenSimDB.getInstance().getNumModels() == 1) {
          Iterator<ModelWindowVTKTopComponent> windowIter=openWindows.iterator();
          double[] bnds=new double[6];
          while (windowIter.hasNext()) {
            bnds=computeSceneBounds();
            ModelWindowVTKTopComponent nextWindow=windowIter.next();
            lockDrawingSurfaces(true);
            nextWindow.getCanvas().GetRenderer().ResetCamera(bnds);
            lockDrawingSurfaces(false);
          }
        }
        repaintAll();
      }
 else       if (ev.getOperation() == ModelEvent.Operation.Close) {
        Model dModel=ev.getModel();
        mapModelsToSettings.remove(dModel);
        removeObjectsBelongingToModelFromSelection(dModel);
        SingleModelVisuals visModel=mapModelsToVisuals.get(dModel);
        if (visModel != null) {
          removeObjectFromScene(visModel.getModelDisplayAssembly());
          modelVisuals.remove(visModel);
        }
        removeAnnotationObjects(dModel);
        mapModelsToVisuals.remove(dModel);
        modelOpacities.remove(dModel);
        if (visModel != null)         visModel.cleanup();
        if (websocketdb != null) {
          ModelVisualizationJson dJson=mapModelsToJsons.get(dModel);
          JSONObject msg=dJson.createCloseModelJson();
          websocketdb.broadcastMessageJson(msg,null);
          System.out.println(msg.toJSONString());
          UUID modelUUID=dJson.getModelUUID();
          mapModelsToJsons.remove(dModel);
        }
      }
 else       if (ev.getOperation() == ModelEvent.Operation.SetCurrent) {
        Enumeration<Model> models=mapModelsToVisuals.keys();
        while (models.hasMoreElements()) {
          Model next=models.nextElement();
          double nominalOpacity=modelOpacities.get(next);
          SingleModelVisuals vis=mapModelsToVisuals.get(next);
          if (next == ev.getModel()) {
            setObjectOpacity(next,nominalOpacity);
          }
 else {
            setObjectOpacity(next,getNonCurrentModelOpacity() * nominalOpacity);
          }
        }
        if (websocketdb != null) {
          Model cModel=ev.getModel();
          currentJson=mapModelsToJsons.get(cModel);
          JSONObject msg=currentJson.createSetCurrentModelJson();
          websocketdb.broadcastMessageJson(msg,null);
          System.out.println(msg.toJSONString());
        }
      }
 else       if (ev.getOperation() == ModelEvent.Operation.Save) {
        updateSettingsSerializer(ev.getModel());
      }
    }
  }
}

Fixed version (ground truth):
/** 
 * update Method is called whenever a model is added, removed and/or moved in the GUI Observable should be of type OpenSimDB.
 */
public void update(Observable o,Object arg){
  if (arg instanceof JSONObject) {
    handleJson((JSONObject)arg);
  }
  if (o instanceof VisWebSocket) {
    getInstance().sync((VisWebSocket)o);
    if (currentJson == null)     setCurrentJson();
    return;
  }
  if (o instanceof OpenSimDB) {
    if (arg instanceof ObjectsAddedEvent) {
      ObjectsAddedEvent ev=(ObjectsAddedEvent)arg;
      Vector<OpenSimObject> objs=ev.getObjects();
      for (int i=0; i < objs.size(); i++) {
        if (objs.get(i) instanceof Model) {
          assert(false);
        }
        if (objs.get(i) instanceof Marker) {
          SingleModelVisuals vis=mapModelsToVisuals.get(ev.getModel());
          repaintAll();
        }
      }
    }
 else     if (arg instanceof ObjectSetCurrentEvent) {
      clearSelectedObjects();
      ObjectSetCurrentEvent ev=(ObjectSetCurrentEvent)arg;
      Vector<OpenSimObject> objs=ev.getObjects();
      for (int i=0; i < objs.size(); i++) {
        if (objs.get(i) instanceof Model) {
          Model currentModel=(Model)objs.get(i);
          Enumeration<Model> models=mapModelsToVisuals.keys();
          while (models.hasMoreElements()) {
            Model next=models.nextElement();
            double nominalOpacity=modelOpacities.get(next);
            SingleModelVisuals vis=mapModelsToVisuals.get(next);
            if (next == currentModel) {
              setObjectOpacity(next,nominalOpacity);
              vis.setPickable(true);
            }
 else {
              setObjectOpacity(next,getNonCurrentModelOpacity() * nominalOpacity);
              vis.setPickable(false);
            }
          }
          setCurrentJson();
          break;
        }
      }
    }
 else     if (arg instanceof ObjectsDeletedEvent) {
      handleObjectsDeletedEvent(arg);
    }
 else     if (arg instanceof ObjectEnabledStateChangeEvent) {
      handleObjectsEnabledStateChangeEvent(arg);
    }
 else     if (arg instanceof ObjectsRenamedEvent) {
      ObjectsRenamedEvent ev=(ObjectsRenamedEvent)arg;
      statusDisplaySelectedObjects();
      repaintAll();
      Vector<OpenSimObject> objs=ev.getObjects();
      for (int i=0; i < objs.size(); i++) {
        if (objs.get(i) instanceof Actuator) {
        }
 else         if (objs.get(i) instanceof Marker) {
        }
      }
    }
 else     if (arg instanceof ModelEvent) {
      ModelEvent ev=(ModelEvent)arg;
      if (ev.getOperation() == ModelEvent.Operation.Open) {
        Model evModel=ev.getModel();
        processSavedSettings(evModel);
        try {
          createNewViewWindowIfNeeded();
        }
 catch (        UnsatisfiedLinkError e) {
          setGraphicsAvailable(false);
        }
        if (isVtkGraphicsAvailable()) {
          SingleModelVisuals newModelVisual=(evModel instanceof ModelForExperimentalData) ? new ExperimentalDataVisuals(evModel) : new SingleModelVisuals(evModel);
          mapModelsToVisuals.put(evModel,newModelVisual);
          getModelVisuals().add(newModelVisual);
          modelOpacities.put(evModel,1.0);
          addVisObjectToAllViews();
          vtkMatrix4x4 m=(evModel instanceof ModelForExperimentalData) ? new vtkMatrix4x4() : getInitialTransform(newModelVisual);
          newModelVisual.getModelDisplayAssembly().SetUserMatrix(m);
          sceneAssembly.AddPart(newModelVisual.getModelDisplayAssembly());
        }
        if (websocketdb != null) {
          if (debugLevel > 1)           System.out.println("String_Node_Str");
          ModelVisualizationJson vizJson=createJsonFroModel(jsondb,evModel);
          exportModelJsonToVisualizer(vizJson,null);
        }
 else {
          VisualizerWindowAction.openVisualizerWindow();
        }
        if (OpenSimDB.getInstance().getNumModels() == 1) {
          Iterator<ModelWindowVTKTopComponent> windowIter=openWindows.iterator();
          double[] bnds=new double[6];
          while (windowIter.hasNext()) {
            bnds=computeSceneBounds();
            ModelWindowVTKTopComponent nextWindow=windowIter.next();
            lockDrawingSurfaces(true);
            nextWindow.getCanvas().GetRenderer().ResetCamera(bnds);
            lockDrawingSurfaces(false);
          }
        }
        repaintAll();
      }
 else       if (ev.getOperation() == ModelEvent.Operation.Close) {
        Model dModel=ev.getModel();
        mapModelsToSettings.remove(dModel);
        removeObjectsBelongingToModelFromSelection(dModel);
        SingleModelVisuals visModel=mapModelsToVisuals.get(dModel);
        if (visModel != null) {
          removeObjectFromScene(visModel.getModelDisplayAssembly());
          modelVisuals.remove(visModel);
        }
        removeAnnotationObjects(dModel);
        mapModelsToVisuals.remove(dModel);
        modelOpacities.remove(dModel);
        if (visModel != null)         visModel.cleanup();
        if (websocketdb != null) {
          ModelVisualizationJson dJson=mapModelsToJsons.get(dModel);
          JSONObject msg=dJson.createCloseModelJson();
          websocketdb.broadcastMessageJson(msg,null);
          if (debugLevel > 1)           System.out.println(msg.toJSONString());
          UUID modelUUID=dJson.getModelUUID();
          mapModelsToJsons.remove(dModel);
        }
      }
 else       if (ev.getOperation() == ModelEvent.Operation.SetCurrent) {
        Enumeration<Model> models=mapModelsToVisuals.keys();
        while (models.hasMoreElements()) {
          Model next=models.nextElement();
          double nominalOpacity=modelOpacities.get(next);
          SingleModelVisuals vis=mapModelsToVisuals.get(next);
          if (next == ev.getModel()) {
            setObjectOpacity(next,nominalOpacity);
          }
 else {
            setObjectOpacity(next,getNonCurrentModelOpacity() * nominalOpacity);
          }
        }
        if (websocketdb != null) {
          Model cModel=ev.getModel();
          currentJson=mapModelsToJsons.get(cModel);
          JSONObject msg=currentJson.createSetCurrentModelJson();
          websocketdb.broadcastMessageJson(msg,null);
          if (debugLevel > 1)           System.out.println(msg.toJSONString());
        }
      }
 else       if (ev.getOperation() == ModelEvent.Operation.Save) {
        updateSettingsSerializer(ev.getModel());
      }
    }
  }
}