Program: 89889
Project: 89889
Buggy source:
@DB(txn=false) protected void prepareAttribute(final int j,final PreparedStatement pstmt,final Attribute attr,Object value) throws SQLException {
  if (attr.is(Attribute.Flag.DaoGenerated) && value == null) {
    value=generateValue(attr);
    if (attr.field == null) {
      pstmt.setObject(j,value);
      return;
    }
  }
  if (attr.field.getType() == String.class) {
    final String str=(String)value;
    if (str == null) {
      pstmt.setString(j,null);
      return;
    }
    final Column column=attr.field.getAnnotation(Column.class);
    final int length=column != null ? column.length() : 255;
    if (length < str.length()) {
      try {
        pstmt.setBytes(j,str.substring(0,column.length()).getBytes("String_Node_Str"));
      }
 catch (      UnsupportedEncodingException e) {
        assert(false);
        throw new CloudRuntimeException("String_Node_Str");
      }
    }
 else {
      try {
        pstmt.setBytes(j,str.getBytes("String_Node_Str"));
      }
 catch (      UnsupportedEncodingException e) {
        assert(false);
        throw new CloudRuntimeException("String_Node_Str");
      }
    }
  }
 else   if (attr.field.getType() == Date.class) {
    final Date date=(Date)value;
    if (date == null) {
      pstmt.setObject(j,null);
      return;
    }
    if (attr.is(Attribute.Flag.Date)) {
      pstmt.setString(j,DateUtil.getDateDisplayString(TimeZone.getTimeZone("String_Node_Str"),date));
    }
 else     if (attr.is(Attribute.Flag.TimeStamp)) {
      pstmt.setString(j,DateUtil.getDateDisplayString(TimeZone.getTimeZone("String_Node_Str"),date));
    }
 else     if (attr.is(Attribute.Flag.Time)) {
      pstmt.setString(j,DateUtil.getDateDisplayString(TimeZone.getTimeZone("String_Node_Str"),date));
    }
  }
 else   if (attr.field.getType() == Calendar.class) {
    final Calendar cal=(Calendar)value;
    if (cal == null) {
      pstmt.setObject(j,null);
      return;
    }
    if (attr.is(Attribute.Flag.Date)) {
      pstmt.setString(j,DateUtil.getDateDisplayString(TimeZone.getTimeZone("String_Node_Str"),cal.getTime()));
    }
 else     if (attr.is(Attribute.Flag.TimeStamp)) {
      pstmt.setString(j,DateUtil.getDateDisplayString(TimeZone.getTimeZone("String_Node_Str"),cal.getTime()));
    }
 else     if (attr.is(Attribute.Flag.Time)) {
      pstmt.setString(j,DateUtil.getDateDisplayString(TimeZone.getTimeZone("String_Node_Str"),cal.getTime()));
    }
  }
 else   if (attr.field.getType().isEnum()) {
    final Enumerated enumerated=attr.field.getType().getAnnotation(Enumerated.class);
    final EnumType type=(enumerated == null) ? EnumType.STRING : enumerated.value();
    if (type == EnumType.STRING) {
      pstmt.setString(j,value == null ? null : value.toString());
    }
 else     if (type == EnumType.ORDINAL) {
      pstmt.setInt(j,value == null ? null : ((Enum<?>)value).ordinal());
    }
  }
 else   if (attr.field.getType() == URI.class) {
    pstmt.setString(j,value == null ? null : value.toString());
  }
 else   if (attr.field.getType() == URL.class) {
    pstmt.setURL(j,(URL)value);
  }
 else   if (attr.field.getType() == byte[].class) {
    pstmt.setBytes(j,(byte[])value);
  }
 else   if (attr.field.getType() == Ip.class) {
    final Enumerated enumerated=attr.field.getType().getAnnotation(Enumerated.class);
    final EnumType type=(enumerated == null) ? EnumType.ORDINAL : enumerated.value();
    if (type == EnumType.STRING) {
      pstmt.setString(j,value == null ? null : value.toString());
    }
 else     if (type == EnumType.ORDINAL) {
      pstmt.setLong(j,value == null ? null : ((Ip)value).longValue());
    }
  }
 else {
    pstmt.setObject(j,value);
  }
}

