Program: 93932
Project: 93932
Buggy source:
/** 
 * Calculates the dependencies of the supplied set of   {@link BundleDescription bundles}. <p/> Callers must supply a   {@link State} against which dependency satisfaction is executed. The supplied State isdestructively modified during constraint satisfaction so it <strong>must</strong> not be the system state. <p/> In a successful invocation, any new bundles that need to be installed are returned, and the supplied <code>State</code> is transformed to reflect the newly resolved state of the supplied bundles. Callers can query the <code>State</code> to find the fully wiring graph of the supplied bundles after successful constraint satisfaction. <p/> If diagnostics are forced, then an  {@link UnableToSatisfyDependenciesException} is thrown if the constraintscannot be satisfied. If diagnostics are not forced, then either an <code>UnableToSatisfyDependenciesException</code> is thrown or the new bundles that need to be installed are returned depending on whether cloning some bundles may improve the chances of satisfying the constraints.
 * @param state the <code>State</code> to satisfy against.
 * @param bundles the bundles to calculate dependencies for.
 * @return an array of descriptions of bundles that need to be added to the state to satisfy constraints.
 * @throws BundleException 
 * @throws UnableToSatisfyDependenciesException 
 */
public BundleDescription[] calculateDependencies(State state,BundleDescription[] bundles) throws BundleException, UnableToSatisfyDependenciesException {
  this.logger.info("String_Node_Str",bundles);
synchronized (this.monitor) {
    doSatisfyConstraints(bundles,state);
    StateDelta delta=state.resolve(bundles);
    for (    BundleDescription description : bundles) {
      if (!description.isResolved()) {
        generateDump(state);
        ResolverErrorsHolder reh=new ResolverErrorsHolder();
        String failure=this.detective.generateFailureDescription(state,description,reh);
        ResolverError[] resolverErrors=reh.getResolverErrors();
        if (resolverErrors != null) {
          for (          ResolverError resolverError : resolverErrors) {
            if (resolverError.getType() == ResolverError.IMPORT_PACKAGE_USES_CONFLICT) {
              VersionConstraint unsatisfiedConstraint=resolverError.getUnsatisfiedConstraint();
              if ((unsatisfiedConstraint instanceof ImportPackageSpecification)) {
                ImportPackageSpecification importPackageSpecification=(ImportPackageSpecification)unsatisfiedConstraint;
                this.logger.debug("String_Node_Str",new Object[]{importPackageSpecification.getName(),importPackageSpecification.getVersionRange(),importPackageSpecification.getBundleSymbolicName(),importPackageSpecification.getBundleVersionRange()});
              }
            }
          }
        }
        throw new UnableToSatisfyBundleDependenciesException(description.getSymbolicName(),description.getVersion(),failure,state,reh.getResolverErrors());
      }
    }
    BundleDelta[] deltas=delta.getChanges(BundleDelta.ADDED,false);
    Set<BundleDescription> newBundles=new HashSet<BundleDescription>();
    for (    BundleDelta bundleDelta : deltas) {
      newBundles.add(bundleDelta.getBundle());
    }
    Set<BundleDescription> dependenciesSet=getNewTransitiveDependencies(new HashSet<BundleDescription>(Arrays.asList(bundles)),newBundles);
    List<BundleDescription> dependencies=new ArrayList<BundleDescription>(dependenciesSet);
    this.logger.info("String_Node_Str",Arrays.toString(bundles),dependencies);
    Collections.sort(dependencies,new BundleDescriptionComparator());
    BundleDescription[] dependencyDescriptions=dependencies.toArray(new BundleDescription[dependencies.size()]);
    return dependencyDescriptions;
  }
}

Fixed version (ground truth):
/** 
 * Calculates the dependencies of the supplied set of   {@link BundleDescription bundles}. <p/> Callers must supply a   {@link State} against which dependency satisfaction is executed. The supplied State isdestructively modified during constraint satisfaction so it <strong>must</strong> not be the system state. <p/> In a successful invocation, any new bundles that need to be installed are returned, and the supplied <code>State</code> is transformed to reflect the newly resolved state of the supplied bundles. Callers can query the <code>State</code> to find the fully wiring graph of the supplied bundles after successful constraint satisfaction. <p/> If diagnostics are forced, then an  {@link UnableToSatisfyDependenciesException} is thrown if the constraintscannot be satisfied. If diagnostics are not forced, then either an <code>UnableToSatisfyDependenciesException</code> is thrown or the new bundles that need to be installed are returned depending on whether cloning some bundles may improve the chances of satisfying the constraints.
 * @param state the <code>State</code> to satisfy against.
 * @param bundles the bundles to calculate dependencies for.
 * @return an array of descriptions of bundles that need to be added to the state to satisfy constraints.
 * @throws BundleException
 * @throws UnableToSatisfyDependenciesException
 */
public BundleDescription[] calculateDependencies(State state,BundleDescription[] bundles) throws BundleException, UnableToSatisfyDependenciesException {
  this.logger.info("String_Node_Str",bundles);
synchronized (this.monitor) {
    doSatisfyConstraints(bundles,state);
    StateDelta delta=state.resolve(bundles);
    for (    BundleDescription description : bundles) {
      if (!description.isResolved()) {
        generateDump(state);
        ResolverErrorsHolder reh=new ResolverErrorsHolder();
        String failure=this.detective.generateFailureDescription(state,description,reh);
        ResolverError[] resolverErrors=reh.getResolverErrors();
        if (resolverErrors != null) {
          for (          ResolverError resolverError : resolverErrors) {
            if (resolverError.getType() == ResolverError.IMPORT_PACKAGE_USES_CONFLICT) {
              VersionConstraint unsatisfiedConstraint=resolverError.getUnsatisfiedConstraint();
              if ((unsatisfiedConstraint instanceof ImportPackageSpecification)) {
                ImportPackageSpecification importPackageSpecification=(ImportPackageSpecification)unsatisfiedConstraint;
                this.logger.debug("String_Node_Str",new Object[]{importPackageSpecification.getName(),importPackageSpecification.getVersionRange(),importPackageSpecification.getBundleSymbolicName(),importPackageSpecification.getBundleVersionRange()});
              }
            }
          }
        }
        throw new UnableToSatisfyBundleDependenciesException(description.getSymbolicName(),description.getVersion(),failure,state,reh.getResolverErrors());
      }
    }
    BundleDelta[] deltas=delta.getChanges(BundleDelta.ADDED,false);
    Set<BundleDescription> newBundles=new HashSet<BundleDescription>();
    for (    BundleDelta bundleDelta : deltas) {
      newBundles.add(bundleDelta.getBundle());
    }
    Set<BundleDescription> dependenciesSet=getNewTransitiveDependencies(new HashSet<BundleDescription>(Arrays.asList(bundles)),newBundles);
    List<BundleDescription> dependencies=new ArrayList<BundleDescription>(dependenciesSet);
    this.logger.info("String_Node_Str",Arrays.toString(bundles),dependencies);
    Collections.sort(dependencies,new BundleDescriptionComparator());
    BundleDescription[] dependencyDescriptions=dependencies.toArray(new BundleDescription[dependencies.size()]);
    return dependencyDescriptions;
  }
}