Program: 110780
Project: 110780
Buggy source:
private static RuleConfiguredTargetBuilder init(RuleContext ruleContext,NestedSetBuilder<Artifact> filesBuilder,ResourceDependencies resourceDeps,JavaCommon javaCommon,AndroidCommon androidCommon,JavaSemantics javaSemantics,AndroidSemantics androidSemantics) throws InterruptedException, RuleErrorException {
  validateRuleContext(ruleContext);
  Multimap<String,TransitiveInfoCollection> depsByArchitecture=MultimapBuilder.treeKeys().arrayListValues().build();
  AndroidConfiguration androidConfig=ruleContext.getFragment(AndroidConfiguration.class);
  for (  Map.Entry<Optional<String>,? extends List<? extends TransitiveInfoCollection>> entry : ruleContext.getSplitPrerequisites("String_Node_Str").entrySet()) {
    String cpu=entry.getKey().or(androidConfig.getCpu());
    depsByArchitecture.putAll(cpu,entry.getValue());
  }
  Map<String,BuildConfiguration> configurationMap=new LinkedHashMap<>();
  Map<String,CcToolchainProvider> toolchainMap=new LinkedHashMap<>();
  for (  Map.Entry<Optional<String>,? extends List<? extends TransitiveInfoCollection>> entry : ruleContext.getSplitPrerequisites("String_Node_Str").entrySet()) {
    String cpu=entry.getKey().or(androidConfig.getCpu());
    TransitiveInfoCollection dep=Iterables.getOnlyElement(entry.getValue());
    CcToolchainProvider toolchain=CppHelper.getToolchain(ruleContext,dep);
    configurationMap.put(cpu,dep.getConfiguration());
    toolchainMap.put(cpu,toolchain);
  }
  NativeLibs nativeLibs=NativeLibs.fromLinkedNativeDeps(ruleContext,androidSemantics.getNativeDepsFileName(),depsByArchitecture,toolchainMap,configurationMap);
  ApplicationManifest applicationManifest;
  ResourceApk resourceApk;
  ResourceApk incrementalResourceApk;
  ResourceApk instantRunResourceApk;
  ResourceApk splitResourceApk;
  if (LocalResourceContainer.definesAndroidResources(ruleContext.attributes())) {
    LocalResourceContainer.validateRuleContext(ruleContext);
    ApplicationManifest ruleManifest=androidSemantics.getManifestForRule(ruleContext);
    applicationManifest=ruleManifest.mergeWith(ruleContext,resourceDeps);
    Artifact featureOfArtifact=ruleContext.attributes().isAttributeValueExplicitlySpecified("String_Node_Str") ? Iterables.getOnlyElement(ruleContext.getPrerequisite("String_Node_Str",Mode.TARGET,ApkProvider.class).getTransitiveApks()) : null;
    Artifact featureAfterArtifact=ruleContext.attributes().isAttributeValueExplicitlySpecified("String_Node_Str") ? Iterables.getOnlyElement(ruleContext.getPrerequisite("String_Node_Str",Mode.TARGET,ApkProvider.class).getTransitiveApks()) : null;
    resourceApk=applicationManifest.packWithDataAndResources(ruleContext.getImplicitOutputArtifact(AndroidRuleClasses.ANDROID_RESOURCES_APK),ruleContext,false,resourceDeps,ruleContext.getImplicitOutputArtifact(AndroidRuleClasses.ANDROID_R_TXT),null,ResourceConfigurationFilter.fromRuleContext(ruleContext),ruleContext.getTokenizedStringListAttr("String_Node_Str"),ruleContext.attributes().get("String_Node_Str",Type.BOOLEAN),ruleContext.getTokenizedStringListAttr("String_Node_Str"),false,ProguardHelper.getProguardConfigArtifact(ruleContext,"String_Node_Str"),createMainDexProguardSpec(ruleContext),ruleContext.getImplicitOutputArtifact(AndroidRuleClasses.ANDROID_PROCESSED_MANIFEST),ruleContext.getImplicitOutputArtifact(AndroidRuleClasses.ANDROID_RESOURCES_ZIP),DataBinding.isEnabled(ruleContext) ? DataBinding.getLayoutInfoFile(ruleContext) : null,featureOfArtifact,featureAfterArtifact);
    ruleContext.assertNoErrors();
    incrementalResourceApk=applicationManifest.addMobileInstallStubApplication(ruleContext).packWithDataAndResources(ruleContext.getImplicitOutputArtifact(AndroidRuleClasses.ANDROID_INCREMENTAL_RESOURCES_APK),ruleContext,false,resourceDeps,null,null,ResourceConfigurationFilter.fromRuleContext(ruleContext),ruleContext.getTokenizedStringListAttr("String_Node_Str"),ruleContext.attributes().get("String_Node_Str",Type.BOOLEAN),ruleContext.getTokenizedStringListAttr("String_Node_Str"),true,ProguardHelper.getProguardConfigArtifact(ruleContext,"String_Node_Str"),null,null,null,null,null,null);
    ruleContext.assertNoErrors();
    instantRunResourceApk=applicationManifest.addInstantRunStubApplication(ruleContext).packWithDataAndResources(getDxArtifact(ruleContext,"String_Node_Str"),ruleContext,false,resourceDeps,null,null,ResourceConfigurationFilter.fromRuleContext(ruleContext),ruleContext.getTokenizedStringListAttr("String_Node_Str"),ruleContext.attributes().get("String_Node_Str",Type.BOOLEAN),ruleContext.getTokenizedStringListAttr("String_Node_Str"),true,ProguardHelper.getProguardConfigArtifact(ruleContext,"String_Node_Str"),null,null,null,null,null,null);
    ruleContext.assertNoErrors();
    splitResourceApk=applicationManifest.createSplitManifest(ruleContext,"String_Node_Str",false).packWithDataAndResources(getDxArtifact(ruleContext,"String_Node_Str"),ruleContext,false,resourceDeps,null,null,ResourceConfigurationFilter.fromRuleContext(ruleContext),ruleContext.getTokenizedStringListAttr("String_Node_Str"),ruleContext.attributes().get("String_Node_Str",Type.BOOLEAN),ruleContext.getTokenizedStringListAttr("String_Node_Str"),true,ProguardHelper.getProguardConfigArtifact(ruleContext,"String_Node_Str"),null,null,null,null,null,null);
    ruleContext.assertNoErrors();
  }
 else {
    if (!ruleContext.attributes().get("String_Node_Str",Type.BOOLEAN)) {
      ruleContext.throwWithRuleError("String_Node_Str" + "String_Node_Str");
    }
    ApplicationManifest resourcesManifest=ApplicationManifest.fromResourcesRule(ruleContext);
    if (resourcesManifest == null) {
      throw new RuleErrorException();
    }
    applicationManifest=resourcesManifest.mergeWith(ruleContext,resourceDeps);
    if (shouldRegenerate(ruleContext,resourceDeps)) {
      resourceApk=applicationManifest.packWithResources(ruleContext.getImplicitOutputArtifact(AndroidRuleClasses.ANDROID_RESOURCES_APK),ruleContext,resourceDeps,true,ProguardHelper.getProguardConfigArtifact(ruleContext,"String_Node_Str"),createMainDexProguardSpec(ruleContext));
      ruleContext.assertNoErrors();
    }
 else {
      resourceApk=applicationManifest.useCurrentResources(ruleContext,ProguardHelper.getProguardConfigArtifact(ruleContext,"String_Node_Str"),createMainDexProguardSpec(ruleContext));
      ruleContext.assertNoErrors();
    }
    incrementalResourceApk=applicationManifest.addMobileInstallStubApplication(ruleContext).packWithResources(ruleContext.getImplicitOutputArtifact(AndroidRuleClasses.ANDROID_INCREMENTAL_RESOURCES_APK),ruleContext,resourceDeps,false,ProguardHelper.getProguardConfigArtifact(ruleContext,"String_Node_Str"),null);
    ruleContext.assertNoErrors();
    instantRunResourceApk=applicationManifest.addInstantRunStubApplication(ruleContext).packWithResources(getDxArtifact(ruleContext,"String_Node_Str"),ruleContext,resourceDeps,false,ProguardHelper.getProguardConfigArtifact(ruleContext,"String_Node_Str"),null);
    ruleContext.assertNoErrors();
    splitResourceApk=applicationManifest.createSplitManifest(ruleContext,"String_Node_Str",false).packWithResources(getDxArtifact(ruleContext,"String_Node_Str"),ruleContext,resourceDeps,false,ProguardHelper.getProguardConfigArtifact(ruleContext,"String_Node_Str"),null);
    ruleContext.assertNoErrors();
  }
  boolean shrinkResources=shouldShrinkResources(ruleContext);
  JavaTargetAttributes resourceClasses=androidCommon.init(javaSemantics,androidSemantics,resourceApk,ruleContext.getConfiguration().isCodeCoverageEnabled(),true,true);
  ruleContext.assertNoErrors();
  Function<Artifact,Artifact> derivedJarFunction=collectDesugaredJars(ruleContext,androidCommon,androidSemantics,resourceClasses);
  Artifact deployJar=createDeployJar(ruleContext,javaSemantics,androidCommon,resourceClasses,derivedJarFunction);
  Artifact proguardMapping=ruleContext.getPrerequisiteArtifact("String_Node_Str",Mode.TARGET);
  return createAndroidBinary(ruleContext,filesBuilder,deployJar,derivedJarFunction,false,javaCommon,androidCommon,javaSemantics,androidSemantics,nativeLibs,applicationManifest,resourceApk,incrementalResourceApk,instantRunResourceApk,splitResourceApk,shrinkResources,resourceClasses,ImmutableList.<Artifact>of(),ImmutableList.<Artifact>of(),proguardMapping);
}

