3 Replies Latest reply on Oct 21, 2005 12:18 PM by Ronald van Kuijk

    Bug in ByteArray

    Tobias Bosch Newbie

      The copy-constructor of ByteArray (the one that takes another ByteArray as argument) has a bug:

      It just copies the reference of the byteBlocks-field of the given template, and does not create an own ArrayList filled with the content of the byteBlocks-field of the template. By this, the template and the new ByteArray reference to the same List. However, in the hibernate-mapping-file for ByteArray, this list is declared such that it belongs to the ByteArray, and therefore the reference can NOT be shared between two ByteArrays.
      The result is, that when you update a variable in the process-context that is stored in a ByteArray (e.g. a Collection), i.e. the variable already had content and you change it, then a ByteArrayUpdateLog will be created that uses the buggy copy-constructor, which causes
      the exception "shared references to a collection found" when persisting the ProcessInstance.

      As this buggy constructor is only used by ByteArrayUpdateLog, and a ByteArrayUpdateLog is only created by a ByteArrayInstance, just create an own ByteArrayInstance with the following method, that will first clone the ByteArrays with the correct constructor:
      public void setObject(Object value) {
      ByteArray oldArrayCopy = this.value != null ?
      new ByteArray(this.value.getBytes())
      : null;
      ByteArray newArray = (ByteArray) value;
      ByteArray newArrayCopy = newArray != null ?
      new ByteArray(newArray.getBytes())
      : null;
      token.addLog(new ByteArrayUpdateLog(
      this, oldArrayCopy, newArrayCopy)
      this.value = (ByteArray) value;