Program: 34755
Project: 34755
Buggy source:
private Operation parseMethod(Class<?> cls,Method method,List<Parameter> globalParameters,Produces methodProduces,Produces classProduces,Consumes methodConsumes,Consumes classConsumes,List<SecurityRequirement> classSecurityRequirements,Optional<org.eclipse.microprofile.openapi.models.ExternalDocumentation> classExternalDocs,Set<String> classTags,List<org.eclipse.microprofile.openapi.models.servers.Server> classServers,Map<String,Callback> classCallbacks){
  Operation operation=new OperationImpl();
  org.eclipse.microprofile.openapi.annotations.Operation apiOperation=ReflectionUtils.getAnnotation(method,org.eclipse.microprofile.openapi.annotations.Operation.class);
  List<org.eclipse.microprofile.openapi.annotations.security.SecurityRequirement> apiSecurity=ReflectionUtils.getRepeatableAnnotations(method,org.eclipse.microprofile.openapi.annotations.security.SecurityRequirement.class);
  List<org.eclipse.microprofile.openapi.annotations.callbacks.Callback> apiCallbacks=ReflectionUtils.getRepeatableAnnotations(method,org.eclipse.microprofile.openapi.annotations.callbacks.Callback.class);
  List<Server> apiServers=ReflectionUtils.getRepeatableAnnotations(method,Server.class);
  List<org.eclipse.microprofile.openapi.annotations.tags.Tag> apiTags=ReflectionUtils.getRepeatableAnnotations(method,org.eclipse.microprofile.openapi.annotations.tags.Tag.class);
  org.eclipse.microprofile.openapi.annotations.tags.Tags tagsAnnotation=ReflectionUtils.getAnnotation(method,org.eclipse.microprofile.openapi.annotations.tags.Tags.class);
  List<org.eclipse.microprofile.openapi.annotations.parameters.Parameter> apiParameters=ReflectionUtils.getRepeatableAnnotations(method,org.eclipse.microprofile.openapi.annotations.parameters.Parameter.class);
  List<org.eclipse.microprofile.openapi.annotations.responses.APIResponse> apiResponses=ReflectionUtils.getRepeatableAnnotations(method,org.eclipse.microprofile.openapi.annotations.responses.APIResponse.class);
  List<Extension> apiExtensions=ReflectionUtils.getRepeatableAnnotations(method,Extension.class);
  ExternalDocumentation apiExternalDocumentation=ReflectionUtils.getAnnotation(method,ExternalDocumentation.class);
  Map<String,Callback> callbacks=new LinkedHashMap<>();
  if (apiCallbacks != null) {
    for (    org.eclipse.microprofile.openapi.annotations.callbacks.Callback methodCallback : apiCallbacks) {
      Map<String,Callback> currentCallbacks=getCallbacks(methodCallback);
      callbacks.putAll(currentCallbacks);
    }
  }
  if (!callbacks.isEmpty()) {
    operation.setCallbacks(callbacks);
  }
 else {
    operation.setCallbacks(classCallbacks);
  }
  if (apiSecurity != null && apiSecurity.size() > 0) {
    Optional<List<SecurityRequirement>> requirementsObject=SecurityParser.getSecurityRequirements(apiSecurity.toArray(new org.eclipse.microprofile.openapi.annotations.security.SecurityRequirement[apiSecurity.size()]));
    if (requirementsObject.isPresent()) {
      requirementsObject.get().stream().filter(r -> operation.getSecurity() == null || !operation.getSecurity().contains(r)).forEach(operation::addSecurityRequirement);
    }
  }
 else {
    classSecurityRequirements.forEach(operation::addSecurityRequirement);
  }
  if (apiServers != null && apiServers.size() > 0) {
    AnnotationsUtils.getServers(apiServers.toArray(new Server[apiServers.size()])).ifPresent(servers -> servers.forEach(operation::addServer));
  }
 else   if (classServers != null && classServers.size() > 0) {
    operation.setServers(classServers);
  }
  AnnotationsUtils.getExternalDocumentation(apiExternalDocumentation).ifPresent(operation::setExternalDocs);
  if ((apiTags != null && !apiTags.isEmpty()) || (tagsAnnotation != null && ArrayUtils.isNotEmpty(tagsAnnotation.refs()))) {
    Stream<String> operationTags=Stream.empty();
    if (apiTags != null) {
      operationTags=apiTags.stream().filter(t -> StringUtils.isNotBlank(t.name()) || StringUtils.isNotBlank(t.ref())).map(t -> {
        if (StringUtils.isNotBlank(t.ref())) {
          return t.ref();
        }
 else {
          return t.name();
        }
      }
);
      AnnotationsUtils.getTags(apiTags.toArray(new org.eclipse.microprofile.openapi.annotations.tags.Tag[apiTags.size()]),true).ifPresent(tags -> openApiTags.addAll(tags));
    }
    if (tagsAnnotation != null && ArrayUtils.isNotEmpty(tagsAnnotation.refs())) {
      operationTags=Stream.concat(operationTags,Stream.of(tagsAnnotation.refs()).filter(StringUtils::isNotBlank));
    }
    operationTags.distinct().forEach(operation::addTag);
  }
 else   if (classTags != null) {
    operation.setTags(new ArrayList<>(classTags));
  }
  if (globalParameters != null) {
    for (    Parameter globalParameter : globalParameters) {
      operation.addParameter(globalParameter);
    }
  }
  if (apiParameters != null) {
    getParametersListFromAnnotation(apiParameters.toArray(new org.eclipse.microprofile.openapi.annotations.parameters.Parameter[apiParameters.size()]),classConsumes,methodConsumes,operation).ifPresent(p -> p.forEach(operation::addParameter));
  }
  if (apiResponses != null) {
    OperationParser.getApiResponses(apiResponses.toArray(new org.eclipse.microprofile.openapi.annotations.responses.APIResponse[apiResponses.size()]),classProduces,methodProduces,components).ifPresent(responses -> {
      if (operation.getResponses() == null) {
        operation.setResponses(responses);
      }
 else {
        responses.forEach(operation.getResponses()::addApiResponse);
      }
    }
);
  }
  if (StringUtils.isBlank(operation.getOperationId())) {
    operation.setOperationId(method.getName());
  }
  if (apiOperation != null) {
    setOperationObjectFromApiOperationAnnotation(operation,apiOperation,methodProduces,classProduces,methodConsumes,classConsumes);
  }
  if (operation.getExternalDocs() == null) {
    classExternalDocs.ifPresent(operation::setExternalDocs);
  }
  Type returnType=method.getGenericReturnType();
  if (!shouldIgnoreClass(returnType.getTypeName())) {
    ResolvedSchema resolvedSchema=ModelConverters.getInstance().resolveAnnotatedType(returnType,new ArrayList<>(),"String_Node_Str");
    if (resolvedSchema.schema != null) {
      Schema returnTypeSchema=resolvedSchema.schema;
      Content content=new ContentImpl();
      MediaType mediaType=new MediaTypeImpl().schema(returnTypeSchema);
      AnnotationsUtils.applyTypes(classConsumes == null ? new String[0] : classConsumes.value(),methodConsumes == null ? new String[0] : methodConsumes.value(),content,mediaType);
      if (operation.getResponses() == null) {
        operation.responses(new APIResponsesImpl().defaultValue(new APIResponseImpl().description(DEFAULT_DESCRIPTION).content(content)));
      }
      if (operation.getResponses().getDefault() != null && StringUtils.isBlank(operation.getResponses().getDefault().getRef()) && operation.getResponses().getDefault().getContent() == null) {
        operation.getResponses().getDefault().content(content);
      }
      Map<String,Schema> schemaMap=resolvedSchema.referencedSchemas;
      if (schemaMap != null) {
        schemaMap.forEach((key,schema) -> components.addSchema(key,schema));
      }
    }
  }
  if (operation.getResponses() == null || operation.getResponses().size() == 0) {
    APIResponse apiResponseObject=new APIResponseImpl();
    apiResponseObject.setDescription(DEFAULT_DESCRIPTION);
    operation.setResponses(new APIResponsesImpl().defaultValue(apiResponseObject));
  }
  return operation;
}

