Program: 30121
Project: 30121
Buggy source:
public Object resolveWSReference(ServiceReferenceDescriptor desc,Context context) throws NamingException {
  Class serviceInterfaceClass=null;
  Object returnObj=null;
  WsUtil wsUtil=new WsUtil();
  InitialContext iContext=new InitialContext();
  if (desc.hasLookupName()) {
    return iContext.lookup(desc.getLookupName());
  }
  try {
    WSContainerResolver.set(desc);
    ClassLoader cl=Thread.currentThread().getContextClassLoader();
    serviceInterfaceClass=cl.loadClass(desc.getServiceInterface());
    resolvePortComponentLinks(desc);
    javax.xml.rpc.Service serviceDelegate=null;
    javax.xml.ws.Service jaxwsDelegate=null;
    Object injValue=null;
    if (desc.hasGeneratedServiceInterface() || desc.hasWsdlFile()) {
      String serviceImplName=desc.getServiceImplClassName();
      if (serviceImplName != null) {
        Class serviceImplClass=cl.loadClass(serviceImplName);
        serviceDelegate=(javax.xml.rpc.Service)serviceImplClass.newInstance();
      }
 else {
        if (javax.xml.ws.Service.class.isAssignableFrom(serviceInterfaceClass) && !javax.xml.ws.Service.class.equals(serviceInterfaceClass)) {
          injValue=initiateInstance(serviceInterfaceClass,desc);
        }
 else {
          if (desc.isInjectable()) {
            InjectionTarget target=desc.getInjectionTargets().iterator().next();
            Class serviceType=null;
            if (target.isFieldInjectable()) {
              java.lang.reflect.Field f=target.getField();
              if (f == null) {
                String fName=target.getFieldName();
                Class targetClass=cl.loadClass(target.getClassName());
                try {
                  f=targetClass.getDeclaredField(fName);
                }
 catch (                java.lang.NoSuchFieldException nsfe) {
                }
              }
              serviceType=f.getType();
            }
            if (target.isMethodInjectable()) {
              Method m=target.getMethod();
              if (m == null) {
                String mName=target.getMethodName();
                Class targetClass=cl.loadClass(target.getClassName());
                try {
                  m=targetClass.getDeclaredMethod(mName);
                }
 catch (                java.lang.NoSuchMethodException nsfe) {
                }
              }
              if (m.getParameterTypes().length == 1) {
                serviceType=m.getParameterTypes()[0];
              }
            }
            if (serviceType != null) {
              Class loadedSvcClass=cl.loadClass(serviceType.getCanonicalName());
              injValue=initiateInstance(loadedSvcClass,desc);
            }
          }
        }
        if (injValue == null) {
          javax.xml.ws.Service svc=javax.xml.ws.Service.create((new WsUtil()).privilegedGetServiceRefWsdl(desc),desc.getServiceName());
          jaxwsDelegate=new JAXWSServiceDelegate(desc,svc,cl);
        }
      }
      if (desc.hasHandlers()) {
        javax.xml.rpc.Service configuredService=wsUtil.createConfiguredService(desc);
        Iterator ports=configuredService.getPorts();
        wsUtil.configureHandlerChain(desc,serviceDelegate,ports,cl);
      }
      if (javax.xml.ws.Service.class.isAssignableFrom(serviceInterfaceClass)) {
        javax.xml.ws.Service service=(injValue != null ? (javax.xml.ws.Service)injValue : jaxwsDelegate);
        if (service != null) {
          wsUtil.configureJAXWSClientHandlers(service,desc);
        }
        if (injValue != null && desc.getInjectionTargetType() != null) {
          Class requestedPortType=service.getClass().getClassLoader().loadClass(desc.getInjectionTargetType());
          ArrayList<WebServiceFeature> wsFeatures=getWebServiceFeatures(desc);
          if (wsFeatures.size() > 0) {
            injValue=service.getPort(requestedPortType,wsFeatures.toArray(new WebServiceFeature[wsFeatures.size()]));
          }
 else {
            injValue=service.getPort(requestedPortType);
          }
        }
      }
    }
 else {
      QName serviceName=desc.getServiceName();
      if (serviceName == null) {
        serviceName=new QName("String_Node_Str","String_Node_Str");
      }
      ServiceFactory serviceFac=ServiceFactory.newInstance();
      serviceDelegate=serviceFac.createService(serviceName);
    }
    InvocationHandler handler=null;
    if (serviceDelegate != null) {
      handler=new ServiceInvocationHandler(desc,serviceDelegate,cl);
      returnObj=Proxy.newProxyInstance(cl,new Class[]{serviceInterfaceClass},handler);
    }
 else     if (jaxwsDelegate != null) {
      returnObj=jaxwsDelegate;
    }
 else     if (injValue != null) {
      returnObj=injValue;
    }
  }
 catch (  PrivilegedActionException pae) {
    logger.log(Level.WARNING,"String_Node_Str",pae);
    NamingException ne=new NamingException();
    ne.initCause(pae.getCause());
    throw ne;
  }
catch (  Exception e) {
    logger.log(Level.WARNING,"String_Node_Str",e);
    NamingException ne=new NamingException();
    ne.initCause(e);
    throw ne;
  }
 finally {
    WSContainerResolver.unset();
  }
  return returnObj;
}

