Program: 147135
Project: 147135
Buggy source:
/** 
 * Run an analysis to compute curves for muscle analyses operating on current model domainName is assumed to be set. If starts with Motion: then we assume we're plotting against a motion curve otherwise it's vs. Generalized coordinate of the current model
 */
void runAnalysisTool(PlotterSourceAnalysis source,PlotterSourceInterface motion,String[] ranges){
  AnalyzeTool tool=plotterModel.getAnalyzeTool(currentModel);
  if (motion instanceof PlotterSourceMotion || motion instanceof PlotterSourceStorage)   tool.setSolveForEquilibrium(!motion.hasFullState(currentModel));
 else   tool.setSolveForEquilibrium(true);
  PlotterSourceAnalysis analysisSource=(PlotterSourceAnalysis)source;
  plotterModel.configureAnalyses(tool,analysisSource,domainName,ranges);
  int numStates=currentModel.getNumStateVariables();
  ArrayStr stateNames=currentModel.getStateVariableNames();
  State saveState=openSimContext.getCurrentStateCopy();
  Storage extendedMotionStorage;
  int key=(int)(java.lang.Math.random() * 100);
  if (motion != null && motion instanceof PlotterSourceMotion) {
    tool.setStartTime(motion.getStorage().getFirstTime());
    tool.setFinalTime(motion.getStorage().getLastTime());
    statesStorage=buildStatesStorageFromMotion(motion.getStorage(),isActivationOverride(),getActivationValue());
    tool.setStatesStorage(statesStorage);
  }
 else {
    StatesReporter reporter=new StatesReporter(currentModel);
    reporter.begin(openSimContext.getCurrentStateRef());
    reporter.step(saveState,key);
    statesStorage=reporter.getStatesStorage();
    statesStorage.print("String_Node_Str");
    StateVector statevec=statesStorage.getStateVector(0);
    ArrayDouble statesForAnalysis=new ArrayDouble(statevec.getData());
    setNonzeroDefaultValues(stateNames,statesForAnalysis,isActivationOverride(),getActivationValue());
    double NUM_STEPS=100.0;
    Coordinate coord=currentModel.getCoordinateSet().get(domainName);
    int xIndex=statesStorage.getStateIndex(getDomainName());
    double domStart=(Double)jDomainStartTextField.getValue();
    double domEnd=(Double)jDomainEndTextField.getValue();
    if (coord.getMotionType() == Coordinate.MotionType.Rotational) {
      domStart=Math.toRadians(domStart);
      if (domStart < coord.getRangeMin())       domStart=coord.getRangeMin();
      domEnd=Math.toRadians(domEnd);
      if (domEnd > coord.getRangeMax())       domEnd=coord.getRangeMax();
    }
    for (int i=0; i < NUM_STEPS; i++) {
      double time=(double)i;
      double increment=1. / (NUM_STEPS - 1) * (domEnd - domStart);
      double val=domStart + increment * i;
      statesForAnalysis.set(xIndex,val);
      StateVector newVector=new StateVector();
      newVector.setStates(time,statesForAnalysis.getAsVector());
      statesStorage.append(newVector);
    }
    tool.setStatesStorage(statesStorage);
    tool.setStartTime(0.);
    tool.setFinalTime(NUM_STEPS);
    sourceX=new PlotterSourceAnalysis(currentModel,statesStorage,"String_Node_Str");
    tool.setModelFilename(currentModel.getInputFileName());
  }
  tool.setPrintResultFiles(false);
  try {
    tool.run(true);
  }
 catch (  IOException ex) {
    ex.printStackTrace();
  }
  openSimContext.setState(saveState);
  int na=currentModel.getAnalysisSet().getSize();
  Analysis analysis=currentModel.getAnalysisSet().get("String_Node_Str");
  analysisSource.updateStorage(analysis);
  currentModel.getSimbodyEngine().convertRadiansToDegrees(analysisSource.getStorage());
  currentModel.getSimbodyEngine().convertRadiansToDegrees(statesStorage);
  ArrayStr coordsArray=new ArrayStr();
  coordsArray.append("String_Node_Str");
  MuscleAnalysis.safeDownCast(analysis).setCoordinates(coordsArray);
}

