Program: 185629
Project: 185629
Buggy source:
private String checkQualifiedType(TypeLookupResult result,IJavaElement enclosingElement) throws JavaModelException {
  if (result.declaration instanceof ClassNode || result.declaration instanceof ConstructorNode) {
    ClassNode type=result.type;
    if (type == null)     type=result.declaringType;
    if (type == null)     type=(ClassNode)result.declaration;
    int typeStart=startOffset(type), typeEnd=endOffset(type);
    type=GroovyUtils.getBaseType(type);
    if (typeEnd > 0) {
      String source=gunit.getSource().substring(typeStart,typeEnd);
      int nameStart=typeStart + source.indexOf(GroovyUtils.splitName(type)[1]);
      if (nameStart > typeStart && nameStart > selectRegion.getEnd() && selectRegion.getEnd() > typeStart) {
        String selected=gunit.getSource().substring(typeStart,selectRegion.getEnd());
        selected=selected.replaceAll("String_Node_Str","String_Node_Str");
        String qualifier=GroovyUtils.splitName(type)[0].replace('$','.');
        Pattern pattern=Pattern.compile("String_Node_Str" + selected + "String_Node_Str");
        Matcher matcher=pattern.matcher(qualifier);
        if (matcher.find()) {
          return matcher.group();
        }
        pattern=Pattern.compile("String_Node_Str" + selected + "String_Node_Str");
        matcher=pattern.matcher(qualifier);
        if (matcher.find()) {
          return qualifier.substring(0,matcher.end());
        }
        ImportNode alias=findImportAlias(selected,enclosingElement);
        if (alias != null) {
          selected=selected.replace(alias.getAlias(),alias.getType().getNameWithoutPackage());
          pattern=Pattern.compile("String_Node_Str" + selected + "String_Node_Str");
          matcher=pattern.matcher(qualifier);
          if (matcher.find()) {
            return qualifier.substring(0,matcher.end());
          }
        }
      }
    }
  }
  return null;
}

Fixed version (ground truth):
private String checkQualifiedType(TypeLookupResult result,IJavaElement enclosingElement) throws JavaModelException {
  if (result.declaration instanceof ClassNode || result.declaration instanceof ConstructorNode) {
    ClassNode type=result.type;
    if (type == null)     type=result.declaringType;
    if (type == null)     type=(ClassNode)result.declaration;
    int typeStart=startOffset(type), typeEnd=endOffset(type);
    type=GroovyUtils.getBaseType(type);
    if (typeStart >= 0 && typeEnd > typeStart) {
      String gunitSource=gunit.getSource();
      if (typeEnd == gunitSource.length() + 1)       typeEnd=gunitSource.length();
 else       if (typeEnd > gunitSource.length())       return null;
      String source=gunitSource.substring(typeStart,typeEnd);
      int nameStart=typeStart + source.indexOf(GroovyUtils.splitName(type)[1]);
      if (nameStart > typeStart && nameStart > selectRegion.getEnd() && selectRegion.getEnd() > typeStart) {
        String selected=gunitSource.substring(typeStart,selectRegion.getEnd());
        selected=selected.replaceAll("String_Node_Str","String_Node_Str");
        String qualifier=GroovyUtils.splitName(type)[0].replace('$','.');
        Pattern pattern=Pattern.compile("String_Node_Str" + selected + "String_Node_Str");
        Matcher matcher=pattern.matcher(qualifier);
        if (matcher.find()) {
          return matcher.group();
        }
        pattern=Pattern.compile("String_Node_Str" + selected + "String_Node_Str");
        matcher=pattern.matcher(qualifier);
        if (matcher.find()) {
          return qualifier.substring(0,matcher.end());
        }
        ImportNode alias=findImportAlias(selected,enclosingElement);
        if (alias != null) {
          selected=selected.replace(alias.getAlias(),alias.getType().getNameWithoutPackage());
          pattern=Pattern.compile("String_Node_Str" + selected + "String_Node_Str");
          matcher=pattern.matcher(qualifier);
          if (matcher.find()) {
            return qualifier.substring(0,matcher.end());
          }
        }
      }
    }
  }
  return null;
}