Program: 53272
Project: 53272
Buggy source:
/** 
 * Reserved for internal use.
 */
final byte[][] generateMessage(Object name,byte[] data,ObjectType interfaceClass,int AttributeOrdinal,Command cmd){
  if (getLimits().getMaxInfoRX() == null) {
    throw new GXDLMSException("String_Node_Str");
  }
  boolean asList=false;
  java.nio.ByteBuffer buff;
  if (name instanceof byte[]) {
    buff=java.nio.ByteBuffer.wrap((byte[])name);
  }
 else {
    if (name == null) {
      buff=java.nio.ByteBuffer.wrap(data);
    }
 else     if (getUseLogicalNameReferencing()) {
      int len=data == null ? 0 : data.length;
      if (cmd == Command.GetRequest || cmd == Command.SetRequest || cmd == Command.MethodRequest) {
        if (name instanceof List) {
          asList=true;
          List<AbstractMap.SimpleEntry<GXDLMSObject,Integer>> tmp=(List<AbstractMap.SimpleEntry<GXDLMSObject,Integer>>)name;
          buff=java.nio.ByteBuffer.allocate(20 + len + tmp.size() * 10);
          buff.put((byte)tmp.size());
          for (          AbstractMap.SimpleEntry<GXDLMSObject,Integer> it : tmp) {
            GXCommon.setUInt16((short)it.getKey().getObjectType().getValue(),buff);
            String[] items=it.getKey().getLogicalName().split("String_Node_Str");
            if (items.length != 6) {
              throw new GXDLMSException("String_Node_Str");
            }
            for (            String it2 : items) {
              buff.put(Integer.valueOf(it2).byteValue());
            }
            buff.put(it.getValue().byteValue());
            buff.put((byte)0);
          }
        }
 else {
          buff=java.nio.ByteBuffer.allocate(20 + len);
          buff.putShort((short)interfaceClass.getValue());
          String[] items=((String)name).split("String_Node_Str",-1);
          if (items.length != 6) {
            throw new GXDLMSException("String_Node_Str");
          }
          for (          String it : items) {
            buff.put((byte)(Short.parseShort(it) & 0xFF));
          }
          buff.put((byte)AttributeOrdinal);
          if (cmd == Command.SetRequest) {
            buff.put((byte)0);
            if (getUseLogicalNameReferencing() && data.length + buff.position() >= getMaxReceivePDUSize()) {
              byte[] tmp=new byte[buff.position()];
              buff.position(0);
              buff.get(tmp);
              java.nio.ByteBuffer tmp2=java.nio.ByteBuffer.wrap(data);
              tmp2.position(data.length);
              return splitToBlocks(tmp2,cmd,false,tmp);
            }
          }
          if (data == null || data.length == 0) {
            buff.put((byte)0);
          }
 else {
            buff.put((byte)1);
          }
        }
      }
 else {
        buff=java.nio.ByteBuffer.allocate(20 + len);
      }
    }
 else {
      int len=data == null ? 0 : data.length;
      if (name instanceof List) {
        List<AbstractMap.SimpleEntry<GXDLMSObject,Integer>> tmp=(List<AbstractMap.SimpleEntry<GXDLMSObject,Integer>>)name;
        buff=java.nio.ByteBuffer.allocate(10 + tmp.size() * 3);
        buff.put((byte)tmp.size());
        for (        AbstractMap.SimpleEntry<GXDLMSObject,Integer> it : tmp) {
          buff.put((byte)2);
          int base_address=it.getKey().getShortName();
          base_address+=((it.getValue() - 1) * 8);
          GXCommon.setUInt16((short)base_address,buff);
        }
      }
 else {
        buff=java.nio.ByteBuffer.allocate(11 + len);
        buff.put((byte)1);
        if (cmd == Command.ReadResponse || cmd == Command.WriteResponse) {
          buff.put((byte)0x0);
        }
 else {
          if (cmd == Command.WriteRequest || data == null || data.length == 0) {
            buff.put((byte)2);
          }
 else {
            buff.put((byte)4);
          }
          int base_address=GXCommon.intValue(name);
          if (AttributeOrdinal != 0) {
            base_address+=((AttributeOrdinal - 1) * 8);
          }
          buff.putShort((short)base_address);
        }
      }
    }
    if (data != null && data.length != 0) {
      if (cmd == Command.WriteRequest) {
        buff.put((byte)1);
      }
      buff.put(data);
    }
  }
  return splitToBlocks(buff,cmd,asList,null);
}

