Program: 91655
Project: 91655
Buggy source:
/** 
 * Invoked by   {@link MetadataProxy} for fetching an attribute value from a table.
 * @param info      the interface type (together with cached information).This is mapped to the table name in the database.
 * @param method    the method invoked. This is mapped to the column name in the database.
 * @param toSearch  contains the identifier and preferred index of the record to search.
 * @return the value of the requested attribute.
 * @throws SQLException if the SQL query failed.
 * @throws MetadataStoreException if a value was not found or can not be converted to the expected type.
 */
final Object readColumn(final LookupInfo info,final Method method,final Dispatcher toSearch) throws SQLException, MetadataStoreException {
  final Class<?> type=subType(info.getMetadataType(),toSearch.identifier);
  final Class<?> returnType=method.getReturnType();
  final boolean wantCollection=Collection.class.isAssignableFrom(returnType);
  final Class<?> elementType=wantCollection ? Classes.boundOfParameterizedProperty(method) : returnType;
  final boolean isMetadata=standard.isMetadata(elementType);
  final String tableName=getTableName(type);
  final String columnName=info.asNameMap(standard).get(method.getName());
  final boolean isArray;
  Object value;
synchronized (this) {
    if (!getExistingColumns(tableName).contains(columnName)) {
      value=null;
      isArray=false;
    }
 else {
      CachedStatement result=take(type,Byte.toUnsignedInt(toSearch.preferredIndex));
      if (result == null) {
        final SQLBuilder helper=helper();
        final String query=helper.clear().append("String_Node_Str").appendIdentifier(schema,tableName).append("String_Node_Str").append(ID_COLUMN).append("String_Node_Str").toString();
        result=new CachedStatement(type,connection().prepareStatement(query),listeners);
      }
      value=result.getValue(toSearch.identifier,columnName);
      isArray=(value instanceof java.sql.Array);
      if (isArray) {
        final java.sql.Array array=(java.sql.Array)value;
        value=array.getArray();
        array.free();
      }
      toSearch.preferredIndex=(byte)recycle(result,Byte.toUnsignedInt(toSearch.preferredIndex));
    }
  }
  if (isArray && (wantCollection || !elementType.isPrimitive())) {
    final Object[] values=new Object[Array.getLength(value)];
    for (int i=0; i < values.length; i++) {
      Object element=Array.get(value,i);
      if (element != null) {
        if (isMetadata) {
          element=lookup(elementType,element.toString());
        }
 else         try {
          element=info.convert(elementType,element);
        }
 catch (        UnconvertibleObjectException e) {
          throw new MetadataStoreException(Errors.format(Errors.Keys.IllegalPropertyValueClass_3,columnName + '[' + i+ ']',elementType,element.getClass()),e);
        }
      }
      values[i]=element;
    }
    value=values;
    if (wantCollection) {
      value=specialize(UnmodifiableArrayList.wrap(values),returnType,elementType);
    }
  }
  if (value != null) {
    if (isMetadata) {
      value=lookup(elementType,value.toString());
    }
 else     try {
      value=info.convert(elementType,value);
    }
 catch (    UnconvertibleObjectException e) {
      throw new MetadataStoreException(Errors.format(Errors.Keys.IllegalPropertyValueClass_3,columnName,elementType,value.getClass()),e);
    }
    if (wantCollection) {
      if (Set.class.isAssignableFrom(returnType)) {
        return Collections.singleton(value);
      }
 else {
        return Collections.singletonList(value);
      }
    }
  }
  return value;
}

Fixed version (ground truth):
/** 
 * Invoked by   {@link MetadataProxy} for fetching an attribute value from a table.
 * @param info      the interface type (together with cached information).This is mapped to the table name in the database.
 * @param method    the method invoked. This is mapped to the column name in the database.
 * @param toSearch  contains the identifier and preferred index of the record to search.
 * @return the value of the requested attribute.
 * @throws SQLException if the SQL query failed.
 * @throws MetadataStoreException if a value was not found or can not be converted to the expected type.
 */
final Object readColumn(final LookupInfo info,final Method method,final Dispatcher toSearch) throws SQLException, MetadataStoreException {
  final Class<?> type=TableHierarchy.subType(info.getMetadataType(),toSearch.identifier);
  final Class<?> returnType=method.getReturnType();
  final boolean wantCollection=Collection.class.isAssignableFrom(returnType);
  final Class<?> elementType=wantCollection ? Classes.boundOfParameterizedProperty(method) : returnType;
  final boolean isMetadata=standard.isMetadata(elementType);
  final String tableName=getTableName(type);
  final String columnName=info.asNameMap(standard).get(method.getName());
  final boolean isArray;
  Object value;
synchronized (this) {
    if (!getExistingColumns(tableName).contains(columnName)) {
      value=null;
      isArray=false;
    }
 else {
      CachedStatement result=take(type,Byte.toUnsignedInt(toSearch.preferredIndex));
      if (result == null) {
        final SQLBuilder helper=helper();
        final String query=helper.clear().append("String_Node_Str").appendIdentifier(schema,tableName).append("String_Node_Str").appendIdentifier(ID_COLUMN).append("String_Node_Str").toString();
        result=new CachedStatement(type,connection().prepareStatement(query),listeners);
      }
      value=result.getValue(toSearch.identifier,columnName);
      isArray=(value instanceof java.sql.Array);
      if (isArray) {
        final java.sql.Array array=(java.sql.Array)value;
        value=array.getArray();
        array.free();
      }
      toSearch.preferredIndex=(byte)recycle(result,Byte.toUnsignedInt(toSearch.preferredIndex));
    }
  }
  if (isArray && (wantCollection || !elementType.isPrimitive())) {
    final Object[] values=new Object[Array.getLength(value)];
    for (int i=0; i < values.length; i++) {
      Object element=Array.get(value,i);
      if (element != null) {
        if (isMetadata) {
          element=lookup(elementType,element.toString());
        }
 else         try {
          element=info.convert(elementType,element);
        }
 catch (        UnconvertibleObjectException e) {
          throw new MetadataStoreException(Errors.format(Errors.Keys.IllegalPropertyValueClass_3,columnName + '[' + i+ ']',elementType,element.getClass()),e);
        }
      }
      values[i]=element;
    }
    value=values;
    if (wantCollection) {
      value=specialize(UnmodifiableArrayList.wrap(values),returnType,elementType);
    }
  }
  if (value != null) {
    if (isMetadata) {
      value=lookup(elementType,value.toString());
    }
 else     try {
      value=info.convert(elementType,value);
    }
 catch (    UnconvertibleObjectException e) {
      throw new MetadataStoreException(Errors.format(Errors.Keys.IllegalPropertyValueClass_3,columnName,elementType,value.getClass()),e);
    }
    if (wantCollection) {
      if (Set.class.isAssignableFrom(returnType)) {
        return Collections.singleton(value);
      }
 else {
        return Collections.singletonList(value);
      }
    }
  }
  return value;
}