Program: 53304
Project: 53304
Buggy source:
/** 
 * Reserved for internal use.
 */
public static Object getData(byte[] buff,int[] pos,int action,int[] count,int[] index,DataType[] type,int[] cachePosition){
  count[0]=0;
  index[0]=0;
  Object value=null;
  if (pos[0] == buff.length) {
    pos[0]=-1;
    return null;
  }
  boolean knownType=type[0] != DataType.NONE;
  if (!knownType) {
    type[0]=DataType.forValue(buff[pos[0]++]);
  }
  if (type[0] == DataType.NONE) {
    return value;
  }
  if (pos[0] == buff.length) {
    pos[0]=-1;
    return null;
  }
  int size=buff.length - pos[0];
  if (type[0] == DataType.ARRAY || type[0] == DataType.STRUCTURE) {
    count[0]=GXCommon.getObjectCount(buff,pos);
    if (action == 2) {
      return value;
    }
    if (cachePosition[0] > pos[0]) {
      pos[0]=cachePosition[0];
    }
    size=buff.length - pos[0];
    if (count[0] != 0 && size < 1) {
      pos[0]=-1;
      return null;
    }
    java.util.ArrayList<Object> arr=new java.util.ArrayList<Object>(count[0]);
    for (index[0]=0; index[0] != count[0]; ++index[0]) {
      DataType[] itemType=new DataType[]{DataType.NONE};
      int[] colCount=new int[1], colIndex=new int[1];
      int[] tmpPos=new int[1];
      Object tmp=getData(buff,pos,0,colCount,colIndex,itemType,tmpPos);
      if (colCount[0] == colIndex[0] && pos[0] != -1) {
        arr.add(tmp);
      }
      if (pos[0] == -1) {
        break;
      }
 else {
        cachePosition[0]=pos[0];
      }
    }
    if (index[0] == count[0] && pos[0] != -1) {
      cachePosition[0]=buff.length;
    }
    value=arr.toArray();
  }
 else   if (type[0] == DataType.BOOLEAN) {
    value=buff[pos[0]++] != 0;
  }
 else   if (type[0] == DataType.BITSTRING) {
    int cnt=buff[pos[0]++];
    --size;
    double t=cnt;
    t/=8;
    if (cnt % 8 != 0) {
      ++t;
    }
    int byteCnt=(int)Math.floor(t);
    if (size < byteCnt) {
      pos[0]=-1;
      return null;
    }
    char[] tmp=new char[cnt];
    for (int a=0; a != cnt; ++a) {
      int i=a / 8;
      byte b=buff[pos[0] + i];
      int val=(b >>> (a % 8)) & 0x1;
      tmp[cnt - a - 1]=val == 0 ? '0' : '1';
    }
    pos[0]+=(int)t;
    value=new String(tmp);
  }
 else   if (type[0] == DataType.INT32) {
    if (size < 4) {
      pos[0]=-1;
      return null;
    }
    value=GXCommon.getInt32(buff,pos);
  }
 else   if (type[0] == DataType.UINT32) {
    if (size < 4) {
      pos[0]=-1;
      return null;
    }
    value=GXCommon.getUInt32(buff,pos);
  }
 else   if (type[0] == DataType.STRING) {
    int len;
    if (knownType) {
      len=buff.length;
    }
 else {
      len=GXCommon.getObjectCount(buff,pos);
      if (buff.length - pos[0] < len) {
        pos[0]=-1;
        return null;
      }
    }
    if (len > 0) {
      boolean octetString=false;
      if (knownType) {
        for (        byte ch : buff) {
          if (ch < 0x21) {
            octetString=true;
            break;
          }
        }
      }
      if (octetString) {
        StringBuilder str=new StringBuilder(buff.length * 3);
        for (        byte ch : buff) {
          str.append(ch & 0xFF);
          str.append('.');
        }
        str.deleteCharAt(str.length() - 1);
        value=str.toString();
      }
 else {
        value=new String(GXCommon.rawData(buff,pos,len));
      }
    }
  }
 else   if (type[0] == DataType.OCTET_STRING) {
    int len;
    if (knownType) {
      len=buff.length;
    }
 else {
      len=GXCommon.getObjectCount(buff,pos);
      if (buff.length - pos[0] < len) {
        pos[0]=-1;
        return null;
      }
    }
    value=GXCommon.rawData(buff,pos,len);
  }
 else   if (type[0] == DataType.BCD) {
    int len;
    if (knownType) {
      len=buff.length;
    }
 else {
      len=GXCommon.getObjectCount(buff,pos);
    }
    StringBuilder bcd=new StringBuilder(len * 2);
    for (int a=0; a != len; ++a) {
      int idHigh=buff[pos[0]] >>> 4;
      int idLow=buff[pos[0]] & 0x0F;
      ++pos[0];
      bcd.append(String.format("String_Node_Str",idHigh,idLow));
    }
    value=bcd.toString();
  }
 else   if (type[0] == DataType.INT8) {
    value=(byte)buff[pos[0]++];
  }
 else   if (type[0] == DataType.INT16) {
    if (size < 2) {
      pos[0]=-1;
      return null;
    }
    value=GXCommon.getInt16(buff,pos);
  }
 else   if (type[0] == DataType.UINT8) {
    value=buff[pos[0]++] & 0xFF;
  }
 else   if (type[0] == DataType.UINT16) {
    if (size < 2) {
      pos[0]=-1;
      return null;
    }
    value=GXCommon.getUInt16(buff,pos);
  }
 else   if (type[0] == DataType.COMPACTARRAY) {
    throw new RuntimeException("String_Node_Str");
  }
 else   if (type[0] == DataType.INT64) {
    if (size < 8) {
      pos[0]=-1;
      return null;
    }
    value=GXCommon.getInt64(buff,pos);
  }
 else   if (type[0] == DataType.UINT64) {
    if (size < 8) {
      pos[0]=-1;
      return null;
    }
    value=GXCommon.getUInt64(buff,pos);
  }
 else   if (type[0] == DataType.ENUM) {
    if (size < 1) {
      pos[0]=-1;
      return null;
    }
    value=buff[pos[0]++];
  }
 else   if (type[0] == DataType.FLOAT32) {
    if (size < 4) {
      pos[0]=-1;
      return null;
    }
    value=GXCommon.toFloat(buff,pos);
  }
 else   if (type[0] == DataType.FLOAT64) {
    if (size < 8) {
      pos[0]=-1;
      return null;
    }
    value=GXCommon.toDouble(buff,pos);
  }
 else   if (type[0] == DataType.DATETIME) {
    if (knownType) {
      if (size - pos[0] < 12) {
        pos[0]=-1;
        return null;
      }
    }
 else {
      ++pos[0];
      if (size < 12) {
        pos[0]=-1;
        return null;
      }
    }
    java.util.Set<DateTimeSkips> skip=EnumSet.noneOf(DateTimeSkips.class);
    java.util.Calendar tm=java.util.Calendar.getInstance();
    int val=GXCommon.getUInt16(buff,pos);
    if (val != 0xFFFF) {
      tm.set(java.util.Calendar.YEAR,val);
    }
 else {
      skip.add(DateTimeSkips.YEAR);
      tm.set(java.util.Calendar.YEAR,0);
    }
    val=buff[pos[0]++];
    if (val > 0 && val < 13) {
      tm.set(java.util.Calendar.MONTH,val - 1);
    }
 else {
      skip.add(DateTimeSkips.MONTH);
      tm.set(java.util.Calendar.MONTH,0);
    }
    val=buff[pos[0]++];
    if (val > 0 && val < 32) {
      tm.set(java.util.Calendar.DATE,val);
    }
 else {
      skip.add(DateTimeSkips.DAY);
      tm.set(java.util.Calendar.DATE,0);
    }
    pos[0]++;
    val=buff[pos[0]++];
    if (val != -1) {
      tm.set(java.util.Calendar.HOUR_OF_DAY,val);
    }
 else {
      skip.add(DateTimeSkips.HOUR);
      tm.set(java.util.Calendar.HOUR_OF_DAY,0);
    }
    val=buff[pos[0]++];
    if (val != -1) {
      tm.set(java.util.Calendar.MINUTE,val);
    }
 else {
      skip.add(DateTimeSkips.MINUTE);
      tm.set(java.util.Calendar.MINUTE,0);
    }
    val=buff[pos[0]++];
    if (val != -1) {
      tm.set(java.util.Calendar.SECOND,val);
    }
 else {
      skip.add(DateTimeSkips.SECOND);
      tm.set(java.util.Calendar.SECOND,0);
    }
    val=buff[pos[0]++];
    if (val != -1) {
      skip.add(DateTimeSkips.MILLISECOND);
      tm.set(java.util.Calendar.MILLISECOND,val);
    }
 else {
      tm.set(java.util.Calendar.MILLISECOND,0);
    }
    GXDateTime dt=new GXDateTime(tm.getTime());
    dt.setSkip(skip);
    value=dt;
  }
 else   if (type[0] == DataType.DATE) {
    if (knownType) {
      if (size < 4) {
        pos[0]=-1;
        return null;
      }
    }
 else     if (size < 5) {
      pos[0]=-1;
      return null;
    }
    java.util.Set<DateTimeSkips> skip=EnumSet.of(DateTimeSkips.HOUR);
    skip.add(DateTimeSkips.MINUTE);
    skip.add(DateTimeSkips.SECOND);
    skip.add(DateTimeSkips.MILLISECOND);
    java.util.Calendar tm=java.util.Calendar.getInstance();
    int val=GXCommon.getUInt16(buff,pos);
    if (val != -1) {
      tm.set(java.util.Calendar.YEAR,val);
    }
 else {
      skip.add(DateTimeSkips.YEAR);
      tm.set(java.util.Calendar.YEAR,0);
    }
    val=buff[pos[0]++];
    if (val > 0 && val < 13) {
      tm.set(java.util.Calendar.MONTH,val - 1);
    }
 else {
      skip.add(DateTimeSkips.MONTH);
      tm.set(java.util.Calendar.MONTH,0);
    }
    val=buff[pos[0]++];
    if (val > 0 && val < 32) {
      tm.set(java.util.Calendar.DATE,val);
    }
 else {
      skip.add(DateTimeSkips.DAY);
      tm.set(java.util.Calendar.DATE,0);
    }
    pos[0]++;
    GXDateTime dt=new GXDateTime(tm.getTime());
    dt.setSkip(skip);
    value=dt;
  }
 else   if (type[0] == DataType.TIME) {
    if (knownType) {
      if (size < 4) {
        pos[0]=-1;
        return null;
      }
    }
 else     if (size < 7) {
      pos[0]=-1;
      return null;
    }
    java.util.Set<DateTimeSkips> skip=EnumSet.of(DateTimeSkips.DAY);
    skip.add(DateTimeSkips.DAY_OF_WEEK);
    skip.add(DateTimeSkips.MONTH);
    skip.add(DateTimeSkips.YEAR);
    java.util.Calendar tm=java.util.Calendar.getInstance();
    int val=buff[pos[0]++];
    if (val != -1) {
      tm.set(java.util.Calendar.HOUR_OF_DAY,val);
    }
 else {
      skip.add(DateTimeSkips.HOUR);
      tm.set(java.util.Calendar.HOUR_OF_DAY,0);
    }
    val=buff[pos[0]++];
    if (val != -1) {
      tm.set(java.util.Calendar.MINUTE,val);
    }
 else {
      skip.add(DateTimeSkips.MINUTE);
      tm.set(java.util.Calendar.MINUTE,0);
    }
    val=buff[pos[0]++];
    if (val != -1) {
      tm.set(java.util.Calendar.SECOND,val);
    }
 else {
      skip.add(DateTimeSkips.SECOND);
      tm.set(java.util.Calendar.SECOND,0);
    }
    val=buff[pos[0]++];
    if (val != -1) {
      tm.set(java.util.Calendar.MILLISECOND,val);
    }
 else {
      skip.add(DateTimeSkips.MILLISECOND);
      tm.set(java.util.Calendar.MILLISECOND,0);
    }
    GXDateTime dt=new GXDateTime(tm.getTime());
    dt.setSkip(skip);
    value=dt;
  }
 else {
    throw new RuntimeException("String_Node_Str");
  }
  return value;
}