Fixed version (ground truth):
/** 
 * Run an analysis to compute curves for muscle analyses operating on current model domainName is assumed to be set. If starts with Motion: then we assume we're plotting against a motion curve otherwise it's vs. Generalized coordinate of the current model
 */
void runAnalysisTool(PlotterSourceAnalysis source,PlotterSourceInterface motion,String[] ranges){
  AnalyzeTool tool=plotterModel.getAnalyzeTool(currentModel);
  if (motion instanceof PlotterSourceMotion || motion instanceof PlotterSourceStorage)   tool.setSolveForEquilibrium(!motion.hasFullState(currentModel));
 else   tool.setSolveForEquilibrium(true);
  PlotterSourceAnalysis analysisSource=(PlotterSourceAnalysis)source;
  plotterModel.configureAnalyses(tool,analysisSource,domainName,ranges);
  int numStates=currentModel.getNumStateVariables();
  ArrayStr stateNames=currentModel.getStateVariableNames();
  State saveState=openSimContext.getCurrentStateCopy();
  Storage extendedMotionStorage;
  int key=(int)(java.lang.Math.random() * 100);
  if (motion != null && motion instanceof PlotterSourceMotion) {
    tool.setStartTime(motion.getStorage().getFirstTime());
    tool.setFinalTime(motion.getStorage().getLastTime());
    statesStorage=buildStatesStorageFromMotion(motion.getStorage(),isActivationOverride(),getActivationValue());
    tool.setStatesStorage(statesStorage);
  }
 else {
    StatesReporter reporter=new StatesReporter(currentModel);
    reporter.begin(openSimContext.getCurrentStateRef());
    reporter.step(saveState,key);
    statesStorage=(Storage)reporter.getStatesStorage().clone();
    statesStorage.print("String_Node_Str");
    StateVector statevec=statesStorage.getStateVector(0);
    ArrayDouble statesForAnalysis=new ArrayDouble(statevec.getData());
    setNonzeroDefaultValues(stateNames,statesForAnalysis,isActivationOverride(),getActivationValue());
    double NUM_STEPS=100.0;
    Coordinate coord=currentModel.getCoordinateSet().get(domainName);
    int xIndex=statesStorage.getStateIndex(getDomainName());
    double domStart=(Double)jDomainStartTextField.getValue();
    double domEnd=(Double)jDomainEndTextField.getValue();
    if (coord.getMotionType() == Coordinate.MotionType.Rotational) {
      domStart=Math.toRadians(domStart);
      if (domStart < coord.getRangeMin())       domStart=coord.getRangeMin();
      domEnd=Math.toRadians(domEnd);
      if (domEnd > coord.getRangeMax())       domEnd=coord.getRangeMax();
    }
    for (int i=0; i < NUM_STEPS; i++) {
      double time=(double)i;
      double increment=1. / (NUM_STEPS - 1) * (domEnd - domStart);
      double val=domStart + increment * i;
      statesForAnalysis.set(xIndex,val);
      StateVector newVector=new StateVector();
      newVector.setStates(time,statesForAnalysis.getAsVector());
      statesStorage.append(newVector);
    }
    tool.setStatesStorage(statesStorage);
    tool.setStartTime(0.);
    tool.setFinalTime(NUM_STEPS);
    sourceX=new PlotterSourceAnalysis(currentModel,statesStorage,"String_Node_Str");
    tool.setModelFilename(currentModel.getInputFileName());
  }
  tool.setPrintResultFiles(false);
  try {
    tool.run(true);
  }
 catch (  IOException ex) {
    ex.printStackTrace();
  }
  openSimContext.realizeVelocity();
  MuscleAnalysis analysis=MuscleAnalysis.safeDownCast(currentModel.getAnalysisSet().get("String_Node_Str"));
  analysisSource.updateStorage(analysis);
  currentModel.getSimbodyEngine().convertRadiansToDegrees(analysisSource.getStorage());
  currentModel.getSimbodyEngine().convertRadiansToDegrees(statesStorage);
  ArrayStr coordsArray=new ArrayStr();
  coordsArray.append("String_Node_Str");
  analysis.setCoordinates(coordsArray);
}