Program: 59283
Project: 59283
Buggy source:
/** 
 * @param testCase
 * @param field
 * @return returns the name of the cube if this cube would be linked by its parent, or null
 * @throws IllegalAccessException
 * @throws IOException
 * @throws InvocationTargetException
 */
private String enrichField(Object testCase,Field field) throws IllegalAccessException, IOException, InvocationTargetException {
  final Object cubeContainerObject=field.get(testCase);
  if (cubeContainerObject == null) {
    final Cube cubeAnnotation=field.getAnnotation(Cube.class);
    final Class<?> cubeContainerClazz=field.getType();
    final String cubeName=getCubeName(cubeAnnotation,cubeContainerClazz);
    final String[] cubePortBinding=getPortBindings(cubeAnnotation,cubeContainerClazz);
    final List<Method> methodsWithCubeDockerFile=ReflectionUtil.getMethodsWithAnnotation(cubeContainerClazz,CubeDockerFile.class);
    if (methodsWithCubeDockerFile.size() > 1) {
      throw new IllegalArgumentException(String.format("String_Node_Str",CubeDockerFile.class.getSimpleName(),CubeDockerFile.class.getSimpleName(),methodsWithCubeDockerFile));
    }
    if ((methodsWithCubeDockerFile.size() == 1 || cubeContainerClazz.isAnnotationPresent(CubeDockerFile.class)) && cubeContainerClazz.isAnnotationPresent(Image.class)) {
      throw new IllegalArgumentException(String.format("String_Node_Str",cubeContainerClazz.getSimpleName(),Image.class.getSimpleName(),CubeDockerFile.class.getSimpleName()));
    }
    File output=null;
    boolean imageSet=false;
    CubeDockerFile cubeContainerClazzAnnotation=null;
    if (methodsWithCubeDockerFile.size() == 1) {
      Method annotatedMethodWithCubeDockerFile=methodsWithCubeDockerFile.get(0);
      cubeContainerClazzAnnotation=annotatedMethodWithCubeDockerFile.getAnnotation(CubeDockerFile.class);
      final Object archive=annotatedMethodWithCubeDockerFile.invoke(null,new Object[0]);
      if (archive instanceof Archive) {
        Archive<?> genericArchive=(Archive)archive;
        output=createTemporalDirectoryForCopyingDockerfile(cubeContainerClazz,cubeName);
        logger.finer(String.format("String_Node_Str",output,cubeName));
        genericArchive.as(ExplodedExporter.class).exportExplodedInto(output);
      }
    }
 else {
      if (cubeContainerClazz.isAnnotationPresent(CubeDockerFile.class)) {
        cubeContainerClazzAnnotation=cubeContainerClazz.getAnnotation(CubeDockerFile.class);
        output=createTemporalDirectoryForCopyingDockerfile(cubeContainerClazz,cubeName);
        logger.finer(String.format("String_Node_Str",output,cubeName));
        DockerFileUtil.copyDockerfileDirectory(cubeContainerClazz,cubeContainerClazzAnnotation,output);
      }
 else {
        if (!cubeContainerClazz.isAnnotationPresent(Image.class)) {
          throw new IllegalArgumentException(String.format("String_Node_Str",testCase.getClass().getName(),cubeContainerClazz.getName(),CubeDockerFile.class.getSimpleName(),Image.class.getSimpleName()));
        }
        imageSet=true;
      }
    }
    final Object containerObjectInstance=ReflectionUtil.newInstance(cubeContainerClazz.getName(),new Class[0],new Class[0],cubeContainerClazz);
    enrichContainerObject(containerObjectInstance);
    field.set(testCase,containerObjectInstance);
    final Set<String> links=enrichAndReturnLinks(containerObjectInstance);
    org.arquillian.cube.spi.Cube cube;
    if (imageSet) {
      cube=createCubeFromImage(cubeName,cubePortBinding,links,cubeContainerClazz.getAnnotation(Image.class),output,testCase.getClass());
    }
 else {
      cube=createCubeFromDockerfile(cubeName,cubePortBinding,links,cubeContainerClazzAnnotation,output,testCase.getClass());
    }
    logger.finer(String.format("String_Node_Str",cubeName,cube.configuration()));
    cubeRegistryInstance.get().addCube(cube);
    CubeController cubeController=cubeControllerInstance.get();
    cubeController.create(cubeName);
    cubeController.start(cubeName);
    return link(field,cubeName);
  }
  return null;
}

