Program: 91656
Project: 91656
Buggy source:
/** 
 * Returns an implementation of the specified metadata interface filled with the data referenced by the specified identifier. Alternatively, this method can also return a   {@link CodeList} or{@link Enum} element.
 * @param < T >         the parameterized type of the {@code type} argument.
 * @param type        the interface to implement (e.g. {@link org.opengis.metadata.citation.Citation}), or the   {@link ControlledVocabulary} type ({@link CodeList} or some {@link Enum}).
 * @param identifier  the identifier of the record for the metadata entity to be created.This is usually the primary key of the record to search for.
 * @return an implementation of the required interface, or the code list element.
 * @throws MetadataStoreException if a SQL query failed.
 */
public <T>T lookup(final Class<T> type,final String identifier) throws MetadataStoreException {
  ArgumentChecks.ensureNonNull("String_Node_Str",type);
  ArgumentChecks.ensureNonEmpty("String_Node_Str",identifier);
  Object value;
  if (ControlledVocabulary.class.isAssignableFrom(type)) {
    value=getCodeList(type,identifier);
  }
 else {
    final CacheKey key=new CacheKey(type,identifier);
synchronized (pool) {
      value=pool.get(key);
      if (value == null && type.isInterface()) {
        value=Proxy.newProxyInstance(classloader,new Class<?>[]{type,MetadataProxy.class},new Dispatcher(identifier,this));
        pool.put(key,value);
      }
    }
    if (value == null) {
      Method method=null;
      final Class<?> subType=subType(type,identifier);
      final Dispatcher toSearch=new Dispatcher(identifier,this);
      try {
        value=subType.getConstructor().newInstance();
        final LookupInfo info=getLookupInfo(subType);
        final Map<String,Object> map=asValueMap(value);
        final Map<String,String> methods=standard.asNameMap(subType,NAME_POLICY,KeyNamePolicy.METHOD_NAME);
        for (        final Map.Entry<String,Object> entry : map.entrySet()) {
          method=subType.getMethod(methods.get(entry.getKey()));
          info.setMetadataType(subType);
          final Object p=readColumn(info,method,toSearch);
          if (p != null) {
            entry.setValue(p);
          }
        }
      }
 catch (      ReflectiveOperationException e) {
        throw new MetadataStoreException(Errors.format(Errors.Keys.UnsupportedImplementation_1,subType),e);
      }
catch (      SQLException e) {
        throw new MetadataStoreException(toSearch.error(method),e);
      }
    }
  }
  return type.cast(value);
}

Fixed version (ground truth):
/** 
 * Returns an implementation of the specified metadata interface filled with the data referenced by the specified identifier. Alternatively, this method can also return a   {@link CodeList} or{@link Enum} element.
 * @param < T >         the parameterized type of the {@code type} argument.
 * @param type        the interface to implement (e.g. {@link org.opengis.metadata.citation.Citation}), or the   {@link ControlledVocabulary} type ({@link CodeList} or some {@link Enum}).
 * @param identifier  the identifier of the record for the metadata entity to be created.This is usually the primary key of the record to search for.
 * @return an implementation of the required interface, or the code list element.
 * @throws MetadataStoreException if a SQL query failed.
 */
public <T>T lookup(final Class<T> type,final String identifier) throws MetadataStoreException {
  ArgumentChecks.ensureNonNull("String_Node_Str",type);
  ArgumentChecks.ensureNonEmpty("String_Node_Str",identifier);
  Object value;
  if (ControlledVocabulary.class.isAssignableFrom(type)) {
    value=getCodeList(type,identifier);
  }
 else {
    final CacheKey key=new CacheKey(type,identifier);
synchronized (pool) {
      value=pool.get(key);
      if (value == null && type.isInterface()) {
        value=Proxy.newProxyInstance(classloader,new Class<?>[]{type,MetadataProxy.class},new Dispatcher(identifier,this));
        pool.put(key,value);
      }
    }
    if (value == null) {
      Method method=null;
      final Class<?> subType=TableHierarchy.subType(type,identifier);
      final Dispatcher toSearch=new Dispatcher(identifier,this);
      try {
        value=subType.getConstructor().newInstance();
        final LookupInfo info=getLookupInfo(subType);
        final Map<String,Object> map=asValueMap(value);
        final Map<String,String> methods=standard.asNameMap(subType,NAME_POLICY,KeyNamePolicy.METHOD_NAME);
        for (        final Map.Entry<String,Object> entry : map.entrySet()) {
          method=subType.getMethod(methods.get(entry.getKey()));
          info.setMetadataType(subType);
          final Object p=readColumn(info,method,toSearch);
          if (p != null) {
            entry.setValue(p);
          }
        }
      }
 catch (      ReflectiveOperationException e) {
        throw new MetadataStoreException(Errors.format(Errors.Keys.UnsupportedImplementation_1,subType),e);
      }
catch (      SQLException e) {
        throw new MetadataStoreException(toSearch.error(method),e);
      }
    }
  }
  return type.cast(value);
}