Program: 9178
Project: 9178
Buggy source:
private boolean mungeNewMethod(BcelClassWeaver weaver,NewMethodTypeMunger munger){
  World w=weaver.getWorld();
  ResolvedMember unMangledInterMethod=munger.getSignature().resolve(w);
  ResolvedMember interMethodBody=munger.getDeclaredInterMethodBody(aspectType,w);
  ResolvedMember interMethodDispatcher=munger.getDeclaredInterMethodDispatcher(aspectType,w);
  ResolvedMember memberHoldingAnyAnnotations=interMethodDispatcher;
  ResolvedType onType=weaver.getWorld().resolve(unMangledInterMethod.getDeclaringType(),munger.getSourceLocation());
  LazyClassGen gen=weaver.getLazyClassGen();
  boolean mungingInterface=gen.isInterface();
  if (onType.isRawType())   onType=onType.getGenericType();
  boolean onInterface=onType.isInterface();
  if (onType.isAnnotation()) {
    signalError(WeaverMessages.ITDM_ON_ANNOTATION_NOT_ALLOWED,weaver,onType);
    return false;
  }
  if (onType.isEnum()) {
    signalError(WeaverMessages.ITDM_ON_ENUM_NOT_ALLOWED,weaver,onType);
    return false;
  }
  if (onInterface && gen.getLazyMethodGen(unMangledInterMethod.getName(),unMangledInterMethod.getSignature(),true) != null) {
    return false;
  }
  if (onType.equals(gen.getType())) {
    ResolvedMember mangledInterMethod=AjcMemberMaker.interMethod(unMangledInterMethod,aspectType,onInterface);
    LazyMethodGen newMethod=makeMethodGen(gen,mangledInterMethod);
    if (mungingInterface) {
      newMethod.setAccessFlags(Modifier.PUBLIC | Modifier.ABSTRACT);
    }
    if (weaver.getWorld().isInJava5Mode()) {
      AnnotationX annotationsOnRealMember[]=null;
      ResolvedType toLookOn=aspectType;
      if (aspectType.isRawType())       toLookOn=aspectType.getGenericType();
      ResolvedMember realMember=getRealMemberForITDFromAspect(toLookOn,memberHoldingAnyAnnotations,false);
      if (realMember == null)       throw new BCException("String_Node_Str" + memberHoldingAnyAnnotations + "String_Node_Str"+ aspectType);
      annotationsOnRealMember=realMember.getAnnotations();
      if (annotationsOnRealMember != null) {
        for (int i=0; i < annotationsOnRealMember.length; i++) {
          AnnotationX annotationX=annotationsOnRealMember[i];
          AnnotationGen a=annotationX.getBcelAnnotation();
          AnnotationGen ag=new AnnotationGen(a,weaver.getLazyClassGen().getConstantPool(),true);
          newMethod.addAnnotation(new AnnotationX(ag,weaver.getWorld()));
        }
      }
      List allDecams=weaver.getWorld().getDeclareAnnotationOnMethods();
      for (Iterator i=allDecams.iterator(); i.hasNext(); ) {
        DeclareAnnotation decaMC=(DeclareAnnotation)i.next();
        if (decaMC.matches(unMangledInterMethod,weaver.getWorld()) && newMethod.getEnclosingClass().getType() == aspectType) {
          newMethod.addAnnotation(decaMC.getAnnotationX());
        }
      }
    }
    if (!onInterface && !Modifier.isAbstract(mangledInterMethod.getModifiers())) {
      InstructionList body=newMethod.getBody();
      InstructionFactory fact=gen.getFactory();
      int pos=0;
      if (!unMangledInterMethod.isStatic()) {
        body.append(InstructionFactory.createThis());
        pos++;
      }
      Type[] paramTypes=BcelWorld.makeBcelTypes(mangledInterMethod.getParameterTypes());
      for (int i=0, len=paramTypes.length; i < len; i++) {
        Type paramType=paramTypes[i];
        body.append(InstructionFactory.createLoad(paramType,pos));
        pos+=paramType.getSize();
      }
      body.append(Utility.createInvoke(fact,weaver.getWorld(),interMethodBody));
      body.append(InstructionFactory.createReturn(BcelWorld.makeBcelType(mangledInterMethod.getReturnType())));
      if (weaver.getWorld().isInJava5Mode()) {
        createAnyBridgeMethodsForCovariance(weaver,munger,unMangledInterMethod,onType,gen,paramTypes);
      }
    }
 else {
    }
    if (weaver.getWorld().isInJava5Mode()) {
      String basicSignature=mangledInterMethod.getSignature();
      String genericSignature=((ResolvedMemberImpl)mangledInterMethod).getSignatureForAttribute();
      if (!basicSignature.equals(genericSignature)) {
        newMethod.addAttribute(createSignatureAttribute(gen.getConstantPool(),genericSignature));
      }
    }
    weaver.addLazyMethodGen(newMethod);
    weaver.getLazyClassGen().warnOnAddedMethod(newMethod.getMethod(),getSignature().getSourceLocation());
    addNeededSuperCallMethods(weaver,onType,munger.getSuperMethodsCalled());
    return true;
  }
 else   if (onInterface && !Modifier.isAbstract(unMangledInterMethod.getModifiers())) {
    if (!gen.getType().isTopmostImplementor(onType)) {
      ResolvedType rtx=gen.getType().getTopmostImplementor(onType);
      if (!rtx.isExposedToWeaver()) {
        ISourceLocation sLoc=munger.getSourceLocation();
        weaver.getWorld().getMessageHandler().handleMessage(MessageUtil.error(WeaverMessages.format(WeaverMessages.ITD_NON_EXPOSED_IMPLEMENTOR,rtx,getAspectType().getName()),(sLoc == null ? getAspectType().getSourceLocation() : sLoc)));
      }
 else {
      }
      return false;
    }
 else {
      ResolvedMember mangledInterMethod=AjcMemberMaker.interMethod(unMangledInterMethod,aspectType,false);
      LazyMethodGen mg=makeMethodGen(gen,mangledInterMethod);
      if (weaver.getWorld().isInJava5Mode()) {
        AnnotationX annotationsOnRealMember[]=null;
        ResolvedType toLookOn=aspectType;
        if (aspectType.isRawType())         toLookOn=aspectType.getGenericType();
        ResolvedMember realMember=getRealMemberForITDFromAspect(toLookOn,memberHoldingAnyAnnotations,false);
        if (realMember == null)         throw new BCException("String_Node_Str" + memberHoldingAnyAnnotations + "String_Node_Str"+ aspectType);
        annotationsOnRealMember=realMember.getAnnotations();
        if (annotationsOnRealMember != null) {
          for (int i=0; i < annotationsOnRealMember.length; i++) {
            AnnotationX annotationX=annotationsOnRealMember[i];
            AnnotationGen a=annotationX.getBcelAnnotation();
            AnnotationGen ag=new AnnotationGen(a,weaver.getLazyClassGen().getConstantPool(),true);
            mg.addAnnotation(new AnnotationX(ag,weaver.getWorld()));
          }
        }
      }
      if (mungingInterface) {
        mg.setAccessFlags(Modifier.PUBLIC | Modifier.ABSTRACT);
      }
      Type[] paramTypes=BcelWorld.makeBcelTypes(mangledInterMethod.getParameterTypes());
      Type returnType=BcelWorld.makeBcelType(mangledInterMethod.getReturnType());
      InstructionList body=mg.getBody();
      InstructionFactory fact=gen.getFactory();
      int pos=0;
      if (!mangledInterMethod.isStatic()) {
        body.append(InstructionFactory.createThis());
        pos++;
      }
      for (int i=0, len=paramTypes.length; i < len; i++) {
        Type paramType=paramTypes[i];
        body.append(InstructionFactory.createLoad(paramType,pos));
        pos+=paramType.getSize();
      }
      body.append(Utility.createInvoke(fact,weaver.getWorld(),interMethodBody));
      Type t=BcelWorld.makeBcelType(interMethodBody.getReturnType());
      if (!t.equals(returnType)) {
        body.append(fact.createCast(t,returnType));
      }
      body.append(InstructionFactory.createReturn(returnType));
      mg.definingType=onType;
      if (weaver.getWorld().isInJava5Mode()) {
        String basicSignature=mangledInterMethod.getSignature();
        String genericSignature=((ResolvedMemberImpl)mangledInterMethod).getSignatureForAttribute();
        if (!basicSignature.equals(genericSignature)) {
          mg.addAttribute(createSignatureAttribute(gen.getConstantPool(),genericSignature));
        }
      }
      weaver.addOrReplaceLazyMethodGen(mg);
      addNeededSuperCallMethods(weaver,onType,munger.getSuperMethodsCalled());
      if (munger.getDeclaredSignature() != null) {
        boolean needsbridging=false;
        ResolvedMember toBridgeTo=munger.getDeclaredSignature().parameterizedWith(null,munger.getSignature().getDeclaringType().resolve(getWorld()),false,munger.getTypeVariableAliases());
        if (!toBridgeTo.getReturnType().getErasureSignature().equals(munger.getSignature().getReturnType().getErasureSignature()))         needsbridging=true;
        UnresolvedType[] originalParams=toBridgeTo.getParameterTypes();
        UnresolvedType[] newParams=munger.getSignature().getParameterTypes();
        for (int ii=0; ii < originalParams.length; ii++) {
          if (!originalParams[ii].getErasureSignature().equals(newParams[ii].getErasureSignature()))           needsbridging=true;
        }
        if (toBridgeTo != null && needsbridging) {
          ResolvedMember bridgerMethod=AjcMemberMaker.bridgerToInterMethod(unMangledInterMethod,gen.getType());
          ResolvedMember bridgingSetter=AjcMemberMaker.interMethod(toBridgeTo,aspectType,false);
          LazyMethodGen bridgeMethod=makeMethodGen(gen,bridgingSetter);
          paramTypes=BcelWorld.makeBcelTypes(bridgingSetter.getParameterTypes());
          Type[] bridgingToParms=BcelWorld.makeBcelTypes(unMangledInterMethod.getParameterTypes());
          returnType=BcelWorld.makeBcelType(bridgingSetter.getReturnType());
          body=bridgeMethod.getBody();
          fact=gen.getFactory();
          pos=0;
          if (!bridgingSetter.isStatic()) {
            body.append(InstructionFactory.createThis());
            pos++;
          }
          for (int i=0, len=paramTypes.length; i < len; i++) {
            Type paramType=paramTypes[i];
            body.append(InstructionFactory.createLoad(paramType,pos));
            if (!bridgingSetter.getParameterTypes()[i].getErasureSignature().equals(unMangledInterMethod.getParameterTypes()[i].getErasureSignature())) {
              body.append(fact.createCast(paramType,bridgingToParms[i]));
            }
            pos+=paramType.getSize();
          }
          body.append(Utility.createInvoke(fact,weaver.getWorld(),bridgerMethod));
          body.append(InstructionFactory.createReturn(returnType));
          gen.addMethodGen(bridgeMethod);
        }
      }
      return true;
    }
  }
 else {
    return false;
  }
}

