Issue 116192 - [sw] fixed text fields sometimes get updated
Summary: [sw] fixed text fields sometimes get updated
Alias: None
Product: Writer
Classification: Application
Component: code (show other issues)
Version: DEV300m95
Hardware: All All
: P3 Trivial (vote)
Target Milestone: 3.4.0
QA Contact: issues@sw
Depends on:
Reported: 2010-12-21 12:09 UTC by
Modified: 2017-05-20 10:30 UTC (History)
4 users (show)

See Also:
Issue Type: DEFECT
Latest Confirmation in: ---
Developer Difficulty: ---


Note You need to log in before you can comment on or make changes to this issue.
Description 2010-12-21 12:09:40 UTC
the sw complex test TextPortionEnumeration may fail
like this on any test that contains a text field:

I: <__ROOT__>
I:   <TextField>        content: abc
O: <__ROOT__>
O:   <TextField>        content:
text content differs:   expected: abc   actual:

this happens very rarely, maybe 1 in 100 test runs.

the text fields used by the test are AuthorFields that
are fixed and have a content set before insertion.
the content of the fields should never change;
the test fails because it does change.

some printf output from a failed run:

SwXTextField::setPropertyValue: X(0xad974408) (nil) de
SwXTextField::attachToRange: X(0xad974408) 0xafdaf210 de
SwAuthorField::Copy: 0xafdaf210 1 de -> 0xae5f356c 1 de
SwAuthorField::Copy: 0xae5f356c 1 de -> 0xada14f08 1 de
SwAuthorField::Copy: 0xae5f356c 1 de -> 0xae4bf9cc 1 de
SwAuthorField::Copy: 0xae4bf9cc 1 de -> 0xae4bfe2c 1 de
SwAuthorField::Copy: 0xae4bfe2c 1 de -> 0xae5f324c 1 de
SwAuthorField::Expand: 0xae5f324c 1 de
SwAuthorField::Expand: 0xae5f324c 1 de
SwAuthorField::Expand: 0xae5f324c 1 de
SwDoc::SetFixFields: before: 0xae5f324c de
SwDoc::SetFixFields: after: 0xae5f324c
SwAuthorField::Expand: 0xae5f324c 1
SwAuthorField::QueryValue: 0xae5f324c

apparently SwDoc::SetFixFields is the guilty party. 
it sets the expansion of the field to the empty string.

setting a breakpoint on SetFixFields yields this:

(gdb) bt 10
#0  SwDoc::SetFixFields (this=0xb325b514, bOnlyTimeDate=false,
    at sw/source/core/doc/docfld.cxx:2080
#1  0xaf0e8e82 in SwEditShell::SetFixFields (this=0xb22e61a8,
    bOnlyTimeDate=0 '\000', pNewDateTime=0x0)
    at sw/source/core/edit/edfld.cxx:539
#2  0xaf877e33 in SwModule::Notify (this=0xb2e38b78, rHint=...)
    at sw/source/ui/app/apphdl.cxx:720
#3  0x00b1ebff in SfxBroadcaster::Broadcast(SfxHint const&) ()
#4  0x05917423 in ?? ()
#5  0x059174c2 in ?? ()
#6  0x012224db in ?? ()
#7  0x0123aca3 in Timer::Timeout() ()
#8  0x0123b042 in Timer::ImplTimerCallbackProc() ()

so this is due to some timeout that sends a event.
SwModule::Notify does this:

        // alle FIX-Date/Time Felder auf akt. setzen
        if( pWrtSh )
            SFX_ITEMSET_ARG( pDocSh->GetMedium()->GetItemSet(), pUpdateDocItem,
SfxUInt16Item, SID_UPDATEDOCMODE, sal_False);
            sal_Bool bUpdateFields = sal_True;
            if( pUpdateDocItem &&  pUpdateDocItem->GetValue() ==
                bUpdateFields = sal_False;
            pWrtSh->SetFixFields();         // HERE!

this is apparently sometimes called after content has
already been inserted via the API.
doing this from a timer does not seem to make much sense to me.
Comment 1 2010-12-21 15:58:58 UTC
SetFixFields does not actually need a WrtShell,
so it can be done earlier while there is not yet a view,
so do it when the SFX_EVENT_DOCCREATED event is dispatched synchronously.

fixed in CWS sw34bf03
Comment 2 2010-12-22 09:37:03 UTC

unfortunately this fix breaks the templates:
fixed fields don't get updated when creating new document from a template.

when creating from a template the SFX_EVENT_DOCCREATED event is not sent;
the following events arrive in Notify:

20008 (what is this?)

i assume LOADFINISHED is also sent when opening a regular document?
can i detect via the SfxObjectShell if i'm a regular document created from a
that could then be used together with LOADFINISHED (which presumably is sent

Comment 3 Mathias_Bauer 2010-12-22 11:35:03 UTC
I expect that in case of a document created from a template the event
SFX_EVENT_LOADFINISHED is used and this can be discussed. From a users POV one
could argue that we could send SFX_EVENT_DOCREATED here also (the document knows
that it will become an untitled documents soon after).

Alternatively you can use SFX_EVENT_LOADFINISHED and look in the ItemSet of its
Medium for an item with ID "SID_TEMPLATE" and value "TRUE" or in the "args" of
its model for an argument "AsTemplate" with value "sal_True".
At least AFAIR correctly. :-)
Comment 4 2010-12-22 11:50:45 UTC
fixed it again, by using SFX_EVENT_LOADFINISHED.
Comment 5 2011-02-14 16:42:55 UTC
the TextPortionEnumerationTest complex test was actually disabled in sb123
(issue 111449),
because of exactly this problem.

unfortunately the disabling was done by disabling the entire directory,
which also disabled 5 other complex tests.

i've enabled most of these in sw34bf03,
except for CheckBookmarks, which fails because of a bug fixed in os146.