Program: 38909
Project: 38909
Buggy source:
@Override public void findMaximalFlowTap(Network network,String phaseShifterId){
  TwoWindingsTransformer phaseShifter=network.getTwoWindingsTransformer(phaseShifterId);
  if (phaseShifter == null) {
    throw new RuntimeException("String_Node_Str" + phaseShifterId + "String_Node_Str");
  }
  if (phaseShifter.getPhaseTapChanger() == null) {
    throw new RuntimeException("String_Node_Str" + phaseShifterId + "String_Node_Str");
  }
  int optimalTap;
  String stateId=network.getStateManager().getWorkingStateId();
  String tmpStateId="String_Node_Str" + UUID.randomUUID();
  network.getStateManager().cloneState(stateId,tmpStateId);
  try {
    network.getStateManager().setWorkingState(tmpStateId);
    LoadFlowFactory loadFlowFactory=config.getLoadFlowFactoryClass().newInstance();
    LoadFlow loadFlow=loadFlowFactory.create(network,computationManager,0);
    runLoadFlow(loadFlow);
    if (phaseShifter.getTerminal1().getP() >= phaseShifter.getCurrentLimits1().getPermanentLimit()) {
      throw new RuntimeException("String_Node_Str");
    }
    int tapPosInc=1;
    float i;
    float limit=getLimit(phaseShifter);
    int tapPos=phaseShifter.getPhaseTapChanger().getTapPosition();
    int maxTap=phaseShifter.getPhaseTapChanger().getHighTapPosition();
    while ((i=getI(phaseShifter)) < limit && tapPos < maxTap) {
      tapPos+=tapPosInc;
      phaseShifter.getPhaseTapChanger().setTapPosition(tapPos);
      runLoadFlow(loadFlow);
      if (getI(phaseShifter) < i) {
        tapPosInc*=-1;
      }
    }
    if (i < limit) {
      optimalTap=phaseShifter.getPhaseTapChanger().getTapPosition();
    }
 else {
      optimalTap=phaseShifter.getPhaseTapChanger().getTapPosition() - tapPosInc;
      phaseShifter.getPhaseTapChanger().setTapPosition(optimalTap);
      runLoadFlow(loadFlow);
      if (getI(phaseShifter) >= limit) {
        throw new AssertionError("String_Node_Str");
      }
    }
  }
 catch (  IllegalAccessException e) {
    throw new UncheckedIllegalAccessException(e);
  }
catch (  InstantiationException e) {
    throw new UncheckedInstantiationException(e);
  }
 finally {
    network.getStateManager().removeState(tmpStateId);
    network.getStateManager().setWorkingState(stateId);
  }
  LOGGER.debug("String_Node_Str",phaseShifter,optimalTap,phaseShifter.getPhaseTapChanger().getTapPosition());
  phaseShifter.getPhaseTapChanger().setTapPosition(optimalTap);
}

Fixed version (ground truth):
@Override public void findMaximalFlowTap(Network network,String phaseShifterId){
  TwoWindingsTransformer phaseShifter=network.getTwoWindingsTransformer(phaseShifterId);
  if (phaseShifter == null) {
    throw new RuntimeException("String_Node_Str" + phaseShifterId + "String_Node_Str");
  }
  if (phaseShifter.getPhaseTapChanger() == null) {
    throw new RuntimeException("String_Node_Str" + phaseShifterId + "String_Node_Str");
  }
  int optimalTap;
  String stateId=network.getStateManager().getWorkingStateId();
  String tmpStateId="String_Node_Str" + UUID.randomUUID();
  network.getStateManager().cloneState(stateId,tmpStateId);
  try {
    network.getStateManager().setWorkingState(tmpStateId);
    LoadFlowFactory loadFlowFactory=config.getLoadFlowFactoryClass().newInstance();
    LoadFlow loadFlow=loadFlowFactory.create(network,computationManager,0);
    runLoadFlow(loadFlow);
    if (phaseShifter.getTerminal1().getI() >= phaseShifter.getCurrentLimits1().getPermanentLimit()) {
      throw new RuntimeException("String_Node_Str");
    }
    int tapPosInc=1;
    float i;
    float limit=getLimit(phaseShifter);
    int tapPos=phaseShifter.getPhaseTapChanger().getTapPosition();
    int maxTap=phaseShifter.getPhaseTapChanger().getHighTapPosition();
    while ((i=getI(phaseShifter)) < limit && tapPos < maxTap) {
      tapPos+=tapPosInc;
      phaseShifter.getPhaseTapChanger().setTapPosition(tapPos);
      runLoadFlow(loadFlow);
      if (getI(phaseShifter) < i) {
        tapPosInc*=-1;
      }
    }
    if (i < limit) {
      optimalTap=phaseShifter.getPhaseTapChanger().getTapPosition();
    }
 else {
      optimalTap=phaseShifter.getPhaseTapChanger().getTapPosition() - tapPosInc;
      phaseShifter.getPhaseTapChanger().setTapPosition(optimalTap);
      runLoadFlow(loadFlow);
      if (getI(phaseShifter) >= limit) {
        throw new AssertionError("String_Node_Str");
      }
    }
  }
 catch (  IllegalAccessException e) {
    throw new UncheckedIllegalAccessException(e);
  }
catch (  InstantiationException e) {
    throw new UncheckedInstantiationException(e);
  }
 finally {
    network.getStateManager().removeState(tmpStateId);
    network.getStateManager().setWorkingState(stateId);
  }
  LOGGER.debug("String_Node_Str",phaseShifter,optimalTap,phaseShifter.getPhaseTapChanger().getTapPosition());
  phaseShifter.getPhaseTapChanger().setTapPosition(optimalTap);
}