Program: 99663
Project: 99663
Buggy source:
/** 
 * Get method of the Model in an other Signature. Generates a new Method that wraps the model so it can be called using the given Signature.  Flags control the behavior of that wrapper. Arguments to the wrapping function are "connected through" to the model based on their type only, so if there are multiple Arguments of the same type this may yield to unexpected connections. This method is called by the IntentCoentextInterpreter.
 * @see com.ibm.wala.dalvik.ipa.callgraph.propagation.cfa.IntentContextInterpreter
 * @see com.ibm.wala.dalvik.ipa.callgraph.propagation.cfa.IntentStarters
 * @param asMethod    The signature to generate
 * @param flags       Control the behavior of the wrapper, may be null
 * @param caller      The class of the caller; only needed depending on the flags
 * @param info        The IntentSterter used
 * @param callerNd    CGNoodle of the caller - may be null
 * @return A wrapper that calls the model
 */
public SummarizedMethod getMethodAs(MethodReference asMethod,TypeReference caller,IntentStarters.StartInfo info,CGNode callerNd) throws CancelException {
  Set<StarterFlags> flags=info.getFlags();
  if (!built) {
    getMethod();
  }
  if (asMethod == null) {
    throw new IllegalArgumentException("String_Node_Str");
  }
  if (flags == null) {
    flags=Collections.emptySet();
  }
  final TypeSafeInstructionFactory instructionFactory=new TypeSafeInstructionFactory(getClassHierarchy());
  final ParameterAccessor acc=new ParameterAccessor(asMethod,true);
  final SSAValueManager pm=new SSAValueManager(acc);
  if (callerNd != null) {
    pm.breadCrumb="String_Node_Str" + caller + "String_Node_Str"+ callerNd.getContext()+ "String_Node_Str"+ this.getClass()+ "String_Node_Str"+ this.getName();
  }
 else {
    pm.breadCrumb="String_Node_Str" + caller + "String_Node_Str"+ this.getClass();
  }
  final VolatileMethodSummary redirect=new VolatileMethodSummary(new MethodSummary(asMethod));
  redirect.setStatic(false);
  final Instantiator instantiator=new Instantiator(redirect,instructionFactory,pm,this.cha,asMethod,this.scope);
  final Parameter self;
{
    self=acc.getThisAs(caller);
    pm.setAllocation(self,null);
  }
  final ParameterAccessor modelAcc=new ParameterAccessor(this.model);
  final List<Parameter> modelsActivities=modelAcc.allExtend(AndroidTypes.ActivityName,getClassHierarchy());
  final List<SSAValue> allActivities=new ArrayList<SSAValue>(modelsActivities.size());
  for (  Parameter activity : modelsActivities) {
    final TypeReference activityType=activity.getType();
    final Parameter inAsMethod=acc.firstOf(activityType);
    if (inAsMethod != null) {
      allActivities.add(inAsMethod);
    }
 else {
      final Atom fdName=activityType.getName().getClassName();
      final AndroidModelClass mClass=AndroidModelClass.getInstance(cha);
      if (AndroidEntryPointManager.MANAGER.doFlatComponents()) {
        if (mClass.getField(fdName) != null) {
          final IField field=mClass.getField(fdName);
          final int instPC=redirect.getNextProgramCounter();
          final SSAValue target=pm.getUnallocated(activityType,new SSAValue.WeaklyNamedKey(activityType.getName(),"String_Node_Str" + fdName.toString()));
          final SSAInstruction getInst=instructionFactory.GetInstruction(instPC,target,field.getReference());
          redirect.addStatement(getInst);
          pm.setAllocation(target,getInst);
          allActivities.add(target);
        }
 else {
          final SSAValue newInstance=instantiator.createInstance(activityType,false,null,null);
          allActivities.add(newInstance);
          mClass.putField(fdName,activityType);
          final int instPC=redirect.getNextProgramCounter();
          final FieldReference fdRef=FieldReference.findOrCreate(mClass.getReference(),fdName,activityType);
          final SSAInstruction putInst=instructionFactory.PutInstruction(instPC,newInstance,fdRef);
          redirect.addStatement(putInst);
          System.out.println("String_Node_Str" + newInstance);
        }
      }
 else {
        final SSAValue newInstance=instantiator.createInstance(activityType,false,null,null);
        allActivities.add(newInstance);
      }
    }
  }
  assert(allActivities.size() == modelsActivities.size());
  final Set<SSAValue> defaults=new HashSet<SSAValue>();
{
    final SSAValue nullBundle=pm.getUnmanaged(AndroidTypes.Bundle,"String_Node_Str");
    redirect.addConstant(nullBundle.getNumber(),new ConstantValue(null));
    nullBundle.setAssigned();
    defaults.add(nullBundle);
  }
{
    final TypeName intentArray=TypeName.findOrCreate("String_Node_Str");
    final SSAValue incoming=acc.firstOf(intentArray);
    if (incoming != null) {
      final VariableKey unpackedIntentKey=new WeaklyNamedKey(AndroidTypes.IntentName,"String_Node_Str");
      final SSAValue unpackedIntent=pm.getUnallocated(AndroidTypes.Intent,unpackedIntentKey);
      final int pc=redirect.getNextProgramCounter();
      final SSAInstruction fetch=instructionFactory.ArrayLoadInstruction(pc,unpackedIntent,incoming,0);
      redirect.addStatement(fetch);
      pm.setAllocation(unpackedIntent,fetch);
      defaults.add(unpackedIntent);
    }
  }
  final SSAValue intent=acc.firstExtends(AndroidTypes.Intent,cha);
  final AndroidStartComponentTool tool=new AndroidStartComponentTool(getClassHierarchy(),asMethod,flags,caller,instructionFactory,acc,pm,redirect,self,info,callerNd);
  final AndroidTypes.AndroidContextType contextType;
  final SSAValue androidContext;
  androidContext=tool.fetchCallerContext();
  contextType=tool.typeOfCallerContext();
  try {
    if (intent != null) {
      tool.setIntent(intent,allActivities);
    }
 else     if (!info.isSystemService()) {
    }
{
      final List<SSAValue> redirectParams=acc.connectThrough(modelAcc,new HashSet<SSAValue>(allActivities),defaults,getClassHierarchy(),instantiator,false,null,null);
      final int callPC=redirect.getNextProgramCounter();
      final CallSiteReference site=CallSiteReference.make(callPC,this.model.getReference(),IInvokeInstruction.Dispatch.STATIC);
      final SSAAbstractInvokeInstruction invokation;
      final SSAValue exception=pm.getException();
      if (this.model.getReference().getReturnType().equals(TypeReference.Void)) {
        invokation=instructionFactory.InvokeInstruction(callPC,redirectParams,exception,site);
      }
 else {
        if (this instanceof SystemServiceModel) {
          final SSAValue svc=pm.getUnmanaged(TypeReference.JavaLangObject,"String_Node_Str");
          invokation=instructionFactory.InvokeInstruction(callPC,svc,redirectParams,exception,site);
          redirect.addStatement(invokation);
          if (instructionFactory.isAssignableFrom(svc.getType(),svc.getValidIn().getReturnType())) {
            final int returnPC=redirect.getNextProgramCounter();
            final SSAInstruction returnInstruction=instructionFactory.ReturnInstruction(returnPC,svc);
            redirect.addStatement(returnInstruction);
          }
          final IClass declaringClass=this.cha.lookupClass(asMethod.getDeclaringClass());
          if (declaringClass == null) {
            throw new IllegalStateException("String_Node_Str" + asMethod.getDeclaringClass() + "String_Node_Str"+ "String_Node_Str"+ asMethod.toString());
          }
          redirect.setLocalNames(pm.makeLocalNames());
          SummarizedMethod override=new SummarizedMethodWithNames(mRef,redirect,declaringClass);
          return override;
        }
 else         if (this instanceof ExternalModel) {
          final SSAValue trash=pm.getUnmanaged(AndroidTypes.Intent,"String_Node_Str");
          invokation=instructionFactory.InvokeInstruction(callPC,trash,redirectParams,exception,site);
        }
 else {
          throw new UnsupportedOperationException("String_Node_Str" + this.model.getClass());
        }
      }
      redirect.addStatement(invokation);
    }
    if (flags.contains(StarterFlags.CALL_ON_ACTIVITY_RESULT) && (!flags.contains(StarterFlags.CONTEXT_FREE))) {
      final List<SSAValue> resultCodes=new ArrayList<SSAValue>();
      final List<SSAValue> resultData=new ArrayList<SSAValue>();
      final SSAValue mResultCode;
      final SSAValue mResultData;
      tool.fetchResults(resultCodes,resultData,allActivities);
      if (resultCodes.size() == 0) {
        throw new IllegalStateException("String_Node_Str" + asMethod + "String_Node_Str"+ caller+ "String_Node_Str"+ this.model+ "String_Node_Str");
      }
      mResultCode=tool.addPhi(resultCodes);
      mResultData=tool.addPhi(resultData);
{
        final SSAValue outRequestCode=acc.firstOf(TypeReference.Int);
        final int callPC=redirect.getNextProgramCounter();
        final Selector mSel=Selector.make("String_Node_Str");
        final MethodReference mRef=MethodReference.findOrCreate(caller,mSel);
        final CallSiteReference site=CallSiteReference.make(callPC,mRef,IInvokeInstruction.Dispatch.VIRTUAL);
        final SSAValue exception=pm.getException();
        final List<SSAValue> params=new ArrayList<SSAValue>();
        params.add(self);
        params.add(outRequestCode);
        params.add(mResultCode);
        params.add(mResultData);
        final SSAInstruction invokation=instructionFactory.InvokeInstruction(callPC,params,exception,site);
        redirect.addStatement(invokation);
      }
    }
    final IClass declaringClass=this.cha.lookupClass(asMethod.getDeclaringClass());
    if (declaringClass == null) {
      throw new IllegalStateException("String_Node_Str" + asMethod.getDeclaringClass() + "String_Node_Str"+ "String_Node_Str"+ asMethod.toString());
    }
    redirect.setLocalNames(pm.makeLocalNames());
    SummarizedMethod override=new SummarizedMethodWithNames(mRef,redirect,declaringClass);
    return override;
  }
 catch (  Exception e) {
    e.printStackTrace();
    System.err.println("String_Node_Str");
    System.err.println(acc.dump());
    System.err.println("String_Node_Str" + pm);
    System.err.println("String_Node_Str" + self);
    System.err.println("String_Node_Str" + acc.dump());
    System.err.println("String_Node_Str" + contextType);
    System.err.println("String_Node_Str" + androidContext);
    System.err.println("String_Node_Str" + asMethod);
    System.err.println("String_Node_Str" + caller);
    System.err.println("String_Node_Str" + info);
    System.err.println("String_Node_Str" + callerNd);
    System.err.println("String_Node_Str" + this.getClass().toString());
    System.err.println("String_Node_Str" + this.name);
    throw new IllegalStateException(e);
  }
}