Fixed version (ground truth):
@DB(txn=false) protected void prepareAttribute(final int j,final PreparedStatement pstmt,final Attribute attr,Object value) throws SQLException {
  if (attr.is(Attribute.Flag.DaoGenerated) && value == null) {
    value=generateValue(attr);
    if (attr.field == null) {
      pstmt.setObject(j,value);
      return;
    }
  }
  if (attr.field.getType() == String.class) {
    final String str=(String)value;
    if (str == null) {
      pstmt.setString(j,null);
      return;
    }
    final Column column=attr.field.getAnnotation(Column.class);
    final int length=column != null ? column.length() : 255;
    if (length < str.length()) {
      try {
        pstmt.setBytes(j,str.substring(0,column.length()).getBytes("String_Node_Str"));
      }
 catch (      UnsupportedEncodingException e) {
        assert(false);
        throw new CloudRuntimeException("String_Node_Str");
      }
    }
 else {
      try {
        pstmt.setBytes(j,str.getBytes("String_Node_Str"));
      }
 catch (      UnsupportedEncodingException e) {
        assert(false);
        throw new CloudRuntimeException("String_Node_Str");
      }
    }
  }
 else   if (attr.field.getType() == Date.class) {
    final Date date=(Date)value;
    if (date == null) {
      pstmt.setObject(j,null);
      return;
    }
    if (attr.is(Attribute.Flag.Date)) {
      pstmt.setString(j,DateUtil.getDateDisplayString(TimeZone.getTimeZone("String_Node_Str"),date));
    }
 else     if (attr.is(Attribute.Flag.TimeStamp)) {
      pstmt.setString(j,DateUtil.getDateDisplayString(TimeZone.getTimeZone("String_Node_Str"),date));
    }
 else     if (attr.is(Attribute.Flag.Time)) {
      pstmt.setString(j,DateUtil.getDateDisplayString(TimeZone.getTimeZone("String_Node_Str"),date));
    }
  }
 else   if (attr.field.getType() == Calendar.class) {
    final Calendar cal=(Calendar)value;
    if (cal == null) {
      pstmt.setObject(j,null);
      return;
    }
    if (attr.is(Attribute.Flag.Date)) {
      pstmt.setString(j,DateUtil.getDateDisplayString(TimeZone.getTimeZone("String_Node_Str"),cal.getTime()));
    }
 else     if (attr.is(Attribute.Flag.TimeStamp)) {
      pstmt.setString(j,DateUtil.getDateDisplayString(TimeZone.getTimeZone("String_Node_Str"),cal.getTime()));
    }
 else     if (attr.is(Attribute.Flag.Time)) {
      pstmt.setString(j,DateUtil.getDateDisplayString(TimeZone.getTimeZone("String_Node_Str"),cal.getTime()));
    }
  }
 else   if (attr.field.getType().isEnum()) {
    final Enumerated enumerated=attr.field.getType().getAnnotation(Enumerated.class);
    final EnumType type=(enumerated == null) ? EnumType.STRING : enumerated.value();
    if (type == EnumType.STRING) {
      pstmt.setString(j,value == null ? null : value.toString());
    }
 else     if (type == EnumType.ORDINAL) {
      pstmt.setInt(j,value == null ? null : ((Enum<?>)value).ordinal());
    }
  }
 else   if (attr.field.getType() == URI.class) {
    pstmt.setString(j,value == null ? null : value.toString());
  }
 else   if (attr.field.getType() == URL.class) {
    pstmt.setURL(j,(URL)value);
  }
 else   if (attr.field.getType() == byte[].class) {
    pstmt.setBytes(j,(byte[])value);
  }
 else   if (attr.field.getType() == Ip.class) {
    final Enumerated enumerated=attr.field.getType().getAnnotation(Enumerated.class);
    final EnumType type=(enumerated == null) ? EnumType.ORDINAL : enumerated.value();
    if (type == EnumType.STRING) {
      pstmt.setString(j,value == null ? null : value.toString());
    }
 else     if (type == EnumType.ORDINAL) {
      pstmt.setLong(j,value == null ? null : (value instanceof Ip) ? ((Ip)value).longValue() : NetUtils.ip2Long((String)value));
    }
  }
 else {
    pstmt.setObject(j,value);
  }
}