Program: 91986
Project: 91986
Buggy source:
/** 
 * Copies the values of a parameter group into another parameter group. All values in the   {@code source} group shall be valid for the {@code destination} group,but the  {@code destination} may have more parameters.Sub-groups are copied recursively. <p>A typical usage of this method is for transferring values from an arbitrary implementation to some specific implementation, or to a parameter group using a different but compatible {@linkplain DefaultParameterValueGroup#getDescriptor() descriptor}.</p>
 * @param values The parameters values to copy.
 * @param destination Where to copy the values.
 * @throws InvalidParameterNameException if a {@code source} parameter name is unknown to the {@code destination}.
 * @throws InvalidParameterValueException if the value of a {@code source} parameter is invalid for the {@code destination}.
 * @see #clone()
 * @since 0.5
 */
public static void copy(final ParameterValueGroup values,final ParameterValueGroup destination) throws InvalidParameterNameException, InvalidParameterValueException {
  final Integer ZERO=0;
  final Map<String,Integer> occurrences=new HashMap<>();
  for (  final GeneralParameterValue value : values.values()) {
    final String name=value.getDescriptor().getName().getCode();
    final int occurrence=occurrences.getOrDefault(name,ZERO);
    if (value instanceof ParameterValueGroup) {
      final List<ParameterValueGroup> groups=destination.groups(name);
      copy((ParameterValueGroup)value,(occurrence < groups.size()) ? groups.get(occurrence) : destination.addGroup(name));
    }
 else {
      final ParameterValue<?> source=(ParameterValue<?>)value;
      final ParameterValue<?> target;
      if (occurrence == 0) {
        try {
          target=destination.parameter(name);
        }
 catch (        ParameterNotFoundException cause) {
          throw new InvalidParameterNameException(Errors.format(Errors.Keys.UnexpectedParameter_1,name),cause,name);
        }
      }
 else {
        target=(ParameterValue<?>)getOrCreate(destination,name,occurrence);
      }
      final Object v=source.getValue();
      final Unit<?> unit=source.getUnit();
      if (unit == null) {
        target.setValue(v);
      }
 else       if (v instanceof Number) {
        target.setValue(((Number)v).doubleValue(),unit);
      }
 else       if (v instanceof double[]) {
        target.setValue((double[])v,unit);
      }
 else {
        throw new InvalidParameterValueException(Errors.format(Errors.Keys.IllegalArgumentValue_2,name,v),name,v);
      }
    }
    occurrences.put(name,occurrence + 1);
  }
}

Fixed version (ground truth):
/** 
 * Copies the values of a parameter group into another parameter group. All values in the   {@code source} group shall be valid for the {@code destination} group,but the  {@code destination} may have more parameters.Sub-groups are copied recursively. <p>A typical usage of this method is for transferring values from an arbitrary implementation to some specific implementation, or to a parameter group using a different but compatible {@linkplain DefaultParameterValueGroup#getDescriptor() descriptor}.</p>
 * @param values The parameters values to copy.
 * @param destination Where to copy the values.
 * @throws InvalidParameterNameException if a {@code source} parameter name is unknown to the {@code destination}.
 * @throws InvalidParameterValueException if the value of a {@code source} parameter is invalid for the {@code destination}.
 * @see #clone()
 * @since 0.5
 */
public static void copy(final ParameterValueGroup values,final ParameterValueGroup destination) throws InvalidParameterNameException, InvalidParameterValueException {
  final Integer ZERO=0;
  final Map<String,Integer> occurrences=new HashMap<>();
  for (  final GeneralParameterValue value : values.values()) {
    final String name=value.getDescriptor().getName().getCode();
    final int occurrence=occurrences.getOrDefault(name,ZERO);
    if (value instanceof ParameterValueGroup) {
      final List<ParameterValueGroup> groups=destination.groups(name);
      copy((ParameterValueGroup)value,(occurrence < groups.size()) ? groups.get(occurrence) : destination.addGroup(name));
    }
 else {
      final ParameterValue<?> source=(ParameterValue<?>)value;
      final ParameterValue<?> target;
      if (occurrence == 0) {
        try {
          target=destination.parameter(name);
        }
 catch (        ParameterNotFoundException cause) {
          throw new InvalidParameterNameException(Errors.format(Errors.Keys.UnexpectedParameter_1,name),cause,name);
        }
      }
 else {
        target=(ParameterValue<?>)getOrCreate(destination,name,occurrence);
      }
      final Object v=source.getValue();
      final Unit<?> unit=source.getUnit();
      if (unit == null) {
        target.setValue(v);
      }
 else       if (v instanceof Number) {
        target.setValue(((Number)v).doubleValue(),unit);
      }
 else       if (v instanceof double[]) {
        target.setValue((double[])v,unit);
      }
 else       if (v != target.getValue()) {
        throw new InvalidParameterValueException(Errors.format(Errors.Keys.IllegalArgumentValue_2,name,v),name,v);
      }
    }
    occurrences.put(name,occurrence + 1);
  }
}