Issue 116192

Summary: [sw] fixed text fields sometimes get updated
Product: Writer Reporter: mst.ooo
Component: codeAssignee: mst.ooo
Status: CLOSED FIXED QA Contact: issues@sw <issues>
Severity: Trivial    
Priority: P3 CC: issues, Mathias_Bauer, os_ooo, stephan.bergmann.secondary
Version: DEV300m95   
Target Milestone: 3.4.0   
Hardware: All   
OS: All   
Issue Type: DEFECT Latest Confirmation in: ---
Developer Difficulty: ---

Description mst.ooo 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:
E.

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,
    pNewDateTime=0x0)
    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&) ()
   from
OO_m95_DEV300_li/opt/openoffice.org3/program/../basis-link/program/libsvlli.so
#4  0x05917423 in ?? ()
   from
OO_m95_DEV300_li/opt/openoffice.org3/program/../basis-link/program/libsfxli.so
#5  0x059174c2 in ?? ()
   from
OO_m95_DEV300_li/opt/openoffice.org3/program/../basis-link/program/libsfxli.so
#6  0x012224db in ?? ()
   from
OO_m95_DEV300_li/opt/openoffice.org3/program/../basis-link/program/libvclli.so
#7  0x0123aca3 in Timer::Timeout() ()
   from
OO_m95_DEV300_li/opt/openoffice.org3/program/../basis-link/program/libvclli.so
#8  0x0123b042 in Timer::ImplTimerCallbackProc() ()
   from
OO_m95_DEV300_li/opt/openoffice.org3/program/../basis-link/program/libvclli.so


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

    case SFX_EVENT_CREATEDOC:
        // 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() ==
document::UpdateDocMode::NO_UPDATE)
                bUpdateFields = sal_False;
            pWrtSh->SetFixFields();         // HERE!
            if(bUpdateFields)

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 mst.ooo 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
http://hg.services.openoffice.org/hg/cws/sw34bf03/rev/de7161d6ce70
Comment 2 mst.ooo 2010-12-22 09:37:03 UTC
@mba:

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:

SFX_EVENT_LOADFINISHED
SFX_EVENT_ACTIVATEDOC
SFX_EVENT_VIEWCREATED
20008 (what is this?)
SFX_EVENT_CREATEDOC

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
template?
that could then be used together with LOADFINISHED (which presumably is sent
synchronously)...

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 mst.ooo 2010-12-22 11:50:45 UTC
fixed it again, by using SFX_EVENT_LOADFINISHED.
http://hg.services.openoffice.org/hg/cws/sw34bf03/rev/81725aa6b7c5
Comment 5 mst.ooo 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.

http://hg.services.openoffice.org/hg/cws/sw34bf03/rev/c3e2a7f0b7c8