<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: DbSqlSession.getUpdatedObjects() and byte arrays in Alfresco Archive</title>
    <link>https://connect.hyland.com/t5/alfresco-archive/dbsqlsession-getupdatedobjects-and-byte-arrays/m-p/136402#M95660</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Yes, it seems you are correct. That equals will indeed not work in that case.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Would you able to throw together a unit test that demonstrates this, ie how can we 'trigger' the update in the same way you see it?&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Tue, 08 Jan 2013 13:33:34 GMT</pubDate>
    <dc:creator>jbarrez</dc:creator>
    <dc:date>2013-01-08T13:33:34Z</dc:date>
    <item>
      <title>DbSqlSession.getUpdatedObjects() and byte arrays</title>
      <link>https://connect.hyland.com/t5/alfresco-archive/dbsqlsession-getupdatedobjects-and-byte-arrays/m-p/136401#M95659</link>
      <description>Hi,we have an Activiti-based application that loads a large number of tasks and uses getVariablesLocal() to retrieve additional information. However, when used with a larger number of tasks, it crashes due to an ActivitiOptimisticLockingException, although nothing is supposed to be saved to the data</description>
      <pubDate>Mon, 07 Jan 2013 17:07:28 GMT</pubDate>
      <guid>https://connect.hyland.com/t5/alfresco-archive/dbsqlsession-getupdatedobjects-and-byte-arrays/m-p/136401#M95659</guid>
      <dc:creator>philipp91</dc:creator>
      <dc:date>2013-01-07T17:07:28Z</dc:date>
    </item>
    <item>
      <title>Re: DbSqlSession.getUpdatedObjects() and byte arrays</title>
      <link>https://connect.hyland.com/t5/alfresco-archive/dbsqlsession-getupdatedobjects-and-byte-arrays/m-p/136402#M95660</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Yes, it seems you are correct. That equals will indeed not work in that case.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Would you able to throw together a unit test that demonstrates this, ie how can we 'trigger' the update in the same way you see it?&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 08 Jan 2013 13:33:34 GMT</pubDate>
      <guid>https://connect.hyland.com/t5/alfresco-archive/dbsqlsession-getupdatedobjects-and-byte-arrays/m-p/136402#M95660</guid>
      <dc:creator>jbarrez</dc:creator>
      <dc:date>2013-01-08T13:33:34Z</dc:date>
    </item>
    <item>
      <title>Re: DbSqlSession.getUpdatedObjects() and byte arrays</title>
      <link>https://connect.hyland.com/t5/alfresco-archive/dbsqlsession-getupdatedobjects-and-byte-arrays/m-p/136403#M95661</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;I'm sorry I most likely can't make a unit test within reasonable time. I haven't been working much with Activiti yet and I haven't developed the part of our application that calls those methods. So it would even take me some time to get Activiti running in a clean environment …&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;But maybe these (generalized) code samples can help build a unit test:&lt;/SPAN&gt;&lt;BR /&gt;&lt;CODE&gt;&lt;BR /&gt;Map&amp;lt;String, Object&amp;gt; vars = someRegularValues();&lt;BR /&gt;Map&amp;lt;String, String&amp;gt; additionalInfo = getThisFromSomewhere();&lt;BR /&gt;vars.put(SOME_CONSTANT, additionalInfo);&lt;BR /&gt;runtimeService.setVariablesLocal(processInstanceId, vars);&lt;BR /&gt;… // Some time later&lt;BR /&gt;// This is the line that causes the crash:&lt;BR /&gt;Map&amp;lt;String, Object&amp;gt; vars = runtimeService.getVariablesLocal(processInstanceId);&lt;BR /&gt;// So this line does not get executed when too much processes are loaded at a time:&lt;BR /&gt;Map&amp;lt;String, String&amp;gt; additionalInfo = (Map&amp;lt;String, String&amp;gt;)vars.get(SOME_CONSTANT);&lt;BR /&gt;&lt;/CODE&gt;&lt;BR /&gt;&lt;SPAN&gt;It is the Map&amp;lt;String, String&amp;gt; in the process variables that is serialized to a byte[] and causes the error.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;When executed with a single process, this won't throw any errors, but it will create and commit unnecessary transactions.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 08 Jan 2013 19:03:18 GMT</pubDate>
      <guid>https://connect.hyland.com/t5/alfresco-archive/dbsqlsession-getupdatedobjects-and-byte-arrays/m-p/136403#M95661</guid>
      <dc:creator>philipp91</dc:creator>
      <dc:date>2013-01-08T19:03:18Z</dc:date>
    </item>
    <item>
      <title>Re: DbSqlSession.getUpdatedObjects() and byte arrays</title>
      <link>https://connect.hyland.com/t5/alfresco-archive/dbsqlsession-getupdatedobjects-and-byte-arrays/m-p/136404#M95662</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;ok. Created &lt;/SPAN&gt;&lt;A href="http://jira.codehaus.org/browse/ACT-1524" rel="nofollow noopener noreferrer"&gt;http://jira.codehaus.org/browse/ACT-1524&lt;/A&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 09 Jan 2013 09:57:00 GMT</pubDate>
      <guid>https://connect.hyland.com/t5/alfresco-archive/dbsqlsession-getupdatedobjects-and-byte-arrays/m-p/136404#M95662</guid>
      <dc:creator>jbarrez</dc:creator>
      <dc:date>2013-01-09T09:57:00Z</dc:date>
    </item>
    <item>
      <title>Re: DbSqlSession.getUpdatedObjects() and byte arrays</title>
      <link>https://connect.hyland.com/t5/alfresco-archive/dbsqlsession-getupdatedobjects-and-byte-arrays/m-p/136405#M95663</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Thank you!&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 09 Jan 2013 12:52:01 GMT</pubDate>
      <guid>https://connect.hyland.com/t5/alfresco-archive/dbsqlsession-getupdatedobjects-and-byte-arrays/m-p/136405#M95663</guid>
      <dc:creator>philipp91</dc:creator>
      <dc:date>2013-01-09T12:52:01Z</dc:date>
    </item>
    <item>
      <title>Re: DbSqlSession.getUpdatedObjects() and byte arrays</title>
      <link>https://connect.hyland.com/t5/alfresco-archive/dbsqlsession-getupdatedobjects-and-byte-arrays/m-p/136406#M95664</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Proposed Solution:&lt;/SPAN&gt;&lt;BR /&gt;&lt;A href="https://github.com/Activiti/Activiti/blob/master/modules/activiti-engine/src/main/java/org/activiti/engine/impl/db/DbSqlSession.java#L564" rel="nofollow noopener noreferrer"&gt;https://github.com/Activiti/Activiti/blob/master/modules/activiti-engine/src/main/java/org/activiti/engine/impl/db/DbSqlSession.java#L564&lt;/A&gt;&lt;BR /&gt;&lt;SPAN&gt;Instead of normal .equals(), use a function like this:&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;private boolean arrayAwareEquals(Object left, Object right) {&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; if (left == null) {&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; return right == null;&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; } else if (left instanceof Object[]) {&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; return Arrays.equals((Object[]) left, (Object[]) right);&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; } else {&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; return left.equals(right);&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;}&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Another approach would be to use wrapper-objects for all byte-arrays (like this: &lt;/SPAN&gt;&lt;A href="http://www.java2s.com/Tutorial/Java/0140__Collections/ByteArraywrapsjavabytearraysbytetoallowbytearraystobeusedaskeysinhashtables.htm" rel="nofollow noopener noreferrer"&gt;http://www.java2s.com/Tutorial/Java/0140__Collections/ByteArraywrapsjavabytearraysbytetoallowbytearraystobeusedaskeysinhashtables.htm&lt;/A&gt;&lt;SPAN&gt;), but that would probably require a lot of code modifications.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 06 Feb 2013 18:55:21 GMT</pubDate>
      <guid>https://connect.hyland.com/t5/alfresco-archive/dbsqlsession-getupdatedobjects-and-byte-arrays/m-p/136406#M95664</guid>
      <dc:creator>philipp91</dc:creator>
      <dc:date>2013-02-06T18:55:21Z</dc:date>
    </item>
    <item>
      <title>Re: DbSqlSession.getUpdatedObjects() and byte arrays</title>
      <link>https://connect.hyland.com/t5/alfresco-archive/dbsqlsession-getupdatedobjects-and-byte-arrays/m-p/136407#M95665</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;I've fixed it on master: &lt;/SPAN&gt;&lt;A href="https://github.com/Activiti/Activiti/commit/ab622919dca574e7ba01c358f8ce5dc8a26f22d5" rel="nofollow noopener noreferrer"&gt;https://github.com/Activiti/Activiti/commit/ab622919dca574e7ba01c358f8ce5dc8a26f22d5&lt;/A&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Could you verify if this fix is what you expected?&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 07 Feb 2013 11:12:34 GMT</pubDate>
      <guid>https://connect.hyland.com/t5/alfresco-archive/dbsqlsession-getupdatedobjects-and-byte-arrays/m-p/136407#M95665</guid>
      <dc:creator>jbarrez</dc:creator>
      <dc:date>2013-02-07T11:12:34Z</dc:date>
    </item>
    <item>
      <title>Re: DbSqlSession.getUpdatedObjects() and byte arrays</title>
      <link>https://connect.hyland.com/t5/alfresco-archive/dbsqlsession-getupdatedobjects-and-byte-arrays/m-p/136408#M95666</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Thank you very much! This is exactly the fix we needed.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 07 Feb 2013 12:45:16 GMT</pubDate>
      <guid>https://connect.hyland.com/t5/alfresco-archive/dbsqlsession-getupdatedobjects-and-byte-arrays/m-p/136408#M95666</guid>
      <dc:creator>philipp91</dc:creator>
      <dc:date>2013-02-07T12:45:16Z</dc:date>
    </item>
    <item>
      <title>Re: DbSqlSession.getUpdatedObjects() and byte arrays</title>
      <link>https://connect.hyland.com/t5/alfresco-archive/dbsqlsession-getupdatedobjects-and-byte-arrays/m-p/136409#M95667</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;The ByteArray-comparison now works fine.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;However, in the case of a HashMap (and also HashSet, which internally uses HashMap), the byte-array will change, so the comparison returns "false", which is actually correct and causes the byte-array to be written to the database although the HashMap hasn't changed.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;It should be possible to reproduce it in Activiti 5.12 exactly like I described in my second post, except that it doesn't fail because of the incorrect array comparison, but because the array actually changed even though it shouldn't. Therefore, getVariablesLocal() causes data to be *written* to the database, but it is meant to read only, of course.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;// EDIT: This is the statement that detects the "change": &lt;/SPAN&gt;&lt;A href="https://github.com/Activiti/Activiti/blob/master/modules/activiti-engine/src/main/java/org/activiti/engine/impl/variable/DeserializedObject.java#L39^" rel="nofollow noopener noreferrer"&gt;https://github.com/Activiti/Activiti/blob/master/modules/activiti-engine/src/main/java/org/activiti/engine/impl/variable/DeserializedObject.java#L39^&lt;/A&gt;&lt;BR /&gt;&lt;SPAN&gt;// EDIT2: Simple workaround: Do not use hash-based collections. However, Activiti developers might consider checking the variable value and not its serialized form for equality (i.e. use .equals() on the value, in this case this would call HashSet.equals() instead of Arrays.equals(byte[]..)) in order to decide whether to write the value back to the database, or not.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 26 Mar 2013 17:28:58 GMT</pubDate>
      <guid>https://connect.hyland.com/t5/alfresco-archive/dbsqlsession-getupdatedobjects-and-byte-arrays/m-p/136409#M95667</guid>
      <dc:creator>philipp91</dc:creator>
      <dc:date>2013-03-26T17:28:58Z</dc:date>
    </item>
    <item>
      <title>Re: DbSqlSession.getUpdatedObjects() and byte arrays</title>
      <link>https://connect.hyland.com/t5/alfresco-archive/dbsqlsession-getupdatedobjects-and-byte-arrays/m-p/136410#M95668</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;The equals-call on the actual object is not a good solution in all cases, as the deserialized object is kept in memory. The default equals (based in memory-location) will return true every time, even if a member-field is changed. These changes do get picked up by a compare of the actual byte-value of the serialization.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;The best solution would be to NOT add a DeserializedObject when variables are fetched only for "read". Not sure if this is an easy fix as the read is done on a low-level.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 27 Mar 2013 12:26:50 GMT</pubDate>
      <guid>https://connect.hyland.com/t5/alfresco-archive/dbsqlsession-getupdatedobjects-and-byte-arrays/m-p/136410#M95668</guid>
      <dc:creator>frederikherema1</dc:creator>
      <dc:date>2013-03-27T12:26:50Z</dc:date>
    </item>
  </channel>
</rss>