Fixed version (ground truth):
public Object resolveWSReference(ServiceReferenceDescriptor desc,Context context) throws NamingException {
  Class serviceInterfaceClass=null;
  Object returnObj=null;
  WsUtil wsUtil=new WsUtil();
  InitialContext iContext=new InitialContext();
  if (desc.hasLookupName()) {
    return iContext.lookup(desc.getLookupName());
  }
  try {
    WSContainerResolver.set(desc);
    ClassLoader cl=Thread.currentThread().getContextClassLoader();
    serviceInterfaceClass=cl.loadClass(desc.getServiceInterface());
    resolvePortComponentLinks(desc);
    javax.xml.rpc.Service serviceDelegate=null;
    javax.xml.ws.Service jaxwsDelegate=null;
    Object injValue=null;
    if (desc.hasGeneratedServiceInterface() || desc.hasWsdlFile()) {
      String serviceImplName=desc.getServiceImplClassName();
      if (serviceImplName != null) {
        Class serviceImplClass=cl.loadClass(serviceImplName);
        serviceDelegate=(javax.xml.rpc.Service)serviceImplClass.newInstance();
      }
 else {
        if (javax.xml.ws.Service.class.isAssignableFrom(serviceInterfaceClass) && !javax.xml.ws.Service.class.equals(serviceInterfaceClass)) {
          injValue=initiateInstance(serviceInterfaceClass,desc);
        }
 else {
          if (desc.isInjectable()) {
            InjectionTarget target=desc.getInjectionTargets().iterator().next();
            Class serviceType=null;
            if (target.isFieldInjectable()) {
              java.lang.reflect.Field f=target.getField();
              if (f == null) {
                String fName=target.getFieldName();
                Class targetClass=cl.loadClass(target.getClassName());
                try {
                  f=targetClass.getDeclaredField(fName);
                }
 catch (                java.lang.NoSuchFieldException nsfe) {
                }
              }
              if (f != null) {
                serviceType=f.getType();
              }
            }
            if (target.isMethodInjectable()) {
              Method m=target.getMethod();
              if (m == null) {
                String mName=target.getMethodName();
                Class targetClass=cl.loadClass(target.getClassName());
                try {
                  m=targetClass.getDeclaredMethod(mName);
                }
 catch (                java.lang.NoSuchMethodException nsfe) {
                }
              }
              if (m != null && m.getParameterTypes().length == 1) {
                serviceType=m.getParameterTypes()[0];
              }
            }
            if (serviceType != null) {
              Class loadedSvcClass=cl.loadClass(serviceType.getCanonicalName());
              injValue=initiateInstance(loadedSvcClass,desc);
            }
          }
        }
        if (injValue == null) {
          javax.xml.ws.Service svc=javax.xml.ws.Service.create((new WsUtil()).privilegedGetServiceRefWsdl(desc),desc.getServiceName());
          jaxwsDelegate=new JAXWSServiceDelegate(desc,svc,cl);
        }
      }
      if (desc.hasHandlers()) {
        javax.xml.rpc.Service configuredService=wsUtil.createConfiguredService(desc);
        Iterator ports=configuredService.getPorts();
        wsUtil.configureHandlerChain(desc,serviceDelegate,ports,cl);
      }
      if (javax.xml.ws.Service.class.isAssignableFrom(serviceInterfaceClass)) {
        javax.xml.ws.Service service=(injValue != null ? (javax.xml.ws.Service)injValue : jaxwsDelegate);
        if (service != null) {
          wsUtil.configureJAXWSClientHandlers(service,desc);
        }
        if (injValue != null && desc.getInjectionTargetType() != null) {
          Class requestedPortType=service.getClass().getClassLoader().loadClass(desc.getInjectionTargetType());
          ArrayList<WebServiceFeature> wsFeatures=getWebServiceFeatures(desc);
          if (wsFeatures.size() > 0) {
            injValue=service.getPort(requestedPortType,wsFeatures.toArray(new WebServiceFeature[wsFeatures.size()]));
          }
 else {
            injValue=service.getPort(requestedPortType);
          }
        }
      }
    }
 else {
      QName serviceName=desc.getServiceName();
      if (serviceName == null) {
        serviceName=new QName("String_Node_Str","String_Node_Str");
      }
      ServiceFactory serviceFac=ServiceFactory.newInstance();
      serviceDelegate=serviceFac.createService(serviceName);
    }
    InvocationHandler handler=null;
    if (serviceDelegate != null) {
      handler=new ServiceInvocationHandler(desc,serviceDelegate,cl);
      returnObj=Proxy.newProxyInstance(cl,new Class[]{serviceInterfaceClass},handler);
    }
 else     if (jaxwsDelegate != null) {
      returnObj=jaxwsDelegate;
    }
 else     if (injValue != null) {
      returnObj=injValue;
    }
  }
 catch (  PrivilegedActionException pae) {
    logger.log(Level.WARNING,"String_Node_Str",pae);
    NamingException ne=new NamingException();
    ne.initCause(pae.getCause());
    throw ne;
  }
catch (  Exception e) {
    logger.log(Level.WARNING,"String_Node_Str",e);
    NamingException ne=new NamingException();
    ne.initCause(e);
    throw ne;
  }
 finally {
    WSContainerResolver.unset();
  }
  return returnObj;
}