Fixed version (ground truth):
/** 
 * Reserved for internal use.
 */
final byte[][] generateMessage(Object name,byte[] data,ObjectType interfaceClass,int AttributeOrdinal,Command cmd){
  if (getLimits().getMaxInfoRX() == null) {
    throw new GXDLMSException("String_Node_Str");
  }
  boolean asList=false;
  java.nio.ByteBuffer buff;
  if (name instanceof byte[]) {
    buff=java.nio.ByteBuffer.wrap((byte[])name);
  }
 else {
    if (name == null) {
      buff=java.nio.ByteBuffer.wrap(data);
    }
 else     if (getUseLogicalNameReferencing()) {
      int len=data == null ? 0 : data.length;
      if (cmd == Command.GetRequest || cmd == Command.SetRequest || cmd == Command.MethodRequest) {
        if (name instanceof List) {
          asList=true;
          List<AbstractMap.SimpleEntry<GXDLMSObject,Integer>> tmp=(List<AbstractMap.SimpleEntry<GXDLMSObject,Integer>>)name;
          buff=java.nio.ByteBuffer.allocate(20 + len + tmp.size() * 10);
          buff.put((byte)tmp.size());
          for (          AbstractMap.SimpleEntry<GXDLMSObject,Integer> it : tmp) {
            GXCommon.setUInt16((short)it.getKey().getObjectType().getValue(),buff);
            String[] items=it.getKey().getLogicalName().split("String_Node_Str");
            if (items.length != 6) {
              throw new GXDLMSException("String_Node_Str");
            }
            for (            String it2 : items) {
              buff.put(Integer.valueOf(it2).byteValue());
            }
            buff.put(it.getValue().byteValue());
            buff.put((byte)0);
          }
        }
 else {
          buff=java.nio.ByteBuffer.allocate(20 + len);
          buff.putShort((short)interfaceClass.getValue());
          String[] items=((String)name).split("String_Node_Str",-1);
          if (items.length != 6) {
            throw new GXDLMSException("String_Node_Str");
          }
          for (          String it : items) {
            buff.put((byte)(Short.parseShort(it) & 0xFF));
          }
          buff.put((byte)AttributeOrdinal);
          if (cmd == Command.SetRequest) {
            buff.put((byte)0);
            if (getUseLogicalNameReferencing() && data.length + buff.position() >= getMaxReceivePDUSize()) {
              byte[] tmp=new byte[buff.position()];
              buff.position(0);
              buff.get(tmp);
              java.nio.ByteBuffer tmp2=java.nio.ByteBuffer.wrap(data);
              tmp2.position(data.length);
              return splitToBlocks(tmp2,cmd,false,tmp);
            }
          }
 else           if (data == null || data.length == 0) {
            buff.put((byte)0);
          }
 else {
            buff.put((byte)1);
          }
        }
      }
 else {
        buff=java.nio.ByteBuffer.allocate(20 + len);
      }
    }
 else {
      int len=data == null ? 0 : data.length;
      if (name instanceof List) {
        List<AbstractMap.SimpleEntry<GXDLMSObject,Integer>> tmp=(List<AbstractMap.SimpleEntry<GXDLMSObject,Integer>>)name;
        buff=java.nio.ByteBuffer.allocate(10 + tmp.size() * 3);
        buff.put((byte)tmp.size());
        for (        AbstractMap.SimpleEntry<GXDLMSObject,Integer> it : tmp) {
          buff.put((byte)2);
          int base_address=it.getKey().getShortName();
          base_address+=((it.getValue() - 1) * 8);
          GXCommon.setUInt16((short)base_address,buff);
        }
      }
 else {
        buff=java.nio.ByteBuffer.allocate(11 + len);
        buff.put((byte)1);
        if (cmd == Command.ReadResponse || cmd == Command.WriteResponse) {
          buff.put((byte)0x0);
        }
 else {
          if (cmd == Command.WriteRequest || data == null || data.length == 0) {
            buff.put((byte)2);
          }
 else {
            buff.put((byte)4);
          }
          int base_address=GXCommon.intValue(name);
          if (AttributeOrdinal != 0) {
            base_address+=((AttributeOrdinal - 1) * 8);
          }
          buff.putShort((short)base_address);
        }
      }
    }
    if (data != null && data.length != 0) {
      if (cmd == Command.WriteRequest) {
        buff.put((byte)1);
      }
      buff.put(data);
    }
  }
  return splitToBlocks(buff,cmd,asList,null);
}