Fixed version (ground truth):
private boolean mungeNewMethod(BcelClassWeaver weaver,NewMethodTypeMunger munger){
  World w=weaver.getWorld();
  ResolvedMember unMangledInterMethod=munger.getSignature().resolve(w);
  ResolvedMember interMethodBody=munger.getDeclaredInterMethodBody(aspectType,w);
  ResolvedMember interMethodDispatcher=munger.getDeclaredInterMethodDispatcher(aspectType,w);
  ResolvedMember memberHoldingAnyAnnotations=interMethodDispatcher;
  ResolvedType onType=weaver.getWorld().resolve(unMangledInterMethod.getDeclaringType(),munger.getSourceLocation());
  LazyClassGen gen=weaver.getLazyClassGen();
  boolean mungingInterface=gen.isInterface();
  if (onType.isRawType())   onType=onType.getGenericType();
  boolean onInterface=onType.isInterface();
  if (onType.isAnnotation()) {
    signalError(WeaverMessages.ITDM_ON_ANNOTATION_NOT_ALLOWED,weaver,onType);
    return false;
  }
  if (onType.isEnum()) {
    signalError(WeaverMessages.ITDM_ON_ENUM_NOT_ALLOWED,weaver,onType);
    return false;
  }
  if (onInterface && gen.getLazyMethodGen(unMangledInterMethod.getName(),unMangledInterMethod.getSignature(),true) != null) {
    return false;
  }
  if (onType.equals(gen.getType())) {
    ResolvedMember mangledInterMethod=AjcMemberMaker.interMethod(unMangledInterMethod,aspectType,onInterface);
    LazyMethodGen newMethod=makeMethodGen(gen,mangledInterMethod);
    if (mungingInterface) {
      newMethod.setAccessFlags(Modifier.PUBLIC | Modifier.ABSTRACT);
    }
    if (weaver.getWorld().isInJava5Mode()) {
      AnnotationX annotationsOnRealMember[]=null;
      ResolvedType toLookOn=aspectType;
      if (aspectType.isRawType())       toLookOn=aspectType.getGenericType();
      ResolvedMember realMember=getRealMemberForITDFromAspect(toLookOn,memberHoldingAnyAnnotations,false);
      if (realMember == null)       throw new BCException("String_Node_Str" + memberHoldingAnyAnnotations + "String_Node_Str"+ aspectType);
      annotationsOnRealMember=realMember.getAnnotations();
      if (annotationsOnRealMember != null) {
        for (int i=0; i < annotationsOnRealMember.length; i++) {
          AnnotationX annotationX=annotationsOnRealMember[i];
          AnnotationGen a=annotationX.getBcelAnnotation();
          AnnotationGen ag=new AnnotationGen(a,weaver.getLazyClassGen().getConstantPool(),true);
          newMethod.addAnnotation(new AnnotationX(ag,weaver.getWorld()));
        }
      }
      List allDecams=weaver.getWorld().getDeclareAnnotationOnMethods();
      for (Iterator i=allDecams.iterator(); i.hasNext(); ) {
        DeclareAnnotation decaMC=(DeclareAnnotation)i.next();
        if (decaMC.matches(unMangledInterMethod,weaver.getWorld()) && newMethod.getEnclosingClass().getType() == aspectType) {
          newMethod.addAnnotation(decaMC.getAnnotationX());
        }
      }
    }
    if (!onInterface && !Modifier.isAbstract(mangledInterMethod.getModifiers())) {
      InstructionList body=newMethod.getBody();
      InstructionFactory fact=gen.getFactory();
      int pos=0;
      if (!unMangledInterMethod.isStatic()) {
        body.append(InstructionFactory.createThis());
        pos++;
      }
      Type[] paramTypes=BcelWorld.makeBcelTypes(mangledInterMethod.getParameterTypes());
      for (int i=0, len=paramTypes.length; i < len; i++) {
        Type paramType=paramTypes[i];
        body.append(InstructionFactory.createLoad(paramType,pos));
        pos+=paramType.getSize();
      }
      body.append(Utility.createInvoke(fact,weaver.getWorld(),interMethodBody));
      body.append(InstructionFactory.createReturn(BcelWorld.makeBcelType(mangledInterMethod.getReturnType())));
      if (weaver.getWorld().isInJava5Mode()) {
        createAnyBridgeMethodsForCovariance(weaver,munger,unMangledInterMethod,onType,gen,paramTypes);
      }
    }
 else {
    }
    if (weaver.getWorld().isInJava5Mode()) {
      String basicSignature=mangledInterMethod.getSignature();
      String genericSignature=((ResolvedMemberImpl)mangledInterMethod).getSignatureForAttribute();
      if (!basicSignature.equals(genericSignature)) {
        newMethod.addAttribute(createSignatureAttribute(gen.getConstantPool(),genericSignature));
      }
    }
    weaver.addLazyMethodGen(newMethod);
    weaver.getLazyClassGen().warnOnAddedMethod(newMethod.getMethod(),getSignature().getSourceLocation());
    addNeededSuperCallMethods(weaver,onType,munger.getSuperMethodsCalled());
    return true;
  }
 else   if (onInterface && !Modifier.isAbstract(unMangledInterMethod.getModifiers())) {
    if (!gen.getType().isTopmostImplementor(onType)) {
      ResolvedType rtx=gen.getType().getTopmostImplementor(onType);
      if (!rtx.isExposedToWeaver()) {
        ISourceLocation sLoc=munger.getSourceLocation();
        weaver.getWorld().getMessageHandler().handleMessage(MessageUtil.error(WeaverMessages.format(WeaverMessages.ITD_NON_EXPOSED_IMPLEMENTOR,rtx,getAspectType().getName()),(sLoc == null ? getAspectType().getSourceLocation() : sLoc)));
      }
 else {
      }
      return false;
    }
 else {
      ResolvedMember mangledInterMethod=AjcMemberMaker.interMethod(unMangledInterMethod,aspectType,false);
      LazyMethodGen mg=makeMethodGen(gen,mangledInterMethod);
      if (weaver.getWorld().isInJava5Mode()) {
        AnnotationX annotationsOnRealMember[]=null;
        ResolvedType toLookOn=aspectType;
        if (aspectType.isRawType())         toLookOn=aspectType.getGenericType();
        ResolvedMember realMember=getRealMemberForITDFromAspect(toLookOn,memberHoldingAnyAnnotations,false);
        if (realMember == null)         throw new BCException("String_Node_Str" + memberHoldingAnyAnnotations + "String_Node_Str"+ aspectType);
        annotationsOnRealMember=realMember.getAnnotations();
        if (annotationsOnRealMember != null) {
          for (int i=0; i < annotationsOnRealMember.length; i++) {
            AnnotationX annotationX=annotationsOnRealMember[i];
            AnnotationGen a=annotationX.getBcelAnnotation();
            AnnotationGen ag=new AnnotationGen(a,weaver.getLazyClassGen().getConstantPool(),true);
            mg.addAnnotation(new AnnotationX(ag,weaver.getWorld()));
          }
        }
      }
      if (mungingInterface) {
        mg.setAccessFlags(Modifier.PUBLIC | Modifier.ABSTRACT);
      }
      Type[] paramTypes=BcelWorld.makeBcelTypes(mangledInterMethod.getParameterTypes());
      Type returnType=BcelWorld.makeBcelType(mangledInterMethod.getReturnType());
      InstructionList body=mg.getBody();
      InstructionFactory fact=gen.getFactory();
      int pos=0;
      if (!mangledInterMethod.isStatic()) {
        body.append(InstructionFactory.createThis());
        pos++;
      }
      for (int i=0, len=paramTypes.length; i < len; i++) {
        Type paramType=paramTypes[i];
        body.append(InstructionFactory.createLoad(paramType,pos));
        pos+=paramType.getSize();
      }
      body.append(Utility.createInvoke(fact,weaver.getWorld(),interMethodBody));
      Type t=BcelWorld.makeBcelType(interMethodBody.getReturnType());
      if (!t.equals(returnType)) {
        body.append(fact.createCast(t,returnType));
      }
      body.append(InstructionFactory.createReturn(returnType));
      mg.definingType=onType;
      if (weaver.getWorld().isInJava5Mode()) {
        String basicSignature=mangledInterMethod.getSignature();
        String genericSignature=((ResolvedMemberImpl)mangledInterMethod).getSignatureForAttribute();
        if (!basicSignature.equals(genericSignature)) {
          mg.addAttribute(createSignatureAttribute(gen.getConstantPool(),genericSignature));
        }
      }
      weaver.addOrReplaceLazyMethodGen(mg);
      addNeededSuperCallMethods(weaver,onType,munger.getSuperMethodsCalled());
      if (munger.getDeclaredSignature() != null) {
        boolean needsbridging=false;
        ResolvedMember toBridgeTo=munger.getDeclaredSignature().parameterizedWith(null,munger.getSignature().getDeclaringType().resolve(getWorld()),false,munger.getTypeVariableAliases());
        if (!toBridgeTo.getReturnType().getErasureSignature().equals(munger.getSignature().getReturnType().getErasureSignature()))         needsbridging=true;
        UnresolvedType[] originalParams=toBridgeTo.getParameterTypes();
        UnresolvedType[] newParams=munger.getSignature().getParameterTypes();
        for (int ii=0; ii < originalParams.length; ii++) {
          if (!originalParams[ii].getErasureSignature().equals(newParams[ii].getErasureSignature()))           needsbridging=true;
        }
        if (needsbridging) {
          ResolvedMember bridgerMethod=AjcMemberMaker.bridgerToInterMethod(unMangledInterMethod,gen.getType());
          ResolvedMember bridgingSetter=AjcMemberMaker.interMethod(toBridgeTo,aspectType,false);
          LazyMethodGen bridgeMethod=makeMethodGen(gen,bridgingSetter);
          paramTypes=BcelWorld.makeBcelTypes(bridgingSetter.getParameterTypes());
          Type[] bridgingToParms=BcelWorld.makeBcelTypes(unMangledInterMethod.getParameterTypes());
          returnType=BcelWorld.makeBcelType(bridgingSetter.getReturnType());
          body=bridgeMethod.getBody();
          fact=gen.getFactory();
          pos=0;
          if (!bridgingSetter.isStatic()) {
            body.append(InstructionFactory.createThis());
            pos++;
          }
          for (int i=0, len=paramTypes.length; i < len; i++) {
            Type paramType=paramTypes[i];
            body.append(InstructionFactory.createLoad(paramType,pos));
            if (!bridgingSetter.getParameterTypes()[i].getErasureSignature().equals(unMangledInterMethod.getParameterTypes()[i].getErasureSignature())) {
              body.append(fact.createCast(paramType,bridgingToParms[i]));
            }
            pos+=paramType.getSize();
          }
          body.append(Utility.createInvoke(fact,weaver.getWorld(),bridgerMethod));
          body.append(InstructionFactory.createReturn(returnType));
          gen.addMethodGen(bridgeMethod);
        }
      }
      return true;
    }
  }
 else {
    return false;
  }
}