Program: 30160
Project: 30160
Buggy source:
public Object resolveEjbReference(EjbReferenceDescriptor ejbRefDesc,Context context) throws NamingException {
  Object jndiObj=null;
  boolean resolved=false;
  if (ejbRefDesc.isLocal()) {
    if (ejbRefDesc.hasLookupName()) {
      jndiObj=context.lookup(ejbRefDesc.getLookupName());
      resolved=true;
    }
  }
 else   if (!ejbRefDesc.hasJndiName() && ejbRefDesc.hasLookupName()) {
    jndiObj=context.lookup(ejbRefDesc.getLookupName());
    resolved=true;
  }
 else   if (ejbRefDesc.hasJndiName() && ejbRefDesc.getJndiName().startsWith("String_Node_Str") && !ejbRefDesc.getJndiName().startsWith("String_Node_Str")) {
    String remoteJndiName=ejbRefDesc.getJndiName();
    String appName=(String)context.lookup("String_Node_Str");
    String newPrefix="String_Node_Str" + appName + "String_Node_Str";
    int javaAppLength="String_Node_Str".length();
    String globalLookup=newPrefix + remoteJndiName.substring(javaAppLength);
    jndiObj=context.lookup(globalLookup);
    resolved=true;
  }
 else {
    String remoteJndiName=EJBUtils.getRemoteEjbJndiName(ejbRefDesc);
    ClassLoader origClassLoader=Utility.getClassLoader();
    boolean setCL=false;
    try {
      try {
        String refInterface=ejbRefDesc.isEJB30ClientView() ? ejbRefDesc.getEjbInterface() : ejbRefDesc.getHomeClassName();
        origClassLoader.loadClass(refInterface);
      }
 catch (      ClassNotFoundException e) {
        ClassLoader referringBundleClassLoader=ejbRefDesc.getReferringBundleDescriptor().getClassLoader();
        Utility.setContextClassLoader(referringBundleClassLoader);
        setCL=true;
      }
      if (remoteJndiName.startsWith(CORBANAME)) {
        GlassFishORBHelper orbHelper=habitat.getComponent(GlassFishORBHelper.class);
        ORB orb=orbHelper.getORB();
        jndiObj=(Object)orb.string_to_object(remoteJndiName);
      }
 else {
        jndiObj=context.lookup(remoteJndiName);
      }
    }
 catch (    Exception e) {
      NamingException ne=new NamingException("String_Node_Str" + ejbRefDesc + "String_Node_Str"+ remoteJndiName+ "String_Node_Str");
      ne.initCause(e);
      throw ne;
    }
 finally {
      if (setCL) {
        Utility.setContextClassLoader(origClassLoader);
      }
    }
  }
  return resolved ? jndiObj : EJBUtils.resolveEjbRefObject(ejbRefDesc,jndiObj);
}

Fixed version (ground truth):
@Override public Object resolveEjbReference(EjbReferenceDescriptor ejbRefDesc,Context context) throws NamingException {
  Object jndiObj=null;
  boolean resolved=false;
  if (ejbRefDesc.isLocal()) {
    if (ejbRefDesc.hasLookupName()) {
      jndiObj=context.lookup(ejbRefDesc.getLookupName());
      resolved=true;
    }
  }
 else   if (!ejbRefDesc.hasJndiName() && ejbRefDesc.hasLookupName()) {
    try {
      jndiObj=context.lookup(ejbRefDesc.getLookupName());
    }
 catch (    NamingException e) {
      ClassLoader oldLoader=null;
      try {
        oldLoader=Utility.setContextClassLoader(ejbRefDesc.getReferringBundleDescriptor().getClassLoader());
        jndiObj=context.lookup(ejbRefDesc.getLookupName());
      }
  finally {
        Utility.setContextClassLoader(oldLoader);
      }
    }
    resolved=true;
  }
 else   if (ejbRefDesc.hasJndiName() && ejbRefDesc.getJndiName().startsWith("String_Node_Str") && !ejbRefDesc.getJndiName().startsWith("String_Node_Str")) {
    String remoteJndiName=ejbRefDesc.getJndiName();
    String appName=(String)context.lookup("String_Node_Str");
    String newPrefix="String_Node_Str" + appName + "String_Node_Str";
    int javaAppLength="String_Node_Str".length();
    String globalLookup=newPrefix + remoteJndiName.substring(javaAppLength);
    jndiObj=context.lookup(globalLookup);
    resolved=true;
  }
 else {
    String remoteJndiName=EJBUtils.getRemoteEjbJndiName(ejbRefDesc);
    ClassLoader origClassLoader=Utility.getClassLoader();
    boolean setCL=false;
    try {
      try {
        String refInterface=ejbRefDesc.isEJB30ClientView() ? ejbRefDesc.getEjbInterface() : ejbRefDesc.getHomeClassName();
        origClassLoader.loadClass(refInterface);
      }
 catch (      ClassNotFoundException e) {
        ClassLoader referringBundleClassLoader=ejbRefDesc.getReferringBundleDescriptor().getClassLoader();
        Utility.setContextClassLoader(referringBundleClassLoader);
        setCL=true;
      }
      if (remoteJndiName.startsWith(CORBANAME)) {
        GlassFishORBHelper orbHelper=habitat.getComponent(GlassFishORBHelper.class);
        ORB orb=orbHelper.getORB();
        jndiObj=(Object)orb.string_to_object(remoteJndiName);
      }
 else {
        jndiObj=context.lookup(remoteJndiName);
      }
    }
 catch (    Exception e) {
      NamingException ne=new NamingException("String_Node_Str" + ejbRefDesc + "String_Node_Str"+ remoteJndiName+ "String_Node_Str");
      ne.initCause(e);
      throw ne;
    }
 finally {
      if (setCL) {
        Utility.setContextClassLoader(origClassLoader);
      }
    }
  }
  return resolved ? jndiObj : EJBUtils.resolveEjbRefObject(ejbRefDesc,jndiObj);
}