Fixed version (ground truth):
/** 
 * Get method of the Model in an other Signature. Generates a new Method that wraps the model so it can be called using the given Signature.  Flags control the behavior of that wrapper. Arguments to the wrapping function are "connected through" to the model based on their type only, so if there are multiple Arguments of the same type this may yield to unexpected connections. This method is called by the IntentCoentextInterpreter.
 * @see com.ibm.wala.dalvik.ipa.callgraph.propagation.cfa.IntentContextInterpreter
 * @see com.ibm.wala.dalvik.ipa.callgraph.propagation.cfa.IntentStarters
 * @param asMethod    The signature to generate
 * @param flags       Control the behavior of the wrapper, may be null
 * @param caller      The class of the caller; only needed depending on the flags
 * @param info        The IntentSterter used
 * @param callerNd    CGNoodle of the caller - may be null
 * @return A wrapper that calls the model
 */
public SummarizedMethod getMethodAs(MethodReference asMethod,TypeReference caller,IntentStarters.StartInfo info,CGNode callerNd) throws CancelException {
  Set<StarterFlags> flags=null;
  if (info != null) {
    flags=info.getFlags();
  }
  if (!built) {
    getMethod();
  }
  if (asMethod == null) {
    throw new IllegalArgumentException("String_Node_Str");
  }
  if (flags == null) {
    flags=Collections.emptySet();
  }
  final TypeSafeInstructionFactory instructionFactory=new TypeSafeInstructionFactory(getClassHierarchy());
  final ParameterAccessor acc=new ParameterAccessor(asMethod,true);
  final SSAValueManager pm=new SSAValueManager(acc);
  if (callerNd != null) {
    pm.breadCrumb="String_Node_Str" + caller + "String_Node_Str"+ callerNd.getContext()+ "String_Node_Str"+ this.getClass()+ "String_Node_Str"+ this.getName();
  }
 else {
    pm.breadCrumb="String_Node_Str" + caller + "String_Node_Str"+ this.getClass();
  }
  final VolatileMethodSummary redirect=new VolatileMethodSummary(new MethodSummary(asMethod));
  redirect.setStatic(false);
  final Instantiator instantiator=new Instantiator(redirect,instructionFactory,pm,this.cha,asMethod,this.scope);
  final Parameter self;
{
    self=acc.getThisAs(caller);
    pm.setAllocation(self,null);
  }
  final ParameterAccessor modelAcc=new ParameterAccessor(this.model);
  final List<Parameter> modelsActivities=modelAcc.allExtend(AndroidTypes.ActivityName,getClassHierarchy());
  final List<SSAValue> allActivities=new ArrayList<SSAValue>(modelsActivities.size());
  for (  Parameter activity : modelsActivities) {
    final TypeReference activityType=activity.getType();
    final Parameter inAsMethod=acc.firstOf(activityType);
    if (inAsMethod != null) {
      allActivities.add(inAsMethod);
    }
 else {
      final Atom fdName=activityType.getName().getClassName();
      final AndroidModelClass mClass=AndroidModelClass.getInstance(cha);
      if (AndroidEntryPointManager.MANAGER.doFlatComponents()) {
        if (mClass.getField(fdName) != null) {
          final IField field=mClass.getField(fdName);
          final int instPC=redirect.getNextProgramCounter();
          final SSAValue target=pm.getUnallocated(activityType,new SSAValue.WeaklyNamedKey(activityType.getName(),"String_Node_Str" + fdName.toString()));
          final SSAInstruction getInst=instructionFactory.GetInstruction(instPC,target,field.getReference());
          redirect.addStatement(getInst);
          pm.setAllocation(target,getInst);
          allActivities.add(target);
        }
 else {
          final SSAValue newInstance=instantiator.createInstance(activityType,false,null,null);
          allActivities.add(newInstance);
          mClass.putField(fdName,activityType);
          final int instPC=redirect.getNextProgramCounter();
          final FieldReference fdRef=FieldReference.findOrCreate(mClass.getReference(),fdName,activityType);
          final SSAInstruction putInst=instructionFactory.PutInstruction(instPC,newInstance,fdRef);
          redirect.addStatement(putInst);
          System.out.println("String_Node_Str" + newInstance);
        }
      }
 else {
        final SSAValue newInstance=instantiator.createInstance(activityType,false,null,null);
        allActivities.add(newInstance);
      }
    }
  }
  assert(allActivities.size() == modelsActivities.size());
  final Set<SSAValue> defaults=new HashSet<SSAValue>();
{
    final SSAValue nullBundle=pm.getUnmanaged(AndroidTypes.Bundle,"String_Node_Str");
    redirect.addConstant(nullBundle.getNumber(),new ConstantValue(null));
    nullBundle.setAssigned();
    defaults.add(nullBundle);
  }
{
    final TypeName intentArray=TypeName.findOrCreate("String_Node_Str");
    final SSAValue incoming=acc.firstOf(intentArray);
    if (incoming != null) {
      final VariableKey unpackedIntentKey=new WeaklyNamedKey(AndroidTypes.IntentName,"String_Node_Str");
      final SSAValue unpackedIntent=pm.getUnallocated(AndroidTypes.Intent,unpackedIntentKey);
      final int pc=redirect.getNextProgramCounter();
      final SSAInstruction fetch=instructionFactory.ArrayLoadInstruction(pc,unpackedIntent,incoming,0);
      redirect.addStatement(fetch);
      pm.setAllocation(unpackedIntent,fetch);
      defaults.add(unpackedIntent);
    }
  }
  final SSAValue intent=acc.firstExtends(AndroidTypes.Intent,cha);
  final AndroidStartComponentTool tool=new AndroidStartComponentTool(getClassHierarchy(),asMethod,flags,caller,instructionFactory,acc,pm,redirect,self,info,callerNd);
  final AndroidTypes.AndroidContextType contextType;
  final SSAValue androidContext;
  androidContext=tool.fetchCallerContext();
  contextType=tool.typeOfCallerContext();
  try {
    if (intent != null) {
      tool.setIntent(intent,allActivities);
    }
 else     if (!info.isSystemService()) {
    }
{
      final List<SSAValue> redirectParams=acc.connectThrough(modelAcc,new HashSet<SSAValue>(allActivities),defaults,getClassHierarchy(),instantiator,false,null,null);
      final int callPC=redirect.getNextProgramCounter();
      final CallSiteReference site=CallSiteReference.make(callPC,this.model.getReference(),IInvokeInstruction.Dispatch.STATIC);
      final SSAAbstractInvokeInstruction invokation;
      final SSAValue exception=pm.getException();
      if (this.model.getReference().getReturnType().equals(TypeReference.Void)) {
        invokation=instructionFactory.InvokeInstruction(callPC,redirectParams,exception,site);
      }
 else {
        if (this instanceof SystemServiceModel) {
          final SSAValue svc=pm.getUnmanaged(TypeReference.JavaLangObject,"String_Node_Str");
          invokation=instructionFactory.InvokeInstruction(callPC,svc,redirectParams,exception,site);
          redirect.addStatement(invokation);
          if (instructionFactory.isAssignableFrom(svc.getType(),svc.getValidIn().getReturnType())) {
            final int returnPC=redirect.getNextProgramCounter();
            final SSAInstruction returnInstruction=instructionFactory.ReturnInstruction(returnPC,svc);
            redirect.addStatement(returnInstruction);
          }
          final IClass declaringClass=this.cha.lookupClass(asMethod.getDeclaringClass());
          if (declaringClass == null) {
            throw new IllegalStateException("String_Node_Str" + asMethod.getDeclaringClass() + "String_Node_Str"+ "String_Node_Str"+ asMethod.toString());
          }
          redirect.setLocalNames(pm.makeLocalNames());
          SummarizedMethod override=new SummarizedMethodWithNames(mRef,redirect,declaringClass);
          return override;
        }
 else         if (this instanceof ExternalModel) {
          final SSAValue trash=pm.getUnmanaged(AndroidTypes.Intent,"String_Node_Str");
          invokation=instructionFactory.InvokeInstruction(callPC,trash,redirectParams,exception,site);
        }
 else {
          throw new UnsupportedOperationException("String_Node_Str" + this.model.getClass());
        }
      }
      redirect.addStatement(invokation);
    }
    if (flags.contains(StarterFlags.CALL_ON_ACTIVITY_RESULT) && (!flags.contains(StarterFlags.CONTEXT_FREE))) {
      final List<SSAValue> resultCodes=new ArrayList<SSAValue>();
      final List<SSAValue> resultData=new ArrayList<SSAValue>();
      final SSAValue mResultCode;
      final SSAValue mResultData;
      tool.fetchResults(resultCodes,resultData,allActivities);
      if (resultCodes.size() == 0) {
        throw new IllegalStateException("String_Node_Str" + asMethod + "String_Node_Str"+ caller+ "String_Node_Str"+ this.model+ "String_Node_Str");
      }
      mResultCode=tool.addPhi(resultCodes);
      mResultData=tool.addPhi(resultData);
{
        final SSAValue outRequestCode=acc.firstOf(TypeReference.Int);
        final int callPC=redirect.getNextProgramCounter();
        final Selector mSel=Selector.make("String_Node_Str");
        final MethodReference mRef=MethodReference.findOrCreate(caller,mSel);
        final CallSiteReference site=CallSiteReference.make(callPC,mRef,IInvokeInstruction.Dispatch.VIRTUAL);
        final SSAValue exception=pm.getException();
        final List<SSAValue> params=new ArrayList<SSAValue>();
        params.add(self);
        params.add(outRequestCode);
        params.add(mResultCode);
        params.add(mResultData);
        final SSAInstruction invokation=instructionFactory.InvokeInstruction(callPC,params,exception,site);
        redirect.addStatement(invokation);
      }
    }
    final IClass declaringClass=this.cha.lookupClass(asMethod.getDeclaringClass());
    if (declaringClass == null) {
      throw new IllegalStateException("String_Node_Str" + asMethod.getDeclaringClass() + "String_Node_Str"+ "String_Node_Str"+ asMethod.toString());
    }
    redirect.setLocalNames(pm.makeLocalNames());
    SummarizedMethod override=new SummarizedMethodWithNames(mRef,redirect,declaringClass);
    return override;
  }
 catch (  Exception e) {
    e.printStackTrace();
    System.err.println("String_Node_Str");
    System.err.println(acc.dump());
    System.err.println("String_Node_Str" + pm);
    System.err.println("String_Node_Str" + self);
    System.err.println("String_Node_Str" + acc.dump());
    System.err.println("String_Node_Str" + contextType);
    System.err.println("String_Node_Str" + androidContext);
    System.err.println("String_Node_Str" + asMethod);
    System.err.println("String_Node_Str" + caller);
    System.err.println("String_Node_Str" + info);
    System.err.println("String_Node_Str" + callerNd);
    System.err.println("String_Node_Str" + this.getClass().toString());
    System.err.println("String_Node_Str" + this.name);
    throw new IllegalStateException(e);
  }
}