Hi there,
we are using your batik libraries version 1.7 to render some SVG images
(charts, diagrams, ...). We encountered an issue while trying to render a pie
chart with a gradient that included zero-values for at least one pie slice.
Trying to render the pie chart caused a NullPointerException in our back end.
Cause:
The value of zero lead to the gradient border box of the pie slice to have a
height equal to 0. We tracked down the issue and it seems to be based inside
the org.apache.batik.bridge.SVGRadialGradientElementBridge#buildGradient
implementation (batik-bridge-1.7) in lines 126-138. This section deals with
border boxes of height/width of zero and is commented inside the source code as
follows:
// The last paragraph of section 7.11 in SVG 1.1 states that objects
// with zero width or height bounding boxes that use gradients with
// gradientUnits="objectBoundingBox" must not use the gradient.
In the implementation the following piece of code seems to be missing some
parentheses:
Rectangle2D bbox = ((AbstractGraphicsNodeBridge) bridge).getBBox();
if (bbox != null && bbox.getWidth() == 0 || bbox.getHeight() == 0) {
return null;
}
The check
if (bbox != null && bbox.getWidth() == 0 || bbox.getHeight() == 0) {
Leads to a NullPointerException in case [bbox == null && bbox.getWidth()!=0]. I
did not track down the implementation as to why bbox is null in the first
place, but my guess would be one of the dimensions having been of value zero
during svg parsing.
Possible solution:
The solution seems to be to simply add a pair of parentheses around the checks
against the border box's height and width:
Before:
if (bbox != null && bbox.getWidth() == 0 || bbox.getHeight() == 0) {
Should probably be:
if (bbox != null && (bbox.getWidth() == 0 || bbox.getHeight() == 0)) {
I checked the current bug list but could not find this issue during a quick
check. I apologize if I missed it. If additional issues (malformed svg,
configuration, ...) may be the root cause as well, additional information would
be much appreciated.
Best regards,
Tobias