Program: 185672
Project: 185672
Buggy source:
public void resolveTypeExpecting(BlockScope scope,TypeBinding requiredType){
  if (this.value == null) {
    this.compilerElementPair=new ElementValuePair(this.name,this.value,this.binding);
    return;
  }
  if (requiredType == null) {
    if (this.value instanceof ArrayInitializer) {
      this.value.resolveTypeExpecting(scope,null);
    }
 else {
      this.value.resolveType(scope);
    }
    this.compilerElementPair=new ElementValuePair(this.name,this.value,this.binding);
    return;
  }
  TypeBinding[] vtb=null;
  if (isClass(requiredType) && isGroovy(scope)) {
    if (this.value instanceof ArrayInitializer) {
      Expression[] values=((ArrayInitializer)this.value).expressions;
      for (int i=0, n=values.length; i < n; i+=1) {
        values[i]=repairClassLiteralReference(values[i],scope,null);
      }
    }
 else {
      vtb=new TypeBinding[1];
      this.value=repairClassLiteralReference(this.value,scope,vtb);
    }
  }
  this.value.setExpectedType(requiredType);
  TypeBinding valueType;
  if (this.value instanceof ArrayInitializer) {
    ArrayInitializer initializer=(ArrayInitializer)this.value;
    valueType=initializer.resolveTypeExpecting(scope,this.binding.returnType);
  }
 else   if (this.value instanceof ArrayAllocationExpression) {
    scope.problemReporter().annotationValueMustBeArrayInitializer(this.binding.declaringClass,this.name,this.value);
    this.value.resolveType(scope);
    valueType=null;
  }
 else {
    valueType=(vtb != null && vtb[0] != null) ? vtb[0] : this.value.resolveType(scope);
    ASTVisitor visitor=new ASTVisitor(){
      public boolean visit(      SingleNameReference reference,      BlockScope scop){
        if (reference.binding instanceof LocalVariableBinding) {
          ((LocalVariableBinding)reference.binding).useFlag=LocalVariableBinding.USED;
        }
        return true;
      }
    }
;
    this.value.traverse(visitor,scope);
  }
  this.compilerElementPair=new ElementValuePair(this.name,this.value,this.binding);
  if (valueType == null)   return;
  TypeBinding leafType=requiredType.leafComponentType();
  if (!(this.value.isConstantValueOfTypeAssignableToType(valueType,requiredType) || valueType.isCompatibleWith(requiredType))) {
    if (!(requiredType.isArrayType() && requiredType.dimensions() == 1 && (this.value.isConstantValueOfTypeAssignableToType(valueType,leafType) || valueType.isCompatibleWith(leafType)))) {
      if (leafType.isAnnotationType() && !valueType.isAnnotationType()) {
        scope.problemReporter().annotationValueMustBeAnnotation(this.binding.declaringClass,this.name,this.value,leafType);
      }
 else {
        scope.problemReporter().typeMismatchError(valueType,requiredType,this.value,null);
      }
      return;
    }
  }
 else {
    scope.compilationUnitScope().recordTypeConversion(requiredType.leafComponentType(),valueType.leafComponentType());
    this.value.computeConversion(scope,requiredType,valueType);
  }
  checkAnnotationMethodType: {
switch (leafType.erasure().id) {
case T_byte:
case T_short:
case T_char:
case T_int:
case T_long:
case T_float:
case T_double:
case T_boolean:
case T_JavaLangString:
      if (this.value instanceof ArrayInitializer) {
        ArrayInitializer initializer=(ArrayInitializer)this.value;
        final Expression[] expressions=initializer.expressions;
        if (expressions != null) {
          for (int i=0, max=expressions.length; i < max; i++) {
            Expression expression=expressions[i];
            if (expression.resolvedType == null)             continue;
            if (expression.constant == Constant.NotAConstant) {
              scope.problemReporter().annotationValueMustBeConstant(this.binding.declaringClass,this.name,expressions[i],false);
            }
          }
        }
      }
 else       if (this.value.constant == Constant.NotAConstant) {
        if (valueType.isArrayType()) {
          scope.problemReporter().annotationValueMustBeArrayInitializer(this.binding.declaringClass,this.name,this.value);
        }
 else {
          scope.problemReporter().annotationValueMustBeConstant(this.binding.declaringClass,this.name,this.value,false);
        }
      }
    break checkAnnotationMethodType;
case T_JavaLangClass:
  if (this.value instanceof ArrayInitializer) {
    ArrayInitializer initializer=(ArrayInitializer)this.value;
    final Expression[] expressions=initializer.expressions;
    if (expressions != null) {
      for (int i=0, max=expressions.length; i < max; i++) {
        Expression currentExpression=expressions[i];
        if (!(currentExpression instanceof ClassLiteralAccess)) {
          scope.problemReporter().annotationValueMustBeClassLiteral(this.binding.declaringClass,this.name,currentExpression);
        }
      }
    }
  }
 else   if (!(this.value instanceof ClassLiteralAccess)) {
    scope.problemReporter().annotationValueMustBeClassLiteral(this.binding.declaringClass,this.name,this.value);
  }
break checkAnnotationMethodType;
}
if (leafType.isEnum()) {
if (this.value instanceof NullLiteral) {
scope.problemReporter().annotationValueMustBeConstant(this.binding.declaringClass,this.name,this.value,true);
}
 else if (this.value instanceof ArrayInitializer) {
ArrayInitializer initializer=(ArrayInitializer)this.value;
final Expression[] expressions=initializer.expressions;
if (expressions != null) {
  for (int i=0, max=expressions.length; i < max; i++) {
    Expression currentExpression=expressions[i];
    if (currentExpression instanceof NullLiteral) {
      scope.problemReporter().annotationValueMustBeConstant(this.binding.declaringClass,this.name,currentExpression,true);
    }
 else     if (currentExpression instanceof NameReference) {
      NameReference nameReference=(NameReference)currentExpression;
      final Binding nameReferenceBinding=nameReference.binding;
      if (nameReferenceBinding.kind() == Binding.FIELD) {
        FieldBinding fieldBinding=(FieldBinding)nameReferenceBinding;
        if (!fieldBinding.declaringClass.isEnum()) {
          scope.problemReporter().annotationValueMustBeConstant(this.binding.declaringClass,this.name,currentExpression,true);
        }
      }
    }
  }
}
}
 else if (this.value instanceof NameReference) {
NameReference nameReference=(NameReference)this.value;
final Binding nameReferenceBinding=nameReference.binding;
if (nameReferenceBinding.kind() == Binding.FIELD) {
  FieldBinding fieldBinding=(FieldBinding)nameReferenceBinding;
  if (!fieldBinding.declaringClass.isEnum()) {
    if (!fieldBinding.type.isArrayType()) {
      scope.problemReporter().annotationValueMustBeConstant(this.binding.declaringClass,this.name,this.value,true);
    }
 else {
      scope.problemReporter().annotationValueMustBeArrayInitializer(this.binding.declaringClass,this.name,this.value);
    }
  }
}
}
 else {
scope.problemReporter().annotationValueMustBeConstant(this.binding.declaringClass,this.name,this.value,true);
}
break checkAnnotationMethodType;
}
if (leafType.isAnnotationType()) {
if (!valueType.leafComponentType().isAnnotationType()) {
scope.problemReporter().annotationValueMustBeAnnotation(this.binding.declaringClass,this.name,this.value,leafType);
}
 else if (this.value instanceof ArrayInitializer) {
ArrayInitializer initializer=(ArrayInitializer)this.value;
final Expression[] expressions=initializer.expressions;
if (expressions != null) {
  for (int i=0, max=expressions.length; i < max; i++) {
    Expression currentExpression=expressions[i];
    if (currentExpression instanceof NullLiteral || !(currentExpression instanceof Annotation)) {
      scope.problemReporter().annotationValueMustBeAnnotation(this.binding.declaringClass,this.name,currentExpression,leafType);
    }
  }
}
}
 else if (!(this.value instanceof Annotation)) {
scope.problemReporter().annotationValueMustBeAnnotation(this.binding.declaringClass,this.name,this.value,leafType);
}
break checkAnnotationMethodType;
}
}
}

