Program: 91971
Project: 91971
Buggy source:
/** 
 * Creates an object from a code using the given proxy.
 * @param < T >   The type of the object to be returned.
 * @param proxy The proxy to use for creating the object.
 * @param code  The code of the object to create.
 * @return The object from one of the authority factory specified at construction time.
 * @throws FactoryException If an error occurred while creating the object.
 */
final <T>T create(AuthorityFactoryProxy<? extends T> proxy,String code) throws FactoryException {
  ArgumentChecks.ensureNonNull("String_Node_Str",code);
  final String authority, version;
  final String[] parameters;
  final DefinitionURI uri=DefinitionURI.parse(code);
  if (uri != null) {
    final Class<? extends T> type=proxy.type;
    authority=uri.authority;
    version=uri.version;
    code=uri.code;
    parameters=uri.parameters;
    proxy=proxy.specialize(uri.type);
    if (code == null || proxy == null) {
      final String s=uri.toString();
      final String message;
      if (code == null) {
        message=Errors.format(Errors.Keys.MissingComponentInElement_2,s,"String_Node_Str");
      }
 else {
        message=Errors.format(Errors.Keys.CanNotCreateObjectOfType_2,type,uri.type);
      }
      throw new NoSuchAuthorityCodeException(message,authority,code,s);
    }
  }
 else {
    int afterAuthority=code.indexOf(DefaultNameSpace.DEFAULT_SEPARATOR);
    int end=CharSequences.skipTrailingWhitespaces(code,0,afterAuthority);
    int start=CharSequences.skipLeadingWhitespaces(code,0,end);
    if (start >= end) {
      throw new NoSuchAuthorityCodeException(Errors.format(Errors.Keys.MissingAuthority_1,code),null,code);
    }
    authority=code.substring(start,end);
    int afterVersion=code.indexOf(DefaultNameSpace.DEFAULT_SEPARATOR,++afterAuthority);
    start=CharSequences.skipLeadingWhitespaces(code,afterAuthority,afterVersion);
    end=CharSequences.skipTrailingWhitespaces(code,start,afterVersion);
    version=(start < end && !code.regionMatches(start,DefinitionURI.NO_VERSION,0,DefinitionURI.NO_VERSION.length())) ? code.substring(start,end) : null;
    code=CharSequences.trimWhitespaces(code,Math.max(afterAuthority,afterVersion + 1),code.length()).toString();
    parameters=null;
  }
  if (parameters != null || code.indexOf(CommonAuthorityFactory.SEPARATOR) >= 0) {
    final StringBuilder buffer=new StringBuilder(authority.length() + code.length() + 1).append(authority).append(DefaultNameSpace.DEFAULT_SEPARATOR).append(code);
    if (parameters != null) {
      for (      final String p : parameters) {
        buffer.append(CommonAuthorityFactory.SEPARATOR).append(p);
      }
    }
    code=buffer.toString();
  }
  return proxy.createFromAPI(getAuthorityFactory(AuthorityFactoryIdentifier.create(proxy.factoryType,authority,version)),code);
}

Fixed version (ground truth):
/** 
 * Creates an object from a code using the given proxy.
 * @param < T >   The type of the object to be returned.
 * @param proxy The proxy to use for creating the object.
 * @param code  The code of the object to create.
 * @return The object from one of the authority factory specified at construction time.
 * @throws FactoryException If an error occurred while creating the object.
 */
final <T>T create(AuthorityFactoryProxy<? extends T> proxy,String code) throws FactoryException {
  ArgumentChecks.ensureNonNull("String_Node_Str",code);
  final String authority, version;
  final String[] parameters;
  final DefinitionURI uri=DefinitionURI.parse(code);
  if (uri != null) {
    if (uri.authority == null) {
      throw new NoSuchAuthorityCodeException(Errors.format(Errors.Keys.MissingAuthority_1,code),null,uri.code,code);
    }
    final Class<? extends T> type=proxy.type;
    authority=uri.authority;
    version=uri.version;
    code=uri.code;
    parameters=uri.parameters;
    proxy=proxy.specialize(uri.type);
    if (code == null || proxy == null) {
      final String s=uri.toString();
      final String message;
      if (code == null) {
        message=Errors.format(Errors.Keys.MissingComponentInElement_2,s,"String_Node_Str");
      }
 else {
        message=Errors.format(Errors.Keys.CanNotCreateObjectOfType_2,type,uri.type);
      }
      throw new NoSuchAuthorityCodeException(message,authority,code,s);
    }
  }
 else {
    int afterAuthority=code.indexOf(DefaultNameSpace.DEFAULT_SEPARATOR);
    int end=CharSequences.skipTrailingWhitespaces(code,0,afterAuthority);
    int start=CharSequences.skipLeadingWhitespaces(code,0,end);
    if (start >= end) {
      throw new NoSuchAuthorityCodeException(Errors.format(Errors.Keys.MissingAuthority_1,code),null,code);
    }
    authority=code.substring(start,end);
    int afterVersion=code.indexOf(DefaultNameSpace.DEFAULT_SEPARATOR,++afterAuthority);
    start=CharSequences.skipLeadingWhitespaces(code,afterAuthority,afterVersion);
    end=CharSequences.skipTrailingWhitespaces(code,start,afterVersion);
    version=(start < end && !code.regionMatches(start,DefinitionURI.NO_VERSION,0,DefinitionURI.NO_VERSION.length())) ? code.substring(start,end) : null;
    code=CharSequences.trimWhitespaces(code,Math.max(afterAuthority,afterVersion + 1),code.length()).toString();
    parameters=null;
  }
  if (parameters != null || code.indexOf(CommonAuthorityFactory.SEPARATOR) >= 0) {
    final StringBuilder buffer=new StringBuilder(authority.length() + code.length() + 1).append(authority).append(DefaultNameSpace.DEFAULT_SEPARATOR).append(code);
    if (parameters != null) {
      for (      final String p : parameters) {
        buffer.append(CommonAuthorityFactory.SEPARATOR).append(p);
      }
    }
    code=buffer.toString();
  }
  return proxy.createFromAPI(getAuthorityFactory(AuthorityFactoryIdentifier.create(proxy.factoryType,authority,version)),code);
}