Fixed version (ground truth):
private static RuleConfiguredTargetBuilder init(RuleContext ruleContext,NestedSetBuilder<Artifact> filesBuilder,ResourceDependencies resourceDeps,JavaCommon javaCommon,AndroidCommon androidCommon,JavaSemantics javaSemantics,AndroidSemantics androidSemantics) throws InterruptedException, RuleErrorException {
  validateRuleContext(ruleContext);
  Multimap<String,TransitiveInfoCollection> depsByArchitecture=MultimapBuilder.treeKeys().arrayListValues().build();
  AndroidConfiguration androidConfig=ruleContext.getFragment(AndroidConfiguration.class);
  for (  Map.Entry<Optional<String>,? extends List<? extends TransitiveInfoCollection>> entry : ruleContext.getSplitPrerequisites("String_Node_Str").entrySet()) {
    String cpu=entry.getKey().or(androidConfig.getCpu());
    depsByArchitecture.putAll(cpu,entry.getValue());
  }
  Map<String,BuildConfiguration> configurationMap=new LinkedHashMap<>();
  Map<String,CcToolchainProvider> toolchainMap=new LinkedHashMap<>();
  for (  Map.Entry<Optional<String>,? extends List<? extends TransitiveInfoCollection>> entry : ruleContext.getSplitPrerequisites("String_Node_Str").entrySet()) {
    String cpu=entry.getKey().or(androidConfig.getCpu());
    TransitiveInfoCollection dep=Iterables.getOnlyElement(entry.getValue());
    CcToolchainProvider toolchain=CppHelper.getToolchain(ruleContext,dep);
    configurationMap.put(cpu,dep.getConfiguration());
    toolchainMap.put(cpu,toolchain);
  }
  NativeLibs nativeLibs=NativeLibs.fromLinkedNativeDeps(ruleContext,androidSemantics.getNativeDepsFileName(),depsByArchitecture,toolchainMap,configurationMap);
  ApplicationManifest applicationManifest;
  ResourceApk resourceApk;
  ResourceApk incrementalResourceApk;
  ResourceApk instantRunResourceApk;
  ResourceApk splitResourceApk;
  if (LocalResourceContainer.definesAndroidResources(ruleContext.attributes())) {
    LocalResourceContainer.validateRuleContext(ruleContext);
    ApplicationManifest ruleManifest=androidSemantics.getManifestForRule(ruleContext);
    applicationManifest=ruleManifest.mergeWith(ruleContext,resourceDeps);
    Artifact featureOfArtifact=ruleContext.attributes().isAttributeValueExplicitlySpecified("String_Node_Str") ? Iterables.getOnlyElement(ruleContext.getPrerequisite("String_Node_Str",Mode.TARGET,ApkProvider.class).getTransitiveApks()) : null;
    Artifact featureAfterArtifact=ruleContext.attributes().isAttributeValueExplicitlySpecified("String_Node_Str") ? Iterables.getOnlyElement(ruleContext.getPrerequisite("String_Node_Str",Mode.TARGET,ApkProvider.class).getTransitiveApks()) : null;
    resourceApk=applicationManifest.packWithDataAndResources(ruleContext.getImplicitOutputArtifact(AndroidRuleClasses.ANDROID_RESOURCES_APK),ruleContext,false,resourceDeps,ruleContext.getImplicitOutputArtifact(AndroidRuleClasses.ANDROID_R_TXT),null,ResourceFilter.fromRuleContext(ruleContext),ruleContext.getTokenizedStringListAttr("String_Node_Str"),ruleContext.attributes().get("String_Node_Str",Type.BOOLEAN),false,ProguardHelper.getProguardConfigArtifact(ruleContext,"String_Node_Str"),createMainDexProguardSpec(ruleContext),ruleContext.getImplicitOutputArtifact(AndroidRuleClasses.ANDROID_PROCESSED_MANIFEST),ruleContext.getImplicitOutputArtifact(AndroidRuleClasses.ANDROID_RESOURCES_ZIP),DataBinding.isEnabled(ruleContext) ? DataBinding.getLayoutInfoFile(ruleContext) : null,featureOfArtifact,featureAfterArtifact);
    ruleContext.assertNoErrors();
    incrementalResourceApk=applicationManifest.addMobileInstallStubApplication(ruleContext).packWithDataAndResources(ruleContext.getImplicitOutputArtifact(AndroidRuleClasses.ANDROID_INCREMENTAL_RESOURCES_APK),ruleContext,false,resourceDeps,null,null,ResourceFilter.fromRuleContext(ruleContext),ruleContext.getTokenizedStringListAttr("String_Node_Str"),ruleContext.attributes().get("String_Node_Str",Type.BOOLEAN),true,ProguardHelper.getProguardConfigArtifact(ruleContext,"String_Node_Str"),null,null,null,null,null,null);
    ruleContext.assertNoErrors();
    instantRunResourceApk=applicationManifest.addInstantRunStubApplication(ruleContext).packWithDataAndResources(getDxArtifact(ruleContext,"String_Node_Str"),ruleContext,false,resourceDeps,null,null,ResourceFilter.fromRuleContext(ruleContext),ruleContext.getTokenizedStringListAttr("String_Node_Str"),ruleContext.attributes().get("String_Node_Str",Type.BOOLEAN),true,ProguardHelper.getProguardConfigArtifact(ruleContext,"String_Node_Str"),null,null,null,null,null,null);
    ruleContext.assertNoErrors();
    splitResourceApk=applicationManifest.createSplitManifest(ruleContext,"String_Node_Str",false).packWithDataAndResources(getDxArtifact(ruleContext,"String_Node_Str"),ruleContext,false,resourceDeps,null,null,ResourceFilter.fromRuleContext(ruleContext),ruleContext.getTokenizedStringListAttr("String_Node_Str"),ruleContext.attributes().get("String_Node_Str",Type.BOOLEAN),true,ProguardHelper.getProguardConfigArtifact(ruleContext,"String_Node_Str"),null,null,null,null,null,null);
    ruleContext.assertNoErrors();
  }
 else {
    if (!ruleContext.attributes().get("String_Node_Str",Type.BOOLEAN)) {
      ruleContext.throwWithRuleError("String_Node_Str" + "String_Node_Str");
    }
    ApplicationManifest resourcesManifest=ApplicationManifest.fromResourcesRule(ruleContext);
    if (resourcesManifest == null) {
      throw new RuleErrorException();
    }
    applicationManifest=resourcesManifest.mergeWith(ruleContext,resourceDeps);
    if (shouldRegenerate(ruleContext,resourceDeps)) {
      resourceApk=applicationManifest.packWithResources(ruleContext.getImplicitOutputArtifact(AndroidRuleClasses.ANDROID_RESOURCES_APK),ruleContext,resourceDeps,true,ProguardHelper.getProguardConfigArtifact(ruleContext,"String_Node_Str"),createMainDexProguardSpec(ruleContext));
      ruleContext.assertNoErrors();
    }
 else {
      resourceApk=applicationManifest.useCurrentResources(ruleContext,ProguardHelper.getProguardConfigArtifact(ruleContext,"String_Node_Str"),createMainDexProguardSpec(ruleContext));
      ruleContext.assertNoErrors();
    }
    incrementalResourceApk=applicationManifest.addMobileInstallStubApplication(ruleContext).packWithResources(ruleContext.getImplicitOutputArtifact(AndroidRuleClasses.ANDROID_INCREMENTAL_RESOURCES_APK),ruleContext,resourceDeps,false,ProguardHelper.getProguardConfigArtifact(ruleContext,"String_Node_Str"),null);
    ruleContext.assertNoErrors();
    instantRunResourceApk=applicationManifest.addInstantRunStubApplication(ruleContext).packWithResources(getDxArtifact(ruleContext,"String_Node_Str"),ruleContext,resourceDeps,false,ProguardHelper.getProguardConfigArtifact(ruleContext,"String_Node_Str"),null);
    ruleContext.assertNoErrors();
    splitResourceApk=applicationManifest.createSplitManifest(ruleContext,"String_Node_Str",false).packWithResources(getDxArtifact(ruleContext,"String_Node_Str"),ruleContext,resourceDeps,false,ProguardHelper.getProguardConfigArtifact(ruleContext,"String_Node_Str"),null);
    ruleContext.assertNoErrors();
  }
  boolean shrinkResources=shouldShrinkResources(ruleContext);
  JavaTargetAttributes resourceClasses=androidCommon.init(javaSemantics,androidSemantics,resourceApk,ruleContext.getConfiguration().isCodeCoverageEnabled(),true,true);
  ruleContext.assertNoErrors();
  Function<Artifact,Artifact> derivedJarFunction=collectDesugaredJars(ruleContext,androidCommon,androidSemantics,resourceClasses);
  Artifact deployJar=createDeployJar(ruleContext,javaSemantics,androidCommon,resourceClasses,derivedJarFunction);
  Artifact proguardMapping=ruleContext.getPrerequisiteArtifact("String_Node_Str",Mode.TARGET);
  return createAndroidBinary(ruleContext,filesBuilder,deployJar,derivedJarFunction,false,javaCommon,androidCommon,javaSemantics,androidSemantics,nativeLibs,applicationManifest,resourceApk,incrementalResourceApk,instantRunResourceApk,splitResourceApk,shrinkResources,resourceClasses,ImmutableList.<Artifact>of(),ImmutableList.<Artifact>of(),proguardMapping);
}