Bug 140226 - Make use of SfxPoolItems more typesafe by using StaticWhichCast
Summary: Make use of SfxPoolItems more typesafe by using StaticWhichCast
Status: NEW
Alias: None
Product: LibreOffice
Classification: Unclassified
Component: Writer (show other bugs)
Version:
(earliest affected)
Inherited From OOo
Hardware: All All
: medium normal
Assignee: Not Assigned
URL:
Whiteboard: target:7.2.0 target:7.3.0 target:7.6....
Keywords: difficultyMedium, easyHack, skillCpp, skillTest, topicCleanup
Depends on:
Blocks: Dev-related
  Show dependency treegraph
 
Reported: 2021-02-07 00:52 UTC by Björn Michaelsen
Modified: 2026-04-28 06:55 UTC (History)
2 users (show)

See Also:
Crash report or crash signature:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Björn Michaelsen 2021-02-07 00:52:43 UTC
Description:
There is a lot of code of the form:

    switch ( rItem.Which() )
    {
        case RES_CHRATR_CASEMAP:
            rFnt.SetCaseMap( static_cast<const SvxCaseMapItem&>(rItem).GetCaseMap() );
            break;
    ...

in Writer and elsewhere. That is: code that uses SfxPoolItems home-grown "WhichId" as type information and then uses a static_cast to downcast the base class to a proper type. As this "WhichId" is generated at runtime, this is errorprone and fragile. Since the introduction of TypedWhichId in include/svl/typedwhich.hxx (Thanks Noel!), there exists a proper mapping of WhichIds to the derived classes of SfxPoolItem. SfxPoolItem::StaticWhichCast uses these to do a proper downcast, while asserting if either the WhichId or the dynamic type does not match expectations. This EasyHack is to:

1/ Find such a static_cast. "git grep static_cast.*Item" might be a starting
   point.
2/ Replace the static_cast with a StaticWhichCast. An example of how this is done
   can be found at: https://gerrit.libreoffice.org/c/core/+/110233
3/ Ensure the debug builds still pass all tests after the change (gerrit/jenkins
   can help here.)

What is to be done, if one of the StaticWhichCasts asserts? Congratulations, you likely just dicovered some type confusion in LibreOffice. You now have three options to resolve this issue:
a/ Investigate how the misleading item ended up in this place and fix it. This
   might be non-trivial.
b/ Put a big, fat FIXME note in the source code hinting that the content of the
   SfxPoolItem defies expectations, use a DynamicWhichCast instead and guard the
   following code against the case that the cast produces a nullptr.
c/ Leave this particular static_cast as is and ad a big, fat FIXME not as per
   above.

Ultimately, a/ is the best option here, but it might be out of the scope of an EasyHack. If you have help available (e.g. from #libreoffice-dev IRC), you might still venture to solve it.

Steps to Reproduce:
.

Actual Results:
.

Expected Results:
.


Reproducible: Always


User Profile Reset: No



Additional Info:
.
Comment 1 Commit Notification 2021-02-23 16:21:58 UTC
Bjoern Michaelsen committed a patch related to this issue.
It has been pushed to "master":

https://git.libreoffice.org/core/commit/a3f83ecbeab33244b526ec68ca0f2034745a6371

tdf#140226: use StaticWhichCast

It will be available in 7.2.0.

The patch should be included in the daily builds available at
https://dev-builds.libreoffice.org/daily/ in the next 24-48 hours. More
information about daily builds can be found at:
https://wiki.documentfoundation.org/Testing_Daily_Builds

Affected users are encouraged to test the fix and report feedback.
Comment 2 Commit Notification 2021-04-09 08:50:24 UTC
Ahmet Hakan Çelik committed a patch related to this issue.
It has been pushed to "master":

https://git.libreoffice.org/core/commit/7f9a66cb11f0889bf10542a17c144f9665c0ce70

tdf#140226: Make use of SfxPoolItems more typesafe by using StaticWhichCast

It will be available in 7.2.0.

The patch should be included in the daily builds available at
https://dev-builds.libreoffice.org/daily/ in the next 24-48 hours. More
information about daily builds can be found at:
https://wiki.documentfoundation.org/Testing_Daily_Builds

Affected users are encouraged to test the fix and report feedback.
Comment 3 Commit Notification 2021-08-14 06:36:24 UTC
Emircan Agac committed a patch related to this issue.
It has been pushed to "master":

https://git.libreoffice.org/core/commit/da76d817400242934fdaebcdb226abf3d6595f56

tdf#140226: use StaticWhichCast

It will be available in 7.3.0.

The patch should be included in the daily builds available at
https://dev-builds.libreoffice.org/daily/ in the next 24-48 hours. More
information about daily builds can be found at:
https://wiki.documentfoundation.org/Testing_Daily_Builds

Affected users are encouraged to test the fix and report feedback.
Comment 4 Commit Notification 2021-08-14 06:37:35 UTC
Emircan Agac committed a patch related to this issue.
It has been pushed to "master":

https://git.libreoffice.org/core/commit/1fdb3f98590532705be9972d031eb09027795760

tdf#140226: use StaticWhichCast

It will be available in 7.3.0.

The patch should be included in the daily builds available at
https://dev-builds.libreoffice.org/daily/ in the next 24-48 hours. More
information about daily builds can be found at:
https://wiki.documentfoundation.org/Testing_Daily_Builds

Affected users are encouraged to test the fix and report feedback.
Comment 5 Commit Notification 2021-08-14 06:37:44 UTC
Emircan Agac committed a patch related to this issue.
It has been pushed to "master":

https://git.libreoffice.org/core/commit/d5eceef8e02886edc142267ee8d74f7adb198a1b

tdf#140226: use StaticWhichCast

It will be available in 7.3.0.

The patch should be included in the daily builds available at
https://dev-builds.libreoffice.org/daily/ in the next 24-48 hours. More
information about daily builds can be found at:
https://wiki.documentfoundation.org/Testing_Daily_Builds

Affected users are encouraged to test the fix and report feedback.
Comment 6 Commit Notification 2021-09-17 08:52:58 UTC
Baran Aytas committed a patch related to this issue.
It has been pushed to "master":

https://git.libreoffice.org/core/commit/6184eefa835f0495ed8136471d61837f5662b6d6

tdf#140226: Make use of SfxPoolItems more typesafe by using StaticWhichCast

It will be available in 7.3.0.

The patch should be included in the daily builds available at
https://dev-builds.libreoffice.org/daily/ in the next 24-48 hours. More
information about daily builds can be found at:
https://wiki.documentfoundation.org/Testing_Daily_Builds

Affected users are encouraged to test the fix and report feedback.
Comment 7 Commit Notification 2023-03-16 09:50:47 UTC
Bayram Çiçek committed a patch related to this issue.
It has been pushed to "master":

https://git.libreoffice.org/core/commit/66d38ba8e9ccb7ba0ef5b3feb67b241a5b6b2e80

tdf#140226: use StaticWhichCast in htmlatr.cxx

It will be available in 7.6.0.

The patch should be included in the daily builds available at
https://dev-builds.libreoffice.org/daily/ in the next 24-48 hours. More
information about daily builds can be found at:
https://wiki.documentfoundation.org/Testing_Daily_Builds

Affected users are encouraged to test the fix and report feedback.
Comment 8 Commit Notification 2023-05-15 21:36:21 UTC
MoazAlaa committed a patch related to this issue.
It has been pushed to "master":

https://git.libreoffice.org/core/commit/a9d60aba81305bf86024df707eb694d1cabc9a1d

tdf#140226: use StaticWhichCast

It will be available in 7.6.0.

The patch should be included in the daily builds available at
https://dev-builds.libreoffice.org/daily/ in the next 24-48 hours. More
information about daily builds can be found at:
https://wiki.documentfoundation.org/Testing_Daily_Builds

Affected users are encouraged to test the fix and report feedback.
Comment 9 Commit Notification 2024-10-29 08:50:45 UTC
Oromidayo Owolabi committed a patch related to this issue.
It has been pushed to "master":

https://git.libreoffice.org/core/commit/7d942fbff01e69d10c23c6d20d10ecc8558004f3

tdf#140226 use StaticWhichCast

It will be available in 25.2.0.

The patch should be included in the daily builds available at
https://dev-builds.libreoffice.org/daily/ in the next 24-48 hours. More
information about daily builds can be found at:
https://wiki.documentfoundation.org/Testing_Daily_Builds

Affected users are encouraged to test the fix and report feedback.
Comment 10 Commit Notification 2024-12-26 19:38:41 UTC
Oromidayo Owolabi committed a patch related to this issue.
It has been pushed to "master":

https://git.libreoffice.org/core/commit/dfdbc253ff6a3e7fc1bc516279a5a5d4b33baa85

tdf#140226 use StaticWhichCast

It will be available in 25.8.0.

The patch should be included in the daily builds available at
https://dev-builds.libreoffice.org/daily/ in the next 24-48 hours. More
information about daily builds can be found at:
https://wiki.documentfoundation.org/Testing_Daily_Builds

Affected users are encouraged to test the fix and report feedback.
Comment 11 Commit Notification 2024-12-26 19:51:45 UTC
Oromidayo Owolabi committed a patch related to this issue.
It has been pushed to "master":

https://git.libreoffice.org/core/commit/ad56e437b0534a69f4f687919eeb56690177bb2d

tdf#140226 use StaticWhichCast

It will be available in 25.8.0.

The patch should be included in the daily builds available at
https://dev-builds.libreoffice.org/daily/ in the next 24-48 hours. More
information about daily builds can be found at:
https://wiki.documentfoundation.org/Testing_Daily_Builds

Affected users are encouraged to test the fix and report feedback.
Comment 12 Commit Notification 2025-01-01 09:30:29 UTC
Manish Bera committed a patch related to this issue.
It has been pushed to "master":

https://git.libreoffice.org/core/commit/7d1d111c36c9e81d41442f3eb29f7fc52b598c90

tdf#140226: use StaticWhichCast

It will be available in 25.8.0.

The patch should be included in the daily builds available at
https://dev-builds.libreoffice.org/daily/ in the next 24-48 hours. More
information about daily builds can be found at:
https://wiki.documentfoundation.org/Testing_Daily_Builds

Affected users are encouraged to test the fix and report feedback.
Comment 13 Commit Notification 2026-04-22 06:33:27 UTC
Julien Nabet committed a patch related to this issue.
It has been pushed to "master":

https://git.libreoffice.org/core/commit/abed1869c0c1f75f856358e208bf113e623b8f12

Related tdf#140226: use StaticWhichCast (chart2 part 1)

It will be available in 26.8.0.

The patch should be included in the daily builds available at
https://dev-builds.libreoffice.org/daily/ in the next 24-48 hours. More
information about daily builds can be found at:
https://wiki.documentfoundation.org/Testing_Daily_Builds

Affected users are encouraged to test the fix and report feedback.
Comment 14 Commit Notification 2026-04-25 06:41:54 UTC
Julien Nabet committed a patch related to this issue.
It has been pushed to "master":

https://git.libreoffice.org/core/commit/9d510964a98a000155877cb45e79cd61ed5ffa00

Related tdf#140226: use StaticWhichCast (chart2 part 2)

It will be available in 26.8.0.

The patch should be included in the daily builds available at
https://dev-builds.libreoffice.org/daily/ in the next 24-48 hours. More
information about daily builds can be found at:
https://wiki.documentfoundation.org/Testing_Daily_Builds

Affected users are encouraged to test the fix and report feedback.
Comment 15 Commit Notification 2026-04-26 11:29:19 UTC
Julien Nabet committed a patch related to this issue.
It has been pushed to "master":

https://git.libreoffice.org/core/commit/a909fbdaeb5335ca32a9bf6862780f990c845272

Related tdf#140226: use StaticWhichCast in annotationmanager.cxx (sd)

It will be available in 26.8.0.

The patch should be included in the daily builds available at
https://dev-builds.libreoffice.org/daily/ in the next 24-48 hours. More
information about daily builds can be found at:
https://wiki.documentfoundation.org/Testing_Daily_Builds

Affected users are encouraged to test the fix and report feedback.
Comment 16 Commit Notification 2026-04-26 11:59:24 UTC
Julien Nabet committed a patch related to this issue.
It has been pushed to "master":

https://git.libreoffice.org/core/commit/062a34deb3018db90561ecfb6f172e95fca8e367

Related tdf#140226: use StaticWhichCast in editeng

It will be available in 26.8.0.

The patch should be included in the daily builds available at
https://dev-builds.libreoffice.org/daily/ in the next 24-48 hours. More
information about daily builds can be found at:
https://wiki.documentfoundation.org/Testing_Daily_Builds

Affected users are encouraged to test the fix and report feedback.
Comment 17 Commit Notification 2026-04-26 13:40:34 UTC
Julien Nabet committed a patch related to this issue.
It has been pushed to "master":

https://git.libreoffice.org/core/commit/b0e6e6c350e19c7634d6bbc2807d474a0c487a85

Related tdf#140226: use StaticWhichCast in drviews7.cxx (sd)

It will be available in 26.8.0.

The patch should be included in the daily builds available at
https://dev-builds.libreoffice.org/daily/ in the next 24-48 hours. More
information about daily builds can be found at:
https://wiki.documentfoundation.org/Testing_Daily_Builds

Affected users are encouraged to test the fix and report feedback.
Comment 18 Commit Notification 2026-04-27 06:50:51 UTC
Julien Nabet committed a patch related to this issue.
It has been pushed to "master":

https://git.libreoffice.org/core/commit/1f38dc2c69cf1bc1f71c58735d267d48bf3e34c8

Related tdf#140226: use StaticWhichCast in fupage.cxx + 2 hrc (sd+include/svx)

It will be available in 26.8.0.

The patch should be included in the daily builds available at
https://dev-builds.libreoffice.org/daily/ in the next 24-48 hours. More
information about daily builds can be found at:
https://wiki.documentfoundation.org/Testing_Daily_Builds

Affected users are encouraged to test the fix and report feedback.
Comment 19 Commit Notification 2026-04-27 19:45:30 UTC
Julien Nabet committed a patch related to this issue.
It has been pushed to "master":

https://git.libreoffice.org/core/commit/4f1d95b0cc85e0b05c0b97c90f7d5df2d4272b76

Related tdf#140226: use StaticWhichCast in svdmodel (svx)

It will be available in 26.8.0.

The patch should be included in the daily builds available at
https://dev-builds.libreoffice.org/daily/ in the next 24-48 hours. More
information about daily builds can be found at:
https://wiki.documentfoundation.org/Testing_Daily_Builds

Affected users are encouraged to test the fix and report feedback.
Comment 20 Commit Notification 2026-04-27 19:57:33 UTC
Julien Nabet committed a patch related to this issue.
It has been pushed to "master":

https://git.libreoffice.org/core/commit/c0b0a18f5c82ff0ea6ceff1c2e3c1fcab9496681

Related tdf#140226: use StaticWhichCast in ww8graf+drwtxtex (sw)

It will be available in 26.8.0.

The patch should be included in the daily builds available at
https://dev-builds.libreoffice.org/daily/ in the next 24-48 hours. More
information about daily builds can be found at:
https://wiki.documentfoundation.org/Testing_Daily_Builds

Affected users are encouraged to test the fix and report feedback.
Comment 21 Commit Notification 2026-04-28 06:55:35 UTC
Julien Nabet committed a patch related to this issue.
It has been pushed to "master":

https://git.libreoffice.org/core/commit/ea3816d1c7108df8113cce0ad6ddb218951993e2

Related tdf#140226: use StaticWhichCast in AccessibilityCheck (sw)

It will be available in 26.8.0.

The patch should be included in the daily builds available at
https://dev-builds.libreoffice.org/daily/ in the next 24-48 hours. More
information about daily builds can be found at:
https://wiki.documentfoundation.org/Testing_Daily_Builds

Affected users are encouraged to test the fix and report feedback.