Program: 80072
Project: 80072
Buggy source:
/** 
 * Write SQLUDTGRP (SQL Descriptor User-Defined Type Group Descriptor) This is the format from the DRDA spec, Volume 1, section 5.6.4.10. However, this format is not rich enough to carry the information needed by JDBC. This format does not have a subtype code for JAVA_OBJECT and this format does not convey the Java class name needed by ResultSetMetaData.getColumnClassName(). SQLUDXTYPE; DRDA TYPE I4; ENVLID 0x02; Length Override 4 Constants which map to java.sql.Types constants DISTINCT, STRUCT, and REF. But DRDA does not define a constant which maps to java.sql.Types.JAVA_OBJECT. SQLUDTRDB; DRDA TYPE VCS; ENVLID 0x32; Length Override 255 Database name. SQLUDTSCHEMA_m; DRDA TYPE VCM; ENVLID 0x3E; Length Override 255 SQLUDTSCHEMA_s; DRDA TYPE VCS; ENVLID 0x32; Length Override 255 Schema name. One of the above. SQLUDTNAME_m; DRDA TYPE VCM; ENVLID 0x3E; Length Override 255 SQLUDTNAME_s; DRDA TYPE VCS; ENVLID 0x32; Length Override 255 Unqualified UDT name. One of the above. Instead, we use the following format and only for communication between Derby servers and Derby clients which are both at version 10.6 or higher. For all other client/server combinations, we send null. SQLUDTNAME_m; DRDA TYPE VCM; ENVLID 0x3E; Length Override 255 SQLUDTNAME_s; DRDA TYPE VCS; ENVLID 0x32; Length Override 255 Fully qualified UDT name. One of the above. SQLUDTCLASSNAME_m; DRDA TYPE VCM; ENVLID 0x3E; Length Override FdocaConstants.LONGVARCHAR_MAX_LEN SQLUDTCLASSNAME_s; DRDA TYPE VCS; ENVLID 0x32; Length Override FdocaConstants.LONGVARCHAR_MAX_LEN Name of the Java class bound to the UDT. One of the above.
 * @param rsmeta	resultset meta data
 * @param pmeta		parameter meta data
 * @param elemNum	column number we are returning (in case of result set), or,parameter number (in case of parameter)
 * @param rtnOutput	whether this is for a result set	
 * @throws DRDAProtocolException
 * @throws SQLException
 */
private void writeSQLUDTGRP(ResultSetMetaData rsmeta,ParameterMetaData pmeta,int jdbcElemNum,boolean rtnOutput) throws DRDAProtocolException, SQLException {
  int jdbcType=rtnOutput ? rsmeta.getColumnType(jdbcElemNum) : pmeta.getParameterType(jdbcElemNum);
  if (!(jdbcType == Types.JAVA_OBJECT) || !appRequester.supportsUDTs()) {
    writer.writeByte(CodePoint.NULLDATA);
    return;
  }
  String typeName=rtnOutput ? rsmeta.getColumnTypeName(jdbcElemNum) : pmeta.getParameterTypeName(jdbcElemNum);
  String className=rtnOutput ? rsmeta.getColumnClassName(jdbcElemNum) : pmeta.getParameterClassName(jdbcElemNum);
  writeVCMorVCS(typeName);
  writeVCMorVCS(className);
}

Fixed version (ground truth):
/** 
 * Write SQLUDTGRP (SQL Descriptor User-Defined Type Group Descriptor) This is the format from the DRDA spec, Volume 1, section 5.6.4.10. However, this format is not rich enough to carry the information needed by JDBC. This format does not have a subtype code for JAVA_OBJECT and this format does not convey the Java class name needed by ResultSetMetaData.getColumnClassName(). SQLUDXTYPE; DRDA TYPE I4; ENVLID 0x02; Length Override 4 Constants which map to java.sql.Types constants DISTINCT, STRUCT, and REF. But DRDA does not define a constant which maps to java.sql.Types.JAVA_OBJECT. SQLUDTRDB; DRDA TYPE VCS; ENVLID 0x32; Length Override 255 Database name. SQLUDTSCHEMA_m; DRDA TYPE VCM; ENVLID 0x3E; Length Override 255 SQLUDTSCHEMA_s; DRDA TYPE VCS; ENVLID 0x32; Length Override 255 Schema name. One of the above. SQLUDTNAME_m; DRDA TYPE VCM; ENVLID 0x3E; Length Override 255 SQLUDTNAME_s; DRDA TYPE VCS; ENVLID 0x32; Length Override 255 Unqualified UDT name. One of the above. Instead, we use the following format and only for communication between Derby servers and Derby clients which are both at version 10.6 or higher. For all other client/server combinations, we send null. SQLUDTNAME_m; DRDA TYPE VCM; ENVLID 0x3E; Length Override 255 SQLUDTNAME_s; DRDA TYPE VCS; ENVLID 0x32; Length Override 255 Fully qualified UDT name. One of the above. SQLUDTCLASSNAME_m; DRDA TYPE VCM; ENVLID 0x3E; Length Override FdocaConstants.LONGVARCHAR_MAX_LEN SQLUDTCLASSNAME_s; DRDA TYPE VCS; ENVLID 0x32; Length Override FdocaConstants.LONGVARCHAR_MAX_LEN Name of the Java class bound to the UDT. One of the above.
 * @param rsmeta	resultset meta data
 * @param pmeta		parameter meta data
 * @param jdbcElemNum	column number we are returning (in case of result set), or,parameter number (in case of parameter)
 * @param rtnOutput	whether this is for a result set	
 * @throws DRDAProtocolException
 * @throws SQLException
 */
private void writeSQLUDTGRP(ResultSetMetaData rsmeta,ParameterMetaData pmeta,int jdbcElemNum,boolean rtnOutput) throws DRDAProtocolException, SQLException {
  int jdbcType=rtnOutput ? rsmeta.getColumnType(jdbcElemNum) : pmeta.getParameterType(jdbcElemNum);
  if (!(jdbcType == Types.JAVA_OBJECT) || !appRequester.supportsUDTs()) {
    writer.writeByte(CodePoint.NULLDATA);
    return;
  }
  String typeName=rtnOutput ? rsmeta.getColumnTypeName(jdbcElemNum) : pmeta.getParameterTypeName(jdbcElemNum);
  String className=rtnOutput ? rsmeta.getColumnClassName(jdbcElemNum) : pmeta.getParameterClassName(jdbcElemNum);
  writeVCMorVCS(typeName);
  writeVCMorVCS(className);
}