jython - new txn - CopyOnWriteArrayList

davidcullen's Avatar


19 Oct, 2019 04:53 AM

I’ve recently upgraded to mac Catalina and I’m not sure if this has something to do with my problem. I’m also running the latest Java code (Java 8 Update 23) and md Version 2019.3 (1880).
Recently I have experienced a newproblem with trying to create new transactions programmatically in jython. I am self taught in jython and and only know a very little about programming in Java. I only use Python/Jython.
The code I have used to create a new transaction is as follows:

acc_1 = root.getAccountByName("Rental:Z:Debit interest - apportionable:EM1") 
acc_2 = root.getAccountByName("Rental:X:Interest - deductible")
acc_3 = root.getAccountByName('Non-deductible interest & fees')
txn = ParentTxn(book) 
txn.setDescription("Debit interest apportioned") 
txnSplit = SplitTxn(txn) 
txnSplit.setParentAmount(1.0, -555) 
txnSplit.setDescription("Apportioned amount")
txnSplit = SplitTxn(txn) 
txnSplit.setParentAmount(1.0, -111) 
txnSplit.setDescription("Apportioned amount") 
This code used to work perfectly before but now I find that after running it that the parent transaction has an empty keyword of the class CopyOnWriteArrayList when previously this showed as an empty keyword of class ArrayList.
I understand that parent transactions are not supposed to hold any keyword (even though they theoretically can) and that keywords should only be held by their split transactions. However this new CopyOnWriteArrayList class empty keyword is causing some problems for me – other parent transactions already existing before the newly created transaction all have an empty keyword of class ArrayList (which works fine).
I’m not sure what I am doing incorrectly or how I can change the new empty keyword class to an empty ArrayList to be consistent with the other existing parent transactions.
Any guidance you can give would be very much appreciated.
  1. 1 Posted by hleofxquotes on 19 Oct, 2019 04:38 PM

    hleofxquotes's Avatar

    Hi David,

    However this new CopyOnWriteArrayList class empty keyword is causing some problems for me

    Can you give a bit more detail on the "problem"? Was there any error? exception?

    Re: CopyOnWriteArrayList vs ArrayList: I don't know the specific on MD code but conceptually both represent "a list'. CopyOnWriteArrayList is used when multiple threads could access a same list and you need to ensure that while one thread is iterating, changes made in other threads (adding) do not affect the iteration. Essentially, to allow some concurrency without having to lock/synchronize the list.

  2. 2 Posted by davidcullen on 20 Oct, 2019 02:54 AM

    davidcullen's Avatar

    Thanks for the prompt response. No errors thrown as such. Difference seems to be that new ParentTxn created which has empty CopyOnWriteArrayList (vs ArrayList Keywords) cannot seem to be edited in md to add a keyword whereas old ParentTxn which have empty ArrayList Keywords can be edited. This is not really a "bad" thing as all my ParentTxns are not supposed to have any Keywords - only their SplitTxns should have any (I test for this programmatically to find any "accidentally" added which I then "move" to their respective SplitTxns). I guess going forward I just need to be aware that some (empty) keywords will be CopyOnWriteArrayList class whereas others will be ArrayList class.

  3. 3 Posted by hleofxquotes on 21 Oct, 2019 04:40 PM

    hleofxquotes's Avatar

    Interesting ... is this "old" vs "new" ParentTxn being represented internally as ArrayList vs CopyOnWriteArrayList only at time of creation?

    If you close MD, re-open and re-read those ParentTxn's, do you still see this disctinction (ArrayList vs CopyOnWriteArrayList)?

  4. Support Staff 4 Posted by Sean Reilly on 21 Oct, 2019 08:56 PM

    Sean Reilly's Avatar

    Hi David,
    Instead of modifying the returned list, please use the setKeywords(List) method to update the keywords, preferably with a new list object. The CopyOnWriteArrayList was my mistake.. it really should be a read-only list being returned, and may be changed to work that way in the future.


    Sean Reilly
    Developer, The Infinite Kind

  5. 5 Posted by davidcullen on 23 Oct, 2019 01:56 AM

    davidcullen's Avatar

    hleofxquotes: Opening/closing md does not seem to make any difference. Some are now CopyOnWriteArrayList but others are ArrayList.

    Sean Reilly: I am now using the setKeywords(List) method to update the keywords, with a new list object, and this seems to work fine. The read-only list (CopyOnWriteArrayList) is fine and this stops keywords being accidentally entered for ParentTxns (there should only be keywords for SplitTxns). I programmatically check for and ParentTxn ArrayList keywords and "move" them to their SplitTxns - all seems to be working fine now.

  6. davidcullen closed this discussion on 22 Dec, 2019 03:01 AM.

Comments are currently closed for this discussion. You can start a new one.

Keyboard shortcuts


? Show this help
ESC Blurs the current field

Comment Form

r Focus the comment reply box
^ + ↩ Submit the comment

You can use Command ⌘ instead of Control ^ on Mac