Fixed version (ground truth):
public void resolveTypeExpecting(BlockScope scope,TypeBinding requiredType){
  if (this.value == null) {
    this.compilerElementPair=new ElementValuePair(this.name,this.value,this.binding);
    return;
  }
  if (requiredType == null) {
    if (this.value instanceof ArrayInitializer) {
      this.value.resolveTypeExpecting(scope,null);
    }
 else {
      this.value.resolveType(scope);
    }
    this.compilerElementPair=new ElementValuePair(this.name,this.value,this.binding);
    return;
  }
  if (isClass(requiredType) && isGroovy(scope)) {
    if (this.value instanceof ArrayInitializer) {
      Expression[] values=((ArrayInitializer)this.value).expressions;
      for (int i=0, n=values.length; i < n; i+=1) {
        values[i]=repairClassLiteralReference(values[i],scope);
      }
    }
 else {
      this.value=repairClassLiteralReference(this.value,scope);
    }
  }
  this.value.setExpectedType(requiredType);
  TypeBinding valueType;
  if (this.value instanceof ArrayInitializer) {
    ArrayInitializer initializer=(ArrayInitializer)this.value;
    valueType=initializer.resolveTypeExpecting(scope,this.binding.returnType);
  }
 else   if (this.value instanceof ArrayAllocationExpression) {
    scope.problemReporter().annotationValueMustBeArrayInitializer(this.binding.declaringClass,this.name,this.value);
    this.value.resolveType(scope);
    valueType=null;
  }
 else {
    valueType=this.value.resolveType(scope);
    ASTVisitor visitor=new ASTVisitor(){
      public boolean visit(      SingleNameReference reference,      BlockScope scop){
        if (reference.binding instanceof LocalVariableBinding) {
          ((LocalVariableBinding)reference.binding).useFlag=LocalVariableBinding.USED;
        }
        return true;
      }
    }
;
    this.value.traverse(visitor,scope);
  }
  this.compilerElementPair=new ElementValuePair(this.name,this.value,this.binding);
  if (valueType == null)   return;
  TypeBinding leafType=requiredType.leafComponentType();
  if (!(this.value.isConstantValueOfTypeAssignableToType(valueType,requiredType) || valueType.isCompatibleWith(requiredType))) {
    if (!(requiredType.isArrayType() && requiredType.dimensions() == 1 && (this.value.isConstantValueOfTypeAssignableToType(valueType,leafType) || valueType.isCompatibleWith(leafType)))) {
      if (leafType.isAnnotationType() && !valueType.isAnnotationType()) {
        scope.problemReporter().annotationValueMustBeAnnotation(this.binding.declaringClass,this.name,this.value,leafType);
      }
 else {
        scope.problemReporter().typeMismatchError(valueType,requiredType,this.value,null);
      }
      return;
    }
  }
 else {
    scope.compilationUnitScope().recordTypeConversion(requiredType.leafComponentType(),valueType.leafComponentType());
    this.value.computeConversion(scope,requiredType,valueType);
  }
  checkAnnotationMethodType: {
switch (leafType.erasure().id) {
case T_byte:
case T_short:
case T_char:
case T_int:
case T_long:
case T_float:
case T_double:
case T_boolean:
case T_JavaLangString:
      if (this.value instanceof ArrayInitializer) {
        ArrayInitializer initializer=(ArrayInitializer)this.value;
        final Expression[] expressions=initializer.expressions;
        if (expressions != null) {
          for (int i=0, max=expressions.length; i < max; i++) {
            Expression expression=expressions[i];
            if (expression.resolvedType == null)             continue;
            if (expression.constant == Constant.NotAConstant) {
              scope.problemReporter().annotationValueMustBeConstant(this.binding.declaringClass,this.name,expressions[i],false);
            }
          }
        }
      }
 else       if (this.value.constant == Constant.NotAConstant) {
        if (valueType.isArrayType()) {
          scope.problemReporter().annotationValueMustBeArrayInitializer(this.binding.declaringClass,this.name,this.value);
        }
 else {
          scope.problemReporter().annotationValueMustBeConstant(this.binding.declaringClass,this.name,this.value,false);
        }
      }
    break checkAnnotationMethodType;
case T_JavaLangClass:
  if (this.value instanceof ArrayInitializer) {
    ArrayInitializer initializer=(ArrayInitializer)this.value;
    final Expression[] expressions=initializer.expressions;
    if (expressions != null) {
      for (int i=0, max=expressions.length; i < max; i++) {
        Expression currentExpression=expressions[i];
        if (!(currentExpression instanceof ClassLiteralAccess)) {
          scope.problemReporter().annotationValueMustBeClassLiteral(this.binding.declaringClass,this.name,currentExpression);
        }
      }
    }
  }
 else   if (!(this.value instanceof ClassLiteralAccess)) {
    scope.problemReporter().annotationValueMustBeClassLiteral(this.binding.declaringClass,this.name,this.value);
  }
break checkAnnotationMethodType;
}
if (leafType.isEnum()) {
if (this.value instanceof NullLiteral) {
scope.problemReporter().annotationValueMustBeConstant(this.binding.declaringClass,this.name,this.value,true);
}
 else if (this.value instanceof ArrayInitializer) {
ArrayInitializer initializer=(ArrayInitializer)this.value;
final Expression[] expressions=initializer.expressions;
if (expressions != null) {
  for (int i=0, max=expressions.length; i < max; i++) {
    Expression currentExpression=expressions[i];
    if (currentExpression instanceof NullLiteral) {
      scope.problemReporter().annotationValueMustBeConstant(this.binding.declaringClass,this.name,currentExpression,true);
    }
 else     if (currentExpression instanceof NameReference) {
      NameReference nameReference=(NameReference)currentExpression;
      final Binding nameReferenceBinding=nameReference.binding;
      if (nameReferenceBinding.kind() == Binding.FIELD) {
        FieldBinding fieldBinding=(FieldBinding)nameReferenceBinding;
        if (!fieldBinding.declaringClass.isEnum()) {
          scope.problemReporter().annotationValueMustBeConstant(this.binding.declaringClass,this.name,currentExpression,true);
        }
      }
    }
  }
}
}
 else if (this.value instanceof NameReference) {
NameReference nameReference=(NameReference)this.value;
final Binding nameReferenceBinding=nameReference.binding;
if (nameReferenceBinding.kind() == Binding.FIELD) {
  FieldBinding fieldBinding=(FieldBinding)nameReferenceBinding;
  if (!fieldBinding.declaringClass.isEnum()) {
    if (!fieldBinding.type.isArrayType()) {
      scope.problemReporter().annotationValueMustBeConstant(this.binding.declaringClass,this.name,this.value,true);
    }
 else {
      scope.problemReporter().annotationValueMustBeArrayInitializer(this.binding.declaringClass,this.name,this.value);
    }
  }
}
}
 else {
scope.problemReporter().annotationValueMustBeConstant(this.binding.declaringClass,this.name,this.value,true);
}
break checkAnnotationMethodType;
}
if (leafType.isAnnotationType()) {
if (!valueType.leafComponentType().isAnnotationType()) {
scope.problemReporter().annotationValueMustBeAnnotation(this.binding.declaringClass,this.name,this.value,leafType);
}
 else if (this.value instanceof ArrayInitializer) {
ArrayInitializer initializer=(ArrayInitializer)this.value;
final Expression[] expressions=initializer.expressions;
if (expressions != null) {
  for (int i=0, max=expressions.length; i < max; i++) {
    Expression currentExpression=expressions[i];
    if (currentExpression instanceof NullLiteral || !(currentExpression instanceof Annotation)) {
      scope.problemReporter().annotationValueMustBeAnnotation(this.binding.declaringClass,this.name,currentExpression,leafType);
    }
  }
}
}
 else if (!(this.value instanceof Annotation)) {
scope.problemReporter().annotationValueMustBeAnnotation(this.binding.declaringClass,this.name,this.value,leafType);
}
break checkAnnotationMethodType;
}
}
}