KXMLGui: Fix merge indices when removing xmlgui clients with actions in groups.
ClosedPublic

Authored by dfaure on Jun 16 2016, 10:37 PM.

Details

Summary

The code was assuming that all actions from the client being removed
were together in one merge point, but the group feature (added slightly later)
changed that. Indices therefore have to be adjusted after each action removal.

While extending the unittest to check this for dynamic actionlists, I found
another bug in the updating of merging indices: when a client inserts an
actionlist element (or possibly a group element for child-child-clients)
and then N more actions, the actionlist would go down N times. Fixed by
comparing clientNames, i.e. only merge points from other clients should
go down while inserting actions, nor our own [except in plugActionList].

BUG: 64754
FIXED-IN: 5.24

Test Plan

Editing toolbars in kate to add actions (without group) to
the katepart toolbar, would lead to incoherent moving of toolbar buttons
at every document switch. This commit fixes that.

Diff Detail

Branch
master
Lint
No Linters Available
Unit
No Unit Test Coverage
dfaure updated this revision to Diff 4564.Jun 16 2016, 10:37 PM
dfaure retitled this revision from to KXMLGui: Fix merge indices when removing xmlgui clients with actions in groups..
dfaure updated this object.
dfaure edited the test plan for this revision. (Show Details)
dfaure added reviewers: svuorela, dhaumann.
dhaumann accepted this revision.Jun 17 2016, 7:55 AM
dhaumann edited edge metadata.

I think this patch looks good (given we sat in front of this issue together, I think I also know what's going on). There are still open questions, but that's rather unrelated to this patch.

Tested with this patch in Kate, it seems to work. All kxmlgui unit tests still pass.

I'm fine with committing. And btw, thanks a lot!

autotests/kxmlgui_unittest.cpp
305

Interesting, this looks as if there were invalid reads before?

411

Is this qDebug() intentional?

src/kxmlguifactory_p.cpp
717

I'm not sure I get this in detail: but as you already mentioned yesterday, it seems this saves iterators. It seems to me this code was written at a time (?) when QList iterators were stable, but since a QList behaves similar to a QVector for ints (iirc), this is rather dangerous, right? I guess that is what you imply with your comment here. In that case, it's a wonder all this is still working ;)

This revision is now accepted and ready to land.Jun 17 2016, 7:55 AM
svuorela added inline comments.Jun 17 2016, 8:26 AM
autotests/kxmlgui_unittest.cpp
306

Isn't it better to move the last QCOMPARE(count,count); up first? Or is it to be able to easier debug if something went wrong?

src/kxmlguibuilder.h
83

And use what instead? maybe mark deprecated?

src/kxmlguifactory_p.cpp
391

actions is const, so range based for is free to use

717

this is the only place the QList is actualyl modified so it is actually safe. but only until the next person modifies the code...

dfaure marked 2 inline comments as done.Jun 17 2016, 8:47 AM
dfaure added inline comments.
autotests/kxmlgui_unittest.cpp
305

Not exactly. QList's [i] asserts when called out of bounds. It didn't happen before, because when the test passes, actions == expectedActions ;)
It simply happened to me while working on the unittest and getting less actions than expected.

306

Right it's at the end because when "A,B,C" is matched against "A,D,B,C" I'd rather be told "at position 1 I expected D but got B" than "expected 3, got 4". Easier to debug.

411

It was, but ok, let's remove it.

src/kxmlguibuilder.h
83

And use nothing, it was only used internally and it's not used anymore.

AFAICS nobody uses this, but yes, good idea to add deprecation macro to make sure it stays that way.

src/kxmlguifactory_p.cpp
717

I actually looked at the kdelibs3 code and it was using QValueList already ;)

Yes it's dangerous to store iterators into a QList or QVector, however what this code does (right under this comment) is to recalculate these two iterators when adding to the QList, which solves exactly that risk. My commit simply makes that more explicit in the comment.

Hmm, I forgot to check for code _removing_ from the list. Although I doubt QList reallocates when shrinking. Checked now, there isn't.

BTW I also searched bugzilla for crashes related to ContainerNode and BuildHelper and didn't find anything ;)

dfaure closed this revision.Jun 17 2016, 8:50 AM
dfaure marked an inline comment as done.