Program: 110782
Project: 110782
Buggy source:
@Override public ConfiguredTarget create(RuleContext ruleContext) throws InterruptedException, RuleErrorException {
  validateRuleContext(ruleContext);
  JavaSemantics javaSemantics=createJavaSemantics();
  AndroidSemantics androidSemantics=createAndroidSemantics();
  if (!AndroidSdkProvider.verifyPresence(ruleContext)) {
    return null;
  }
  checkResourceInlining(ruleContext);
  NestedSetBuilder<Aar> transitiveAars=collectTransitiveAars(ruleContext);
  NestedSetBuilder<Artifact> proguardConfigsbuilder=NestedSetBuilder.stableOrder();
  proguardConfigsbuilder.addTransitive(new ProguardLibrary(ruleContext).collectProguardSpecs());
  AndroidIdlHelper.maybeAddSupportLibProguardConfigs(ruleContext,proguardConfigsbuilder);
  NestedSet<Artifact> transitiveProguardConfigs=proguardConfigsbuilder.build();
  JavaCommon javaCommon=AndroidCommon.createJavaCommonWithAndroidDataBinding(ruleContext,javaSemantics,true);
  javaSemantics.checkRule(ruleContext,javaCommon);
  AndroidCommon androidCommon=new AndroidCommon(javaCommon);
  boolean definesLocalResources=LocalResourceContainer.definesAndroidResources(ruleContext.attributes());
  if (definesLocalResources) {
    LocalResourceContainer.validateRuleContext(ruleContext);
  }
  final ResourceApk resourceApk;
  if (definesLocalResources) {
    ApplicationManifest applicationManifest=androidSemantics.getManifestForRule(ruleContext).renamePackage(ruleContext,AndroidCommon.getJavaPackage(ruleContext));
    resourceApk=applicationManifest.packWithDataAndResources(null,ruleContext,true,ResourceDependencies.fromRuleDeps(ruleContext,JavaCommon.isNeverLink(ruleContext)),ruleContext.getImplicitOutputArtifact(AndroidRuleClasses.ANDROID_R_TXT),ruleContext.getImplicitOutputArtifact(AndroidRuleClasses.ANDROID_MERGED_SYMBOLS),ResourceConfigurationFilter.empty(ruleContext),ImmutableList.<String>of(),false,ImmutableList.<String>of(),false,null,null,ruleContext.getImplicitOutputArtifact(AndroidRuleClasses.ANDROID_PROCESSED_MANIFEST),ruleContext.getImplicitOutputArtifact(AndroidRuleClasses.ANDROID_RESOURCES_ZIP),DataBinding.isEnabled(ruleContext) ? DataBinding.getLayoutInfoFile(ruleContext) : null,null,null);
    if (ruleContext.hasErrors()) {
      return null;
    }
  }
 else {
    resourceApk=ResourceApk.fromTransitiveResources(ResourceDependencies.fromRuleResourceAndDeps(ruleContext,false));
  }
  if (!ruleContext.getFragment(AndroidConfiguration.class).allowSrcsLessAndroidLibraryDeps() && !definesLocalResources && ruleContext.attributes().get("String_Node_Str",BuildType.LABEL_LIST).isEmpty()&& ruleContext.attributes().get("String_Node_Str",BuildType.LABEL_LIST).isEmpty()&& !ruleContext.attributes().get("String_Node_Str",BuildType.LABEL_LIST).isEmpty()) {
    ruleContext.attributeError("String_Node_Str","String_Node_Str");
  }
  JavaTargetAttributes javaTargetAttributes=androidCommon.init(javaSemantics,androidSemantics,resourceApk,false,true,false);
  if (javaTargetAttributes == null) {
    return null;
  }
  Artifact classesJar=ruleContext.getImplicitOutputArtifact(AndroidRuleClasses.ANDROID_LIBRARY_CLASS_JAR);
  Artifact aarOut=ruleContext.getImplicitOutputArtifact(AndroidRuleClasses.ANDROID_LIBRARY_AAR);
  final ResourceContainer primaryResources;
  final Aar aar;
  if (definesLocalResources) {
    primaryResources=resourceApk.getPrimaryResource();
    ApplicationManifest applicationManifest=androidSemantics.getManifestForRule(ruleContext);
    aar=Aar.create(aarOut,applicationManifest.getManifest());
    transitiveAars.add(aar);
  }
 else   if (AndroidCommon.getAndroidResources(ruleContext) != null) {
    primaryResources=Iterables.getOnlyElement(AndroidCommon.getAndroidResources(ruleContext).getDirectAndroidResources());
    aar=Aar.create(aarOut,primaryResources.getManifest());
    transitiveAars.add(aar);
  }
 else {
    aar=null;
    ApplicationManifest applicationManifest=ApplicationManifest.generatedManifest(ruleContext).renamePackage(ruleContext,AndroidCommon.getJavaPackage(ruleContext));
    String javaPackage=AndroidCommon.getJavaPackage(ruleContext);
    ResourceContainer resourceContainer=ResourceContainer.builder().setLabel(ruleContext.getLabel()).setJavaPackageFromString(javaPackage).setManifest(applicationManifest.getManifest()).setJavaSourceJar(ruleContext.getImplicitOutputArtifact(AndroidRuleClasses.ANDROID_JAVA_SOURCE_JAR)).setManifestExported(ruleContext.attributes().get("String_Node_Str",Type.BOOLEAN)).setRTxt(ruleContext.getImplicitOutputArtifact(AndroidRuleClasses.ANDROID_R_TXT)).build();
    primaryResources=new AndroidResourcesProcessorBuilder(ruleContext).setLibrary(true).setRTxtOut(resourceContainer.getRTxt()).setManifestOut(ruleContext.getImplicitOutputArtifact(AndroidRuleClasses.ANDROID_PROCESSED_MANIFEST)).setSourceJarOut(resourceContainer.getJavaSourceJar()).setJavaPackage(resourceContainer.getJavaPackage()).withPrimary(resourceContainer).withDependencies(resourceApk.getResourceDependencies()).setDebug(ruleContext.getConfiguration().getCompilationMode() != CompilationMode.OPT).build(ruleContext);
  }
  new AarGeneratorBuilder(ruleContext).withPrimary(primaryResources).withManifest(aar != null ? aar.getManifest() : primaryResources.getManifest()).withRtxt(primaryResources.getRTxt()).withClasses(classesJar).setAAROut(aarOut).build(ruleContext);
  RuleConfiguredTargetBuilder builder=new RuleConfiguredTargetBuilder(ruleContext);
  androidCommon.addTransitiveInfoProviders(builder,androidSemantics,aarOut,resourceApk,null,ImmutableList.<Artifact>of());
  androidSemantics.addTransitiveInfoProviders(builder,ruleContext,javaCommon,androidCommon,null);
  NestedSetBuilder<Artifact> transitiveResourcesJars=collectTransitiveResourceJars(ruleContext);
  if (androidCommon.getResourceClassJar() != null) {
    transitiveResourcesJars.add(androidCommon.getResourceClassJar());
  }
  builder.addProvider(NativeLibsZipsProvider.class,new NativeLibsZipsProvider(AndroidCommon.collectTransitiveNativeLibsZips(ruleContext).build())).add(JavaNeverlinkInfoProvider.class,new JavaNeverlinkInfoProvider(androidCommon.isNeverLink())).add(JavaSourceInfoProvider.class,JavaSourceInfoProvider.fromJavaTargetAttributes(javaTargetAttributes,javaSemantics)).add(AndroidCcLinkParamsProvider.class,AndroidCcLinkParamsProvider.create(androidCommon.getCcLinkParamsStore())).add(JavaPluginInfoProvider.class,JavaCommon.getTransitivePlugins(ruleContext)).add(ProguardSpecProvider.class,new ProguardSpecProvider(transitiveProguardConfigs)).addOutputGroup(OutputGroupProvider.HIDDEN_TOP_LEVEL,transitiveProguardConfigs).add(AndroidLibraryResourceClassJarProvider.class,AndroidLibraryResourceClassJarProvider.create(transitiveResourcesJars.build()));
  if (!JavaCommon.isNeverLink(ruleContext)) {
    builder.add(AndroidLibraryAarProvider.class,AndroidLibraryAarProvider.create(aar,transitiveAars.build()));
  }
  return builder.build();
}

