https://bz.apache.org/bugzilla/show_bug.cgi?id=69813
Bug ID: 69813
Summary: StylesTable uses a catch block for logic flow
Product: POI
Version: unspecified
Hardware: All
OS: All
Status: NEW
Severity: normal
Priority: P2
Component: XSSF
Assignee: [email protected]
Reporter: [email protected]
Target Milestone: ---
Filing a bug rather than submitting a PR or just committing myself (it's been a
few years!) because our new ownership doesn't know how to let employees
contribute to open-source projects yet - legal has them paranoid about exposing
IP. I've not even gotten a clear answer about doing it on my own time on my
own machine if it relates to work code, and I don't want to fight that one even
if I'm in the right.
So, commentary aside, this is a simple one to fix that cut one of our use cases
by 70%:
StylesTable method:
public TableStyle getTableStyle(String name) {
if (name == null) return null;
try {
return XSSFBuiltinTableStyle.valueOf(name).getStyle();
} catch (IllegalArgumentException e) {
return getExplicitTableStyle(name);
}
}
turns out to cause performance issues when we have a sheet with a large table
and custom table style. If this method is called a few thousand times, 80% of
the CPU time spent is on generating stack traces for the thrown
IllegalArgumentException, which is never used.
Of course, best practices say don't use checked exceptions for logic control,
for exactly that reason. This looks like someone didn't expect custom table
formats to be used very often, so they figured it would be a simple route to
take. Turns out we defy that logic :)
Instead, it should check getExplictTableStyle(name) first, as that just returns
null if the hash lookup fails, then try the builtins and return null if it
isn't one of those either. That would truly be an exceptional case, where
there was a named style but it wasn't a builtin or custom definition. That
would be an invalid Excel file, so using an exception to notice it is fine.
--
You are receiving this mail because:
You are the assignee for the bug.
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]