Fixed version (ground truth):
private Operation parseMethod(Class<?> cls,Method method,List<Parameter> globalParameters,Produces methodProduces,Produces classProduces,Consumes methodConsumes,Consumes classConsumes,List<SecurityRequirement> classSecurityRequirements,Optional<org.eclipse.microprofile.openapi.models.ExternalDocumentation> classExternalDocs,Set<String> classTags,List<org.eclipse.microprofile.openapi.models.servers.Server> classServers,Map<String,Callback> classCallbacks){
  Operation operation=new OperationImpl();
  org.eclipse.microprofile.openapi.annotations.Operation apiOperation=ReflectionUtils.getAnnotation(method,org.eclipse.microprofile.openapi.annotations.Operation.class);
  List<org.eclipse.microprofile.openapi.annotations.security.SecurityRequirement> apiSecurity=ReflectionUtils.getRepeatableAnnotations(method,org.eclipse.microprofile.openapi.annotations.security.SecurityRequirement.class);
  List<org.eclipse.microprofile.openapi.annotations.callbacks.Callback> apiCallbacks=ReflectionUtils.getRepeatableAnnotations(method,org.eclipse.microprofile.openapi.annotations.callbacks.Callback.class);
  List<Server> apiServers=ReflectionUtils.getRepeatableAnnotations(method,Server.class);
  List<org.eclipse.microprofile.openapi.annotations.tags.Tag> apiTags=ReflectionUtils.getRepeatableAnnotations(method,org.eclipse.microprofile.openapi.annotations.tags.Tag.class);
  org.eclipse.microprofile.openapi.annotations.tags.Tags tagsAnnotation=ReflectionUtils.getAnnotation(method,org.eclipse.microprofile.openapi.annotations.tags.Tags.class);
  List<org.eclipse.microprofile.openapi.annotations.parameters.Parameter> apiParameters=ReflectionUtils.getRepeatableAnnotations(method,org.eclipse.microprofile.openapi.annotations.parameters.Parameter.class);
  List<org.eclipse.microprofile.openapi.annotations.responses.APIResponse> apiResponses=ReflectionUtils.getRepeatableAnnotations(method,org.eclipse.microprofile.openapi.annotations.responses.APIResponse.class);
  List<Extension> apiExtensions=ReflectionUtils.getRepeatableAnnotations(method,Extension.class);
  ExternalDocumentation apiExternalDocumentation=ReflectionUtils.getAnnotation(method,ExternalDocumentation.class);
  Map<String,Callback> callbacks=new LinkedHashMap<>();
  if (apiCallbacks != null) {
    for (    org.eclipse.microprofile.openapi.annotations.callbacks.Callback methodCallback : apiCallbacks) {
      Map<String,Callback> currentCallbacks=getCallbacks(methodCallback);
      callbacks.putAll(currentCallbacks);
    }
  }
  if (!callbacks.isEmpty()) {
    operation.setCallbacks(callbacks);
  }
 else {
    operation.setCallbacks(classCallbacks);
  }
  if (apiSecurity != null && apiSecurity.size() > 0) {
    Optional<List<SecurityRequirement>> requirementsObject=SecurityParser.getSecurityRequirements(apiSecurity.toArray(new org.eclipse.microprofile.openapi.annotations.security.SecurityRequirement[apiSecurity.size()]));
    if (requirementsObject.isPresent()) {
      requirementsObject.get().stream().filter(r -> operation.getSecurity() == null || !operation.getSecurity().contains(r)).forEach(operation::addSecurityRequirement);
    }
  }
 else {
    classSecurityRequirements.forEach(operation::addSecurityRequirement);
  }
  if (apiServers != null && apiServers.size() > 0) {
    AnnotationsUtils.getServers(apiServers.toArray(new Server[apiServers.size()])).ifPresent(servers -> servers.forEach(operation::addServer));
  }
 else   if (classServers != null && classServers.size() > 0) {
    operation.setServers(classServers);
  }
  AnnotationsUtils.getExternalDocumentation(apiExternalDocumentation).ifPresent(operation::setExternalDocs);
  if ((apiTags != null && !apiTags.isEmpty()) || (tagsAnnotation != null && ArrayUtils.isNotEmpty(tagsAnnotation.refs()))) {
    Stream<String> operationTags=Stream.empty();
    if (apiTags != null) {
      operationTags=apiTags.stream().filter(t -> StringUtils.isNotBlank(t.name()) || StringUtils.isNotBlank(t.ref())).map(t -> {
        if (StringUtils.isNotBlank(t.ref())) {
          return t.ref();
        }
 else {
          return t.name();
        }
      }
);
      AnnotationsUtils.getTags(apiTags.toArray(new org.eclipse.microprofile.openapi.annotations.tags.Tag[apiTags.size()]),true).ifPresent(tags -> openApiTags.addAll(tags));
    }
    if (tagsAnnotation != null && ArrayUtils.isNotEmpty(tagsAnnotation.refs())) {
      operationTags=Stream.concat(operationTags,Stream.of(tagsAnnotation.refs()).filter(StringUtils::isNotBlank));
    }
    operationTags.distinct().forEach(operation::addTag);
  }
 else   if (classTags != null && !classTags.isEmpty()) {
    operation.setTags(new ArrayList<>(classTags));
  }
  if (globalParameters != null) {
    for (    Parameter globalParameter : globalParameters) {
      operation.addParameter(globalParameter);
    }
  }
  if (apiParameters != null) {
    getParametersListFromAnnotation(apiParameters.toArray(new org.eclipse.microprofile.openapi.annotations.parameters.Parameter[apiParameters.size()]),classConsumes,methodConsumes,operation).ifPresent(p -> p.forEach(operation::addParameter));
  }
  if (apiResponses != null) {
    OperationParser.getApiResponses(apiResponses.toArray(new org.eclipse.microprofile.openapi.annotations.responses.APIResponse[apiResponses.size()]),classProduces,methodProduces,components).ifPresent(responses -> {
      if (operation.getResponses() == null) {
        operation.setResponses(responses);
      }
 else {
        responses.forEach(operation.getResponses()::addApiResponse);
      }
    }
);
  }
  if (StringUtils.isBlank(operation.getOperationId())) {
    operation.setOperationId(method.getName());
  }
  if (apiOperation != null) {
    setOperationObjectFromApiOperationAnnotation(operation,apiOperation,methodProduces,classProduces,methodConsumes,classConsumes);
  }
  if (operation.getExternalDocs() == null) {
    classExternalDocs.ifPresent(operation::setExternalDocs);
  }
  Type returnType=method.getGenericReturnType();
  if (!shouldIgnoreClass(returnType.getTypeName())) {
    ResolvedSchema resolvedSchema=ModelConverters.getInstance().resolveAnnotatedType(returnType,new ArrayList<>(),"String_Node_Str");
    if (resolvedSchema.schema != null) {
      Schema returnTypeSchema=resolvedSchema.schema;
      Content content=new ContentImpl();
      MediaType mediaType=new MediaTypeImpl().schema(returnTypeSchema);
      AnnotationsUtils.applyTypes(classConsumes == null ? new String[0] : classConsumes.value(),methodConsumes == null ? new String[0] : methodConsumes.value(),content,mediaType);
      if (operation.getResponses() == null) {
        operation.responses(new APIResponsesImpl().defaultValue(new APIResponseImpl().description(DEFAULT_DESCRIPTION).content(content)));
      }
      if (operation.getResponses().getDefault() != null && StringUtils.isBlank(operation.getResponses().getDefault().getRef()) && operation.getResponses().getDefault().getContent() == null) {
        operation.getResponses().getDefault().content(content);
      }
      Map<String,Schema> schemaMap=resolvedSchema.referencedSchemas;
      if (schemaMap != null) {
        schemaMap.forEach((key,schema) -> components.addSchema(key,schema));
      }
    }
  }
  if (operation.getResponses() == null || operation.getResponses().size() == 0) {
    APIResponse apiResponseObject=new APIResponseImpl();
    apiResponseObject.setDescription(DEFAULT_DESCRIPTION);
    operation.setResponses(new APIResponsesImpl().defaultValue(apiResponseObject));
  }
  return operation;
}