Bug 107572 - Macro Calc Range autoformat("Default") throws IllegalArgumentException
Summary: Macro Calc Range autoformat("Default") throws IllegalArgumentException
Status: RESOLVED FIXED
Alias: None
Product: LibreOffice
Classification: Unclassified
Component: BASIC (show other bugs)
Version:
(earliest affected)
5.2.0.0.alpha1
Hardware: All All
: medium normal
Assignee: Julien Nabet
QA Contact:
URL:
Whiteboard: target:5.4.0 target:5.3.4
Keywords: bibisectRequest, regression
Depends on:
Blocks:
 
Reported: 2017-05-02 19:47 UTC by database.frameworks
Modified: 2017-05-11 14:19 UTC (History)
1 user (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 database.frameworks 2017-05-02 19:47:25 UTC
Description:
Wrote a function in BASIC that formats a Calc range using .autoformat function, see documentation here: http://api.libreoffice.org/docs/idl/ref/interfacecom_1_1sun_1_1star_1_1table_1_1XAutoFormattable.html

In the API reference it says it throws the error com::sun::star::lang::IllegalArgumentException if the specified AutoFormat does not exist. However, calling .autoformat("Default") throws this error, even though "Default" is an autoformat that exists.

Steps to Reproduce:
1. Open a calc document
2. In any BASIC macro routine, copy in the following line of code:

thisComponent.Sheets(0).getCellRangeByName("A1:F14").autoformat("Default")

3. Running this macro results in the IllegalArgumentException
4. Confirm that the syntax is correct by using a different autoformat like:

thisComponent.Sheets(0).getCellRangeByName("A1:F14").autoformat("Green")

Actual Results:  
IllegalArgumentException

Expected Results:
Calc Range Autoformatted using "Default" autoformatting


Reproducible: Always

User Profile Reset: Yes

Additional Info:


User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:53.0) Gecko/20100101 Firefox/53.0
Comment 1 Xisco Faulí 2017-05-02 21:46:19 UTC
Reproduced in

Version: 5.4.0.0.alpha0+
Build ID: 597a2f5d5bd37443262b0775b8439bc3502aef1b
CPU threads: 4; OS: Linux 4.8; UI render: default; VCL: gtk2; 
Locale: ca-ES (ca_ES.UTF-8); Calc: group

and

Version: 5.2.0.0.alpha1+
Build ID: 5b168b3fa568e48e795234dc5fa454bf24c9805e
CPU Threads: 4; OS Version: Linux 4.8; UI Render: default; 
Locale: ca-ES (ca_ES.UTF-8)

but not in

Version: 5.0.0.0.alpha1+
Build ID: 0db96caf0fcce09b87621c11b584a6d81cc7df86
Locale: ca-ES (ca_ES.UTF-8)
Comment 2 Julien Nabet 2017-05-07 23:15:17 UTC
I submitted this patch for review:
https://gerrit.libreoffice.org/#/c/37362/
Comment 3 Julien Nabet 2017-05-08 06:55:12 UTC
Some explanation:
autoformat code in macro is called here:
   5424         ScAutoFormat* pAutoFormat = ScGlobal::GetOrCreateAutoFormat();
   5425         ScAutoFormat::const_iterator it = pAutoFormat->find(aName);
   5426         if (it != pAutoFormat->end())
   5427         {
   5428             ScAutoFormat::const_iterator itBeg = pAutoFormat->begin();
   5429             size_t nIndex = std::distance(itBeg, it);
   5430             pDocSh->GetDocFunc().AutoFormat(aRange, nullptr, nIndex, true);
   5431         }
   5432         else
   5433             throw lang::IllegalArgumentException();

(see http://opengrok.libreoffice.org/xref/core/sc/source/ui/unoobj/cellsuno.cxx#5418)

pAutoFormat contains a map (m_Data) which indeed includes "Default" when testing on gdb

    310 class SC_DLLPUBLIC ScAutoFormat
    311 {
    312     typedef std::map<OUString, std::unique_ptr<ScAutoFormatData>, DefaultFirstEntry> MapType;
    313     MapType m_Data;
(see http://opengrok.libreoffice.org/xref/core/sc/inc/autoform.hxx#ScAutoFormat)

find call line 5425 from cellsuno.cxx can't find "Default" entry in the map and always returns itEnd

The problem is DefaultFirstEntry
    911 bool DefaultFirstEntry::operator() (const OUString& left, const OUString& right) const
    912 {
    913     OUString aStrStandard(ScGlobal::GetRscString(STR_STYLENAME_STANDARD));
    914     if ( ScGlobal::GetpTransliteration()->isEqual( left, aStrStandard ) )
    915         return true;
    916     if ( ScGlobal::GetpTransliteration()->isEqual( right, aStrStandard ) )
    917         return false;
    918     return ScGlobal::GetCollator()->compareString( left, right) < 0;
    919 }
(see http://opengrok.libreoffice.org/xref/core/sc/source/core/tool/autoform.cxx#911)

If a parameter corresponds to aStrStandard, it can return true or false (according if it's left or right parameter). In my case, it always return true.

So we must first check if left and right parameter are equal and return false in this case.
Comment 4 Commit Notification 2017-05-10 21:46:04 UTC
Julien Nabet committed a patch related to this issue.
It has been pushed to "master":

http://cgit.freedesktop.org/libreoffice/core/commit/?id=965494c544dd8f35ae83b7cf38549009da06c367

tdf#107572: retrieve Default autoformat

It will be available in 5.4.0.

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

Affected users are encouraged to test the fix and report feedback.
Comment 5 Julien Nabet 2017-05-10 21:54:17 UTC
For 5.3 branch: https://gerrit.libreoffice.org/#/c/37487/
Comment 6 Commit Notification 2017-05-11 14:19:50 UTC
Julien Nabet committed a patch related to this issue.
It has been pushed to "libreoffice-5-3":

http://cgit.freedesktop.org/libreoffice/core/commit/?id=9fd3f402e7a6dfe133433d05de7452f32e1c41ba&h=libreoffice-5-3

tdf#107572: retrieve Default autoformat

It will be available in 5.3.4.

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

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