3 Replies Latest reply on Oct 21, 2005 12:18 PM by kukeltje

    Bug in ByteArray

    tobias.bosch

      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.

      Workaround:
      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;
      }

        • 1. Re: Bug in ByteArray
          kukeltje

          Could you file a Jira issue for this to. Nice going btw....Who do you work for that you are so good in finding bugs... Micro****? :-)

          • 2. Re: Bug in ByteArray

            Just want to say thanks to Tobias. I was running into this issue and I was just about to dive into why it only happens with Collections (at least for me). Thanks for saving me the trouble. Thank goodness for open source. Just rebuilt the jar and I'm a.o.k.

            Matt

            • 3. Re: Bug in ByteArray
              kukeltje

              still... if a jira issue is not filed, it will not neccesarilly be solved. If I do not forget it, I'll do it, if someone else beats me to it I'll be grateful