Program: 78934
Project: 78934
Buggy source:
/** 
 * Retrieves a context for resolving <code>name</code>. If the first component of <code>name</code> name is a URL string, then attempt to find a URL context for it. If none is found, or if the first component of <code>name</code> is not a URL string, then return <code>getDefaultInitCtx()</code>. <p> When creating a subclass of InitialContext, use this method as follows. Define a new method that uses this method to get an initial context of the desired subclass. <p><blockquote><pre> protected XXXContext getURLOrDefaultInitXXXCtx(Name name) throws NamingException { Context answer = getURLOrDefaultInitCtx(name); if (!(answer instanceof XXXContext)) { if (answer == null) { throw new NoInitialContextException(); } else { throw new NotContextException("Not an XXXContext"); } } return (XXXContext)answer; } </pre></blockquote> When providing implementations for the new methods in the subclass, use this newly defined method to get the initial context. <p><blockquote><pre> public Object XXXMethod1(Name name, ...) { throws NamingException { return getURLOrDefaultInitXXXCtx(name).XXXMethod1(name, ...); } </pre></blockquote>
 * @param name The non-null name for which to get the context.
 * @return A URL context for <code>name</code> or the cachedinitial context. The result cannot be null.
 * @exception NoInitialContextException If cannot find an initial context.
 * @exception NamingException In a naming exception is encountered.
 * @see javax.naming.spi.NamingManager#getURLContext
 */
protected Context getURLOrDefaultInitCtx(Name name) throws NamingException {
  if (NamingManager.hasInitialContextFactoryBuilder()) {
    return getDefaultInitCtx();
  }
  if (name.size() > 0) {
    String first=name.get(0);
    String scheme=getURLScheme(first);
    if (scheme != null) {
      Context ctx=NamingManager.getURLContext(scheme,myProps);
      if (ctx != null) {
        return ctx;
      }
    }
  }
  return getDefaultInitCtx();
}

Fixed version (ground truth):
/** 
 * Retrieves a context for resolving <code>name</code>. If the first component of <code>name</code> name is a URL string, then attempt to find a URL context for it. If none is found, or if the first component of <code>name</code> is not a URL string, then return <code>getDefaultInitCtx()</code>. <p> When creating a subclass of InitialContext, use this method as follows. Define a new method that uses this method to get an initial context of the desired subclass. <blockquote><pre> protected XXXContext getURLOrDefaultInitXXXCtx(Name name) throws NamingException { Context answer = getURLOrDefaultInitCtx(name); if (!(answer instanceof XXXContext)) { if (answer == null) { throw new NoInitialContextException(); } else { throw new NotContextException("Not an XXXContext"); } } return (XXXContext)answer; } </pre></blockquote> When providing implementations for the new methods in the subclass, use this newly defined method to get the initial context. <blockquote><pre> public Object XXXMethod1(Name name, ...) { throws NamingException { return getURLOrDefaultInitXXXCtx(name).XXXMethod1(name, ...); } </pre></blockquote>
 * @param name The non-null name for which to get the context.
 * @return A URL context for <code>name</code> or the cachedinitial context. The result cannot be null.
 * @exception NoInitialContextException If cannot find an initial context.
 * @exception NamingException In a naming exception is encountered.
 * @see javax.naming.spi.NamingManager#getURLContext
 */
protected Context getURLOrDefaultInitCtx(Name name) throws NamingException {
  if (NamingManager.hasInitialContextFactoryBuilder()) {
    return getDefaultInitCtx();
  }
  if (name.size() > 0) {
    String first=name.get(0);
    String scheme=getURLScheme(first);
    if (scheme != null) {
      Context ctx=NamingManager.getURLContext(scheme,myProps);
      if (ctx != null) {
        return ctx;
      }
    }
  }
  return getDefaultInitCtx();
}