Ashhar Ahmad Khan created FINERACT-2806:
-------------------------------------------
Summary: IndexOutOfBoundsException in
JournalEntryWritePlatformServiceImpl.revertJournalEntry when no unreversed
manual journal entries exist
Key: FINERACT-2806
URL: https://issues.apache.org/jira/browse/FINERACT-2806
Project: Apache Fineract
Issue Type: Bug
Reporter: Ashhar Ahmad Khan
*What is broken*
{{JournalEntryWritePlatformServiceImpl.revertJournalEntry(List<JournalEntry>,
String)}} calls {{journalEntries.get(0).getOffice().getId()}} with no check
that the list is non-empty. This overload is called from two places: the public
API entry point {{{}revertJournalEntry(JsonCommand){}}}, which validates the
list is non-empty before calling it, and
{{{}defineOpeningBalance(JsonCommand){}}}, which does not. For each transaction
ID returned by {{{}findNonReversedContraTransactionIds(){}}},
{{defineOpeningBalance()}} fetches journal entries via the narrower
{{findUnReversedManualJournalEntriesByTransactionId()}} query and passes the
result straight into {{revertJournalEntry()}} with no guard. If a contra
transaction has no unreversed manual journal entries (for example, if it was
system-generated rather than manually posted), this query returns an empty list
and the method throws {{{}IndexOutOfBoundsException{}}}, blocking the entire
opening-balance definition workflow.
*Why it's broken*
The guard pattern already exists elsewhere in the same file —
{{revertShareAccountJournalEntries()}} checks for a null or empty list before
an equivalent access — but was never applied to this call site.
*Changes made*
{{JournalEntryWritePlatformServiceImpl.revertJournalEntry(List<JournalEntry>,
String)}} now returns early when the list is null or empty, mirroring the guard
already used elsewhere in the file.
Added {{{}JournalEntryWritePlatformServiceImplTest.java{}}}, a regression test
confirming {{revertJournalEntry()}} no longer throws when called with an empty
list.
--
This message was sent by Atlassian Jira
(v8.20.10#820010)