Exmaralda-Org / exmaralda

26 stars 15 forks source link

Inconsistencies in Find Dialog #127

Closed berndmoos closed 1 year ago

berndmoos commented 6 years ago

The FindDialog keeps the search result until a new search is carried out. When the structure of a transcript changes (e.g. an event is split), it can happen that the search result is no longer valid (i.e. EventSearchResult.offset refers to an offest that is no longer there because the event string in question is shorter than before). This can cause an exception like so:

java.lang.StringIndexOutOfBoundsException: String index out of range: 6 at java.lang.String.substring(String.java:1963) at org.exmaralda.partitureditor.search.SearchResultListCellRenderer.getListCellRendererComponent(SearchResultListCellRenderer.java:46)

The dialog then fails to build up:

image

berndmoos commented 1 year ago

Q: Actually, this must be in the Search & Replace dialog because the Find dialog does not use the offset. But then the Search & Replace dialog is modal??? A: it is in the CellRenderer. The Find dialog is non-modal and is kept after closing, the Replace dialog is modal and is disposed after closing. So this is in the Find dialog.

I can make the error go away by checking within the CellRenderer whether or not offset etc. makes sense. If not, an error line is produced.

This is not a candidate for the Turing Prize for elegant code. Then again, I was practically still a child when I wrote the code for that dialog, so please excuse. One of these days, the Find and Replace dialogs could be remade from scratch. Today is not that day.