Fixed version (ground truth):
/** 
 * Reserved for internal use.
 */
public static Object getData(byte[] buff,int[] pos,int action,int[] count,int[] index,DataType[] type,int[] cachePosition){
  count[0]=0;
  index[0]=0;
  Object value=null;
  if (pos[0] == buff.length) {
    pos[0]=-1;
    return null;
  }
  boolean knownType=type[0] != DataType.NONE;
  if (!knownType) {
    type[0]=DataType.forValue(buff[pos[0]++]);
  }
  if (type[0] == DataType.NONE) {
    return value;
  }
  if (pos[0] == buff.length) {
    pos[0]=-1;
    return null;
  }
  int size=buff.length - pos[0];
  if (type[0] == DataType.ARRAY || type[0] == DataType.STRUCTURE) {
    count[0]=GXCommon.getObjectCount(buff,pos);
    if (action == 2) {
      return value;
    }
    if (cachePosition[0] > pos[0]) {
      pos[0]=cachePosition[0];
    }
    size=buff.length - pos[0];
    if (count[0] != 0 && size < 1) {
      pos[0]=-1;
      return null;
    }
    java.util.ArrayList<Object> arr=new java.util.ArrayList<Object>(count[0]);
    for (index[0]=0; index[0] != count[0]; ++index[0]) {
      DataType[] itemType=new DataType[]{DataType.NONE};
      int[] colCount=new int[1], colIndex=new int[1];
      int[] tmpPos=new int[1];
      Object tmp=getData(buff,pos,0,colCount,colIndex,itemType,tmpPos);
      if (colCount[0] == colIndex[0] && pos[0] != -1) {
        arr.add(tmp);
      }
      if (pos[0] == -1) {
        break;
      }
 else {
        cachePosition[0]=pos[0];
      }
    }
    if (index[0] == count[0] && pos[0] != -1) {
      cachePosition[0]=buff.length;
    }
    value=arr.toArray();
  }
 else   if (type[0] == DataType.BOOLEAN) {
    value=buff[pos[0]++] != 0;
  }
 else   if (type[0] == DataType.BITSTRING) {
    int cnt=buff[pos[0]++];
    --size;
    double t=cnt;
    t/=8;
    if (cnt % 8 != 0) {
      ++t;
    }
    int byteCnt=(int)Math.floor(t);
    if (size < byteCnt) {
      pos[0]=-1;
      return null;
    }
    char[] tmp=new char[cnt];
    for (int a=0; a != cnt; ++a) {
      int i=a / 8;
      byte b=buff[pos[0] + i];
      int val=(b >>> (a % 8)) & 0x1;
      tmp[cnt - a - 1]=val == 0 ? '0' : '1';
    }
    pos[0]+=(int)t;
    value=new String(tmp);
  }
 else   if (type[0] == DataType.INT32) {
    if (size < 4) {
      pos[0]=-1;
      return null;
    }
    value=GXCommon.getInt32(buff,pos);
  }
 else   if (type[0] == DataType.UINT32) {
    if (size < 4) {
      pos[0]=-1;
      return null;
    }
    value=GXCommon.getUInt32(buff,pos);
  }
 else   if (type[0] == DataType.STRING) {
    int len;
    if (knownType) {
      len=buff.length;
    }
 else {
      len=GXCommon.getObjectCount(buff,pos);
      if (buff.length - pos[0] < len) {
        pos[0]=-1;
        return null;
      }
    }
    if (len > 0) {
      boolean octetString=false;
      if (knownType) {
        for (        byte ch : buff) {
          if (ch < 0x21) {
            octetString=true;
            break;
          }
        }
      }
      if (octetString) {
        StringBuilder str=new StringBuilder(buff.length * 3);
        for (        byte ch : buff) {
          str.append(ch & 0xFF);
          str.append('.');
        }
        str.deleteCharAt(str.length() - 1);
        value=str.toString();
      }
 else {
        value=new String(GXCommon.rawData(buff,pos,len));
      }
    }
  }
 else   if (type[0] == DataType.OCTET_STRING) {
    int len;
    if (knownType) {
      len=buff.length;
    }
 else {
      len=GXCommon.getObjectCount(buff,pos);
      if (buff.length - pos[0] < len) {
        pos[0]=-1;
        return null;
      }
    }
    value=GXCommon.rawData(buff,pos,len);
  }
 else   if (type[0] == DataType.BCD) {
    int len;
    if (knownType) {
      len=buff.length;
    }
 else {
      len=GXCommon.getObjectCount(buff,pos);
    }
    StringBuilder bcd=new StringBuilder(len * 2);
    for (int a=0; a != len; ++a) {
      int idHigh=buff[pos[0]] >>> 4;
      int idLow=buff[pos[0]] & 0x0F;
      ++pos[0];
      bcd.append(String.format("String_Node_Str",idHigh,idLow));
    }
    value=bcd.toString();
  }
 else   if (type[0] == DataType.INT8) {
    value=(byte)buff[pos[0]++];
  }
 else   if (type[0] == DataType.INT16) {
    if (size < 2) {
      pos[0]=-1;
      return null;
    }
    value=GXCommon.getInt16(buff,pos);
  }
 else   if (type[0] == DataType.UINT8) {
    value=buff[pos[0]++] & 0xFF;
  }
 else   if (type[0] == DataType.UINT16) {
    if (size < 2) {
      pos[0]=-1;
      return null;
    }
    value=GXCommon.getUInt16(buff,pos);
  }
 else   if (type[0] == DataType.COMPACTARRAY) {
    throw new RuntimeException("String_Node_Str");
  }
 else   if (type[0] == DataType.INT64) {
    if (size < 8) {
      pos[0]=-1;
      return null;
    }
    value=GXCommon.getInt64(buff,pos);
  }
 else   if (type[0] == DataType.UINT64) {
    if (size < 8) {
      pos[0]=-1;
      return null;
    }
    value=GXCommon.getUInt64(buff,pos);
  }
 else   if (type[0] == DataType.ENUM) {
    if (size < 1) {
      pos[0]=-1;
      return null;
    }
    value=buff[pos[0]++];
  }
 else   if (type[0] == DataType.FLOAT32) {
    if (size < 4) {
      pos[0]=-1;
      return null;
    }
    value=GXCommon.toFloat(buff,pos);
  }
 else   if (type[0] == DataType.FLOAT64) {
    if (size < 8) {
      pos[0]=-1;
      return null;
    }
    value=GXCommon.toDouble(buff,pos);
  }
 else   if (type[0] == DataType.DATETIME) {
    if (knownType) {
      if (size - pos[0] < 12) {
        pos[0]=-1;
        return null;
      }
    }
 else {
      ++pos[0];
      if (size < 12) {
        pos[0]=-1;
        return null;
      }
    }
    java.util.Set<DateTimeSkips> skip=EnumSet.noneOf(DateTimeSkips.class);
    java.util.Calendar tm=java.util.Calendar.getInstance(java.util.TimeZone.getTimeZone("String_Node_Str"));
    int val=GXCommon.getUInt16(buff,pos);
    if (val != 0xFFFF) {
      tm.set(java.util.Calendar.YEAR,val);
    }
 else {
      skip.add(DateTimeSkips.YEAR);
      tm.set(java.util.Calendar.YEAR,0);
    }
    val=buff[pos[0]++];
    if (val > 0 && val < 13) {
      tm.set(java.util.Calendar.MONTH,val - 1);
    }
 else {
      skip.add(DateTimeSkips.MONTH);
      tm.set(java.util.Calendar.MONTH,0);
    }
    val=buff[pos[0]++];
    if (val > 0 && val < 32) {
      tm.set(java.util.Calendar.DATE,val);
    }
 else {
      skip.add(DateTimeSkips.DAY);
      tm.set(java.util.Calendar.DATE,0);
    }
    pos[0]++;
    val=buff[pos[0]++];
    if (val != -1) {
      tm.set(java.util.Calendar.HOUR_OF_DAY,val);
    }
 else {
      skip.add(DateTimeSkips.HOUR);
      tm.set(java.util.Calendar.HOUR_OF_DAY,0);
    }
    val=buff[pos[0]++];
    if (val != -1) {
      tm.set(java.util.Calendar.MINUTE,val);
    }
 else {
      skip.add(DateTimeSkips.MINUTE);
      tm.set(java.util.Calendar.MINUTE,0);
    }
    val=buff[pos[0]++];
    if (val != -1) {
      tm.set(java.util.Calendar.SECOND,val);
    }
 else {
      skip.add(DateTimeSkips.SECOND);
      tm.set(java.util.Calendar.SECOND,0);
    }
    val=buff[pos[0]++];
    if (val != -1) {
      skip.add(DateTimeSkips.MILLISECOND);
      tm.set(java.util.Calendar.MILLISECOND,val);
    }
 else {
      tm.set(java.util.Calendar.MILLISECOND,0);
    }
    GXDateTime dt=new GXDateTime(tm.getTime());
    dt.setSkip(skip);
    value=dt;
  }
 else   if (type[0] == DataType.DATE) {
    if (knownType) {
      if (size < 4) {
        pos[0]=-1;
        return null;
      }
    }
 else     if (size < 5) {
      pos[0]=-1;
      return null;
    }
    java.util.Set<DateTimeSkips> skip=EnumSet.of(DateTimeSkips.HOUR);
    skip.add(DateTimeSkips.MINUTE);
    skip.add(DateTimeSkips.SECOND);
    skip.add(DateTimeSkips.MILLISECOND);
    java.util.Calendar tm=java.util.Calendar.getInstance(java.util.TimeZone.getTimeZone("String_Node_Str"));
    int val=GXCommon.getUInt16(buff,pos);
    if (val != -1) {
      tm.set(java.util.Calendar.YEAR,val);
    }
 else {
      skip.add(DateTimeSkips.YEAR);
      tm.set(java.util.Calendar.YEAR,0);
    }
    val=buff[pos[0]++];
    if (val > 0 && val < 13) {
      tm.set(java.util.Calendar.MONTH,val - 1);
    }
 else {
      skip.add(DateTimeSkips.MONTH);
      tm.set(java.util.Calendar.MONTH,0);
    }
    val=buff[pos[0]++];
    if (val > 0 && val < 32) {
      tm.set(java.util.Calendar.DATE,val);
    }
 else {
      skip.add(DateTimeSkips.DAY);
      tm.set(java.util.Calendar.DATE,0);
    }
    pos[0]++;
    GXDateTime dt=new GXDateTime(tm.getTime());
    dt.setSkip(skip);
    value=dt;
  }
 else   if (type[0] == DataType.TIME) {
    if (knownType) {
      if (size < 4) {
        pos[0]=-1;
        return null;
      }
    }
 else     if (size < 7) {
      pos[0]=-1;
      return null;
    }
    java.util.Set<DateTimeSkips> skip=EnumSet.of(DateTimeSkips.DAY);
    skip.add(DateTimeSkips.DAY_OF_WEEK);
    skip.add(DateTimeSkips.MONTH);
    skip.add(DateTimeSkips.YEAR);
    java.util.Calendar tm=java.util.Calendar.getInstance(java.util.TimeZone.getTimeZone("String_Node_Str"));
    int val=buff[pos[0]++];
    if (val != -1) {
      tm.set(java.util.Calendar.HOUR_OF_DAY,val);
    }
 else {
      skip.add(DateTimeSkips.HOUR);
      tm.set(java.util.Calendar.HOUR_OF_DAY,0);
    }
    val=buff[pos[0]++];
    if (val != -1) {
      tm.set(java.util.Calendar.MINUTE,val);
    }
 else {
      skip.add(DateTimeSkips.MINUTE);
      tm.set(java.util.Calendar.MINUTE,0);
    }
    val=buff[pos[0]++];
    if (val != -1) {
      tm.set(java.util.Calendar.SECOND,val);
    }
 else {
      skip.add(DateTimeSkips.SECOND);
      tm.set(java.util.Calendar.SECOND,0);
    }
    val=buff[pos[0]++];
    if (val != -1) {
      tm.set(java.util.Calendar.MILLISECOND,val);
    }
 else {
      skip.add(DateTimeSkips.MILLISECOND);
      tm.set(java.util.Calendar.MILLISECOND,0);
    }
    GXDateTime dt=new GXDateTime(tm.getTime());
    dt.setSkip(skip);
    value=dt;
  }
 else {
    throw new RuntimeException("String_Node_Str");
  }
  return value;
}