Fixed version (ground truth):
/** 
 * @param testCase
 * @param field
 * @return returns the name of the cube if this cube would be linked by its parent, or null
 * @throws IllegalAccessException
 * @throws IOException
 * @throws InvocationTargetException
 */
private String enrichField(Object testCase,Field field) throws IllegalAccessException, IOException, InvocationTargetException {
  final Object cubeContainerObject=field.get(testCase);
  if (cubeContainerObject == null) {
    final Cube cubeAnnotation=field.getAnnotation(Cube.class);
    final Class<?> cubeContainerClazz=field.getType();
    final String cubeName=getCubeName(cubeAnnotation,cubeContainerClazz);
    final String[] cubePortBinding=getPortBindings(cubeAnnotation,cubeContainerClazz);
    final List<Method> methodsWithCubeDockerFile=ReflectionUtil.getMethodsWithAnnotation(cubeContainerClazz,CubeDockerFile.class);
    if (methodsWithCubeDockerFile.size() > 1) {
      throw new IllegalArgumentException(String.format("String_Node_Str",CubeDockerFile.class.getSimpleName(),CubeDockerFile.class.getSimpleName(),methodsWithCubeDockerFile));
    }
    if ((methodsWithCubeDockerFile.size() == 1 || cubeContainerClazz.isAnnotationPresent(CubeDockerFile.class)) && cubeContainerClazz.isAnnotationPresent(Image.class)) {
      throw new IllegalArgumentException(String.format("String_Node_Str",cubeContainerClazz.getSimpleName(),Image.class.getSimpleName(),CubeDockerFile.class.getSimpleName()));
    }
    File output=null;
    boolean imageSet=false;
    CubeDockerFile cubeContainerClazzAnnotation=null;
    if (methodsWithCubeDockerFile.size() == 1) {
      Method annotatedMethodWithCubeDockerFile=methodsWithCubeDockerFile.get(0);
      cubeContainerClazzAnnotation=annotatedMethodWithCubeDockerFile.getAnnotation(CubeDockerFile.class);
      final Object archive=annotatedMethodWithCubeDockerFile.invoke(null,new Object[0]);
      if (archive instanceof Archive) {
        Archive<?> genericArchive=(Archive)archive;
        output=createTemporalDirectoryForCopyingDockerfile(cubeContainerClazz,cubeName);
        logger.finer(String.format("String_Node_Str",output,cubeName));
        genericArchive.as(ExplodedExporter.class).exportExplodedInto(output);
      }
    }
 else {
      if (cubeContainerClazz.isAnnotationPresent(CubeDockerFile.class)) {
        cubeContainerClazzAnnotation=cubeContainerClazz.getAnnotation(CubeDockerFile.class);
        output=createTemporalDirectoryForCopyingDockerfile(cubeContainerClazz,cubeName);
        logger.finer(String.format("String_Node_Str",output,cubeName));
        DockerFileUtil.copyDockerfileDirectory(cubeContainerClazz,cubeContainerClazzAnnotation,output);
      }
 else {
        if (!cubeContainerClazz.isAnnotationPresent(Image.class)) {
          throw new IllegalArgumentException(String.format("String_Node_Str",testCase.getClass().getName(),cubeContainerClazz.getName(),CubeDockerFile.class.getSimpleName(),Image.class.getSimpleName()));
        }
        imageSet=true;
      }
    }
    final Object containerObjectInstance=ReflectionUtil.newInstance(cubeContainerClazz.getName(),new Class[0],new Class[0],cubeContainerClazz);
    enrichContainerObject(containerObjectInstance);
    field.set(testCase,containerObjectInstance);
    final Set<String> links=enrichAndReturnLinks(containerObjectInstance);
    org.arquillian.cube.spi.Cube cube;
    if (imageSet) {
      cube=createCubeFromImage(cubeName,cubePortBinding,links,cubeContainerClazz.getAnnotation(Image.class),output,testCase.getClass());
    }
 else {
      cube=createCubeFromDockerfile(cubeName,cubePortBinding,links,cubeContainerClazzAnnotation,output,testCase.getClass());
    }
    logger.finer(String.format("String_Node_Str",cubeName,cube.configuration()));
    cubeRegistryInstance.get().addCube(cube);
    CubeController cubeController=cubeControllerInstance.get();
    cubeController.create(cubeName);
    cubeController.start(cubeName);
    enrichHostPort(containerObjectInstance,cube);
    return link(field,cubeName);
  }
  return null;
}