Fixed version (ground truth):
@Override public ConfiguredTarget create(RuleContext ruleContext) throws InterruptedException, RuleErrorException {
  validateRuleContext(ruleContext);
  JavaSemantics javaSemantics=createJavaSemantics();
  AndroidSemantics androidSemantics=createAndroidSemantics();
  if (!AndroidSdkProvider.verifyPresence(ruleContext)) {
    return null;
  }
  checkResourceInlining(ruleContext);
  NestedSetBuilder<Aar> transitiveAars=collectTransitiveAars(ruleContext);
  NestedSetBuilder<Artifact> proguardConfigsbuilder=NestedSetBuilder.stableOrder();
  proguardConfigsbuilder.addTransitive(new ProguardLibrary(ruleContext).collectProguardSpecs());
  AndroidIdlHelper.maybeAddSupportLibProguardConfigs(ruleContext,proguardConfigsbuilder);
  NestedSet<Artifact> transitiveProguardConfigs=proguardConfigsbuilder.build();
  JavaCommon javaCommon=AndroidCommon.createJavaCommonWithAndroidDataBinding(ruleContext,javaSemantics,true);
  javaSemantics.checkRule(ruleContext,javaCommon);
  AndroidCommon androidCommon=new AndroidCommon(javaCommon);
  boolean definesLocalResources=LocalResourceContainer.definesAndroidResources(ruleContext.attributes());
  if (definesLocalResources) {
    LocalResourceContainer.validateRuleContext(ruleContext);
  }
  final ResourceApk resourceApk;
  if (definesLocalResources) {
    ApplicationManifest applicationManifest=androidSemantics.getManifestForRule(ruleContext).renamePackage(ruleContext,AndroidCommon.getJavaPackage(ruleContext));
    resourceApk=applicationManifest.packWithDataAndResources(null,ruleContext,true,ResourceDependencies.fromRuleDeps(ruleContext,JavaCommon.isNeverLink(ruleContext)),ruleContext.getImplicitOutputArtifact(AndroidRuleClasses.ANDROID_R_TXT),ruleContext.getImplicitOutputArtifact(AndroidRuleClasses.ANDROID_MERGED_SYMBOLS),ResourceFilter.empty(ruleContext),ImmutableList.<String>of(),false,false,null,null,ruleContext.getImplicitOutputArtifact(AndroidRuleClasses.ANDROID_PROCESSED_MANIFEST),ruleContext.getImplicitOutputArtifact(AndroidRuleClasses.ANDROID_RESOURCES_ZIP),DataBinding.isEnabled(ruleContext) ? DataBinding.getLayoutInfoFile(ruleContext) : null,null,null);
    if (ruleContext.hasErrors()) {
      return null;
    }
  }
 else {
    resourceApk=ResourceApk.fromTransitiveResources(ResourceDependencies.fromRuleResourceAndDeps(ruleContext,false));
  }
  if (!ruleContext.getFragment(AndroidConfiguration.class).allowSrcsLessAndroidLibraryDeps() && !definesLocalResources && ruleContext.attributes().get("String_Node_Str",BuildType.LABEL_LIST).isEmpty()&& ruleContext.attributes().get("String_Node_Str",BuildType.LABEL_LIST).isEmpty()&& !ruleContext.attributes().get("String_Node_Str",BuildType.LABEL_LIST).isEmpty()) {
    ruleContext.attributeError("String_Node_Str","String_Node_Str");
  }
  JavaTargetAttributes javaTargetAttributes=androidCommon.init(javaSemantics,androidSemantics,resourceApk,false,true,false);
  if (javaTargetAttributes == null) {
    return null;
  }
  Artifact classesJar=ruleContext.getImplicitOutputArtifact(AndroidRuleClasses.ANDROID_LIBRARY_CLASS_JAR);
  Artifact aarOut=ruleContext.getImplicitOutputArtifact(AndroidRuleClasses.ANDROID_LIBRARY_AAR);
  final ResourceContainer primaryResources;
  final Aar aar;
  if (definesLocalResources) {
    primaryResources=resourceApk.getPrimaryResource();
    ApplicationManifest applicationManifest=androidSemantics.getManifestForRule(ruleContext);
    aar=Aar.create(aarOut,applicationManifest.getManifest());
    transitiveAars.add(aar);
  }
 else   if (AndroidCommon.getAndroidResources(ruleContext) != null) {
    primaryResources=Iterables.getOnlyElement(AndroidCommon.getAndroidResources(ruleContext).getDirectAndroidResources());
    aar=Aar.create(aarOut,primaryResources.getManifest());
    transitiveAars.add(aar);
  }
 else {
    aar=null;
    ApplicationManifest applicationManifest=ApplicationManifest.generatedManifest(ruleContext).renamePackage(ruleContext,AndroidCommon.getJavaPackage(ruleContext));
    String javaPackage=AndroidCommon.getJavaPackage(ruleContext);
    ResourceContainer resourceContainer=ResourceContainer.builder().setLabel(ruleContext.getLabel()).setJavaPackageFromString(javaPackage).setManifest(applicationManifest.getManifest()).setJavaSourceJar(ruleContext.getImplicitOutputArtifact(AndroidRuleClasses.ANDROID_JAVA_SOURCE_JAR)).setManifestExported(ruleContext.attributes().get("String_Node_Str",Type.BOOLEAN)).setRTxt(ruleContext.getImplicitOutputArtifact(AndroidRuleClasses.ANDROID_R_TXT)).build();
    primaryResources=new AndroidResourcesProcessorBuilder(ruleContext).setLibrary(true).setRTxtOut(resourceContainer.getRTxt()).setManifestOut(ruleContext.getImplicitOutputArtifact(AndroidRuleClasses.ANDROID_PROCESSED_MANIFEST)).setSourceJarOut(resourceContainer.getJavaSourceJar()).setJavaPackage(resourceContainer.getJavaPackage()).withPrimary(resourceContainer).withDependencies(resourceApk.getResourceDependencies()).setDebug(ruleContext.getConfiguration().getCompilationMode() != CompilationMode.OPT).build(ruleContext);
  }
  new AarGeneratorBuilder(ruleContext).withPrimary(primaryResources).withManifest(aar != null ? aar.getManifest() : primaryResources.getManifest()).withRtxt(primaryResources.getRTxt()).withClasses(classesJar).setAAROut(aarOut).build(ruleContext);
  RuleConfiguredTargetBuilder builder=new RuleConfiguredTargetBuilder(ruleContext);
  androidCommon.addTransitiveInfoProviders(builder,androidSemantics,aarOut,resourceApk,null,ImmutableList.<Artifact>of());
  androidSemantics.addTransitiveInfoProviders(builder,ruleContext,javaCommon,androidCommon,null);
  NestedSetBuilder<Artifact> transitiveResourcesJars=collectTransitiveResourceJars(ruleContext);
  if (androidCommon.getResourceClassJar() != null) {
    transitiveResourcesJars.add(androidCommon.getResourceClassJar());
  }
  builder.addProvider(NativeLibsZipsProvider.class,new NativeLibsZipsProvider(AndroidCommon.collectTransitiveNativeLibsZips(ruleContext).build())).add(JavaNeverlinkInfoProvider.class,new JavaNeverlinkInfoProvider(androidCommon.isNeverLink())).add(JavaSourceInfoProvider.class,JavaSourceInfoProvider.fromJavaTargetAttributes(javaTargetAttributes,javaSemantics)).add(AndroidCcLinkParamsProvider.class,AndroidCcLinkParamsProvider.create(androidCommon.getCcLinkParamsStore())).add(JavaPluginInfoProvider.class,JavaCommon.getTransitivePlugins(ruleContext)).add(ProguardSpecProvider.class,new ProguardSpecProvider(transitiveProguardConfigs)).addOutputGroup(OutputGroupProvider.HIDDEN_TOP_LEVEL,transitiveProguardConfigs).add(AndroidLibraryResourceClassJarProvider.class,AndroidLibraryResourceClassJarProvider.create(transitiveResourcesJars.build()));
  if (!JavaCommon.isNeverLink(ruleContext)) {
    builder.add(AndroidLibraryAarProvider.class,AndroidLibraryAarProvider.create(aar,transitiveAars.build()));
  }
  return builder.build();
}