Program: 91889
Project: 91889
Buggy source:
/** 
 * Performs the part of   {@code DefaultConcatenatedOperations} construction that requires an iteration overthe sequence of coordinate operations. This method performs the following processing: <ul> <li>Verify the validity of the  {@code operations} argument.</li><li>Add the single operations in the  {@code flattened} array.</li><li>Set the  {@link #transform} field to the concatenated transform.</li><li>Set the  {@link #coordinateOperationAccuracy} field, but only if {@code setAccuracy} is {@code true}.</li> </ul> This method invokes itself recursively if there is nested   {@code ConcatenatedOperation} instancesin the given list. This should not happen according ISO 19111 standard, but we try to be safe. <div class="section">How coordinate operation accuracy is determined</div> If  {@code setAccuracy} is {@code true}, then this method copies accuracy information found in the single  {@link Transformation} instance. This method ignores instances of other kinds for the following reason:some  {@link Conversion} instances declare an accuracy, which is typically close to zero. If a concatenatedoperation contains such conversion together with a transformation with unknown accuracy, then we do not want to declare "0 meter" as the concatenated operation accuracy; it would be a false information. An other reason is that a concatenated operation typically contains an arbitrary amount of conversions, but only one transformation. So considering only transformations usually means to pickup only one operation in the given  {@code operations} list, which make things clearer.<div class="note"><b>Note:</b> according ISO 19111, the accuracy attribute is allowed only for transformations. However this restriction is not enforced everywhere. For example the EPSG database declares an accuracy of 0 meter for conversions, which is conceptually exact. In this class we are departing from strict interpretation of the specification since we are adding accuracy informations to a concatenated operation. This departure should be considered as a convenience feature only; accuracies are really relevant in transformations only.</div>
 * @param properties  The properties specified at construction time, or {@code null} if unknown.
 * @param operations  The operations to concatenate.
 * @param flattened   The destination list in which to add the {@code SingleOperation} instances.
 * @param mtFactory   The math transform factory to use, or {@code null} for not performing concatenation.
 * @param setAccuracy {@code true} for setting the {@link #coordinateOperationAccuracy} field.
 * @throws FactoryException if the factory can not concatenate the math transforms.
 */
private void initialize(final Map<String,?> properties,final CoordinateOperation[] operations,final List<CoordinateOperation> flattened,final MathTransformFactory mtFactory,boolean setAccuracy) throws FactoryException {
  CoordinateReferenceSystem previous=null;
  for (int i=0; i < operations.length; i++) {
    final CoordinateOperation op=operations[i];
    ArgumentChecks.ensureNonNullElement("String_Node_Str",i,op);
    if (previous != null) {
      final CoordinateReferenceSystem next=op.getSourceCRS();
      if (next != null) {
        final int dim1=previous.getCoordinateSystem().getDimension();
        final int dim2=next.getCoordinateSystem().getDimension();
        if (dim1 != dim2) {
          throw new IllegalArgumentException(Errors.getResources(properties).getString(Errors.Keys.MismatchedDimension_3,"String_Node_Str" + i + "String_Node_Str",dim1,dim2));
        }
      }
    }
    previous=op.getTargetCRS();
    MathTransform step=op.getMathTransform();
    if (op instanceof ConcatenatedOperation) {
      final List<? extends CoordinateOperation> children=((ConcatenatedOperation)op).getOperations();
      @SuppressWarnings("String_Node_Str") final CoordinateOperation[] asArray=children.toArray(new CoordinateOperation[children.size()]);
      initialize(properties,asArray,flattened,(step == null) ? mtFactory : null,setAccuracy);
    }
 else {
      flattened.add(op);
    }
    if (mtFactory != null) {
      transform=(transform != null) ? mtFactory.createConcatenatedTransform(transform,step) : step;
    }
    if (setAccuracy && (op instanceof Transformation || op instanceof ConcatenatedOperation)) {
      if (coordinateOperationAccuracy == null) {
        setAccuracy=(PositionalAccuracyConstant.getLinearAccuracy(op) > 0);
        if (setAccuracy) {
          coordinateOperationAccuracy=op.getCoordinateOperationAccuracy();
        }
      }
 else {
        coordinateOperationAccuracy=null;
        setAccuracy=false;
      }
    }
  }
}

Fixed version (ground truth):
/** 
 * Performs the part of   {@code DefaultConcatenatedOperations} construction that requires an iteration overthe sequence of coordinate operations. This method performs the following processing: <ul> <li>Verify the validity of the  {@code operations} argument.</li><li>Add the single operations in the  {@code flattened} array.</li><li>Set the  {@link #transform} field to the concatenated transform.</li><li>Set the  {@link #coordinateOperationAccuracy} field, but only if {@code setAccuracy} is {@code true}.</li> </ul> This method invokes itself recursively if there is nested   {@code ConcatenatedOperation} instancesin the given list. This should not happen according ISO 19111 standard, but we try to be safe. <div class="section">How coordinate operation accuracy is determined</div> If  {@code setAccuracy} is {@code true}, then this method copies accuracy information found in the single  {@link Transformation} instance. This method ignores instances of other kinds for the following reason:some  {@link Conversion} instances declare an accuracy, which is typically close to zero. If a concatenatedoperation contains such conversion together with a transformation with unknown accuracy, then we do not want to declare "0 meter" as the concatenated operation accuracy; it would be a false information. An other reason is that a concatenated operation typically contains an arbitrary amount of conversions, but only one transformation. So considering only transformations usually means to pickup only one operation in the given  {@code operations} list, which make things clearer.<div class="note"><b>Note:</b> according ISO 19111, the accuracy attribute is allowed only for transformations. However this restriction is not enforced everywhere. For example the EPSG database declares an accuracy of 0 meter for conversions, which is conceptually exact. In this class we are departing from strict interpretation of the specification since we are adding accuracy informations to a concatenated operation. This departure should be considered as a convenience feature only; accuracies are really relevant in transformations only.</div>
 * @param properties  The properties specified at construction time, or {@code null} if unknown.
 * @param operations  The operations to concatenate.
 * @param flattened   The destination list in which to add the {@code SingleOperation} instances.
 * @param mtFactory   The math transform factory to use, or {@code null} for not performing concatenation.
 * @param setAccuracy {@code true} for setting the {@link #coordinateOperationAccuracy} field.
 * @param setDomain   {@code true} for setting the {@link #domainOfValidity} field.
 * @throws FactoryException if the factory can not concatenate the math transforms.
 */
private void initialize(final Map<String,?> properties,final CoordinateOperation[] operations,final List<CoordinateOperation> flattened,final MathTransformFactory mtFactory,boolean setAccuracy,boolean setDomain) throws FactoryException {
  CoordinateReferenceSystem previous=null;
  for (int i=0; i < operations.length; i++) {
    final CoordinateOperation op=operations[i];
    ArgumentChecks.ensureNonNullElement("String_Node_Str",i,op);
    if (previous != null) {
      final CoordinateReferenceSystem next=op.getSourceCRS();
      if (next != null) {
        final int dim1=previous.getCoordinateSystem().getDimension();
        final int dim2=next.getCoordinateSystem().getDimension();
        if (dim1 != dim2) {
          throw new IllegalArgumentException(Errors.getResources(properties).getString(Errors.Keys.MismatchedDimension_3,"String_Node_Str" + i + "String_Node_Str",dim1,dim2));
        }
      }
    }
    previous=op.getTargetCRS();
    MathTransform step=op.getMathTransform();
    if (op instanceof ConcatenatedOperation) {
      final List<? extends CoordinateOperation> children=((ConcatenatedOperation)op).getOperations();
      @SuppressWarnings("String_Node_Str") final CoordinateOperation[] asArray=children.toArray(new CoordinateOperation[children.size()]);
      initialize(properties,asArray,flattened,(step == null) ? mtFactory : null,setAccuracy,setDomain);
    }
 else {
      flattened.add(op);
    }
    if (mtFactory != null) {
      transform=(transform != null) ? mtFactory.createConcatenatedTransform(transform,step) : step;
    }
    if (setAccuracy && (op instanceof Transformation || op instanceof ConcatenatedOperation) && (PositionalAccuracyConstant.getLinearAccuracy(op) != 0)) {
      if (coordinateOperationAccuracy == null) {
        coordinateOperationAccuracy=op.getCoordinateOperationAccuracy();
      }
 else {
        coordinateOperationAccuracy=null;
        setAccuracy=false;
      }
    }
    if (setDomain) {
      final Extent domain=op.getDomainOfValidity();
      if (domain != null) {
        if (domainOfValidity == null) {
          domainOfValidity=domain;
        }
 else         if (!domain.equals(domainOfValidity)) {
          domainOfValidity=null;
          setDomain=false;
        }
      }
    }
  }
}