getValue fails with NPE on obtained width
Ansgar Radermacher <[email protected]> Tue, 22 Aug 2017 13:46:47 +0200
| Newsgroups | gmane.text.xml.batik.user |
|---|---|
| Message-ID | <[email protected]> |
--------------3EAADC075FFC96F956D5F2B3
Content-Type: text/plain; charset=iso-8859-15; format=flowed
Content-Transfer-Encoding: 7bit
Dear all,
we have the following bug in in Papyrus
*Bug 521232* <https://bugs.eclipse.org/bugs/show_bug.cgi?id=521232>
-[All diagrams] NPE if SVG unit is not in pixels
This bug is caused by calling getValue() in the following way
(simplified to ease explanation)
SVGSVGElement svgRoot = svgDocument.getRootElement();
SVGAnimatedLength width = svgRoot.getWidth();
SVGLength baseWidth = width.getBaseVal();
if (baseWidth != null) {
svgWidth = baseWidth.getValue(); // NPE occurs here
...
The NPE during the call of getValue occurs, if the svgRoot above belongs
to an SVG file created with inkscape and units are in mm (default in
Europe). A sample file can be downloaded from the Papyrus forum, see
https://www.eclipse.org/forums/index.php/m/1771137/#msg_1771137
Thread [main] (Suspended (exception NullPointerException))
AbstractSVGLength$DefaultContext.getPixelUnitToMillimeter() line:
not available [local variables unavailable]
UnitProcessor.svgToUserSpace(float, short, short,
UnitProcessor$Context) line: not available
AbstractSVGAnimatedLength$BaseSVGLength(AbstractSVGLength).getValue()
line: not available [local variables unavailable]
LinkLFSVGNodePlateFigure(SVGNodePlateFigure).getSvgDimension(SVGDocument)
line: 212
...
value of baseWidth in case of error.
AbstractSVGAnimatedLength$BaseSVGLength (id=1092)
unitType 1
valid false
value 0.0
Yet the code works, if getValueInSpecifiedUnits() instead of getValue()
is used. Thus, my question is: do we use batik in a wrong way,
e.g.should be always getValueInSpecifiedUnits or is this a bug in batik
which we should report?
Best regards
Ansgar
PS: The SVG tag flowRoot seems to be non-supported. Since that is a
different issue, I will create a separate post.
--
Ansgar Radermacher CEA/DRT/DILS/LISE
http://www-list.cea.fr/en/
phone: +33 16908 3812
mailto: [email protected]
--------------3EAADC075FFC96F956D5F2B3
Content-Type: text/html; charset=iso-8859-15
Content-Transfer-Encoding: quoted-printable
<html>
<head>
<meta http-equiv=3D"content-type" content=3D"text/html; charset=3Diso=
-8859-15">
</head>
<body text=3D"#000000" bgcolor=3D"#FFFFFF">
<p>Dear all,</p>
<p>we have the following bug in in Papyrus<br>
</p>
<p><a href=3D"https://bugs.eclipse.org/bugs/show_bug.cgi?id=3D521232"=
><b>Bug=A0521232</b></a>
-<span id=3D"summary_alias_container"> <span
id=3D"short_desc_nonedit_display">[All diagrams] NPE if SVG uni=
t
is not in pixels</span></span></p>
<p><span id=3D"summary_alias_container"><span
id=3D"short_desc_nonedit_display">This bug is caused by calling=
getValue() in the following way (simplified to ease
explanation)</span></span></p>
<p>SVGSVGElement <span id=3D"summary_alias_container"><span
id=3D"short_desc_nonedit_display">svgRoot</span></span> =3D
svgDocument.getRootElement();<br>
<span id=3D"summary_alias_container"><span
id=3D"short_desc_nonedit_display">SVGAnimatedLength width =3D
svgRoot.getWidth();<br>
SVGLength baseWidth =3D width.getBaseVal();<br>
if (baseWidth !=3D null) {<br>
=A0=A0 svgWidth =3D baseWidth.getValue();=A0=A0 // NPE occurs h=
ere<br>
=A0=A0 ...<br>
<br>
The NPE during the call of getValue occurs, if the svgRoot
above belongs to an SVG file created with inkscape and units
are in mm (default in Europe). A sample file can be downloaded
from the Papyrus forum, see
<a class=3D"moz-txt-link-freetext" href=3D"https://www.eclipse.=
org/forums/index.php/m/1771137/#msg_1771137">https://www.eclipse.org/foru=
ms/index.php/m/1771137/#msg_1771137</a><br>
</span></span></p>
<span id=3D"summary_alias_container"><span
id=3D"short_desc_nonedit_display">Thread [main] (Suspended
(exception NullPointerException))=A0=A0=A0 <br>
=A0=A0=A0 AbstractSVGLength$DefaultContext.getPixelUnitToMillimet=
er()
line: not available [local variables unavailable]=A0=A0=A0 <br>
=A0=A0=A0 UnitProcessor.svgToUserSpace(float, short, short,
UnitProcessor$Context) line: not available<br>
=A0=A0=A0
AbstractSVGAnimatedLength$BaseSVGLength(AbstractSVGLength).getVal=
ue()
line: not available [local variables unavailable]<br>
=A0=A0=A0
LinkLFSVGNodePlateFigure(SVGNodePlateFigure).getSvgDimension(SVGDocument)=
line: 212<br>
=A0=A0=A0 ...</span></span>
<p><span id=3D"summary_alias_container"><span
id=3D"short_desc_nonedit_display"><br>
</span></span></p>
<p><span id=3D"summary_alias_container"><span
id=3D"short_desc_nonedit_display">value of baseWidth in case of=
error.<br>
AbstractSVGAnimatedLength$BaseSVGLength=A0 (id=3D1092)<br>
=A0=A0=A0 unitType=A0=A0=A0 1=A0=A0=A0 <br>
=A0=A0=A0 valid=A0=A0=A0 false=A0=A0=A0 <br>
=A0=A0=A0 value=A0=A0=A0 0.0=A0=A0 </span></span><span
id=3D"summary_alias_container"><span
id=3D"short_desc_nonedit_display"><br>
<br>
<br>
Yet the code works, if getValueInSpecifiedUnits() instead of
getValue() is used. Thus, my question is: do we use batik in a
wrong way, e.g.should be always getValueInSpecifiedUnits or is
this a bug in batik which we should report?</span></span></p>
<p><span id=3D"summary_alias_container"><span
id=3D"short_desc_nonedit_display">Best regards</span></span></p=
>
<p><span id=3D"summary_alias_container"><span
id=3D"short_desc_nonedit_display">Ansgar<br>
</span></span></p>
<p><span id=3D"summary_alias_container"><span
id=3D"short_desc_nonedit_display"><br>
</span></span></p>
<p><span id=3D"summary_alias_container"><span
id=3D"short_desc_nonedit_display">PS: The SVG </span></span><sp=
an
class=3D"MsgBodyText">tag flowRoot seems to be non-supported.
Since that is a different issue, I will create a separate post.</=
span></p>
--
<pre class=3D"moz-signature" cols=3D"72">Ansgar Radermacher =
CEA/DRT/DILS/LISE
<a class=3D"moz-txt-link-freetext" href=3D"http://www-list.cea.fr/en/">ht=
tp://www-list.cea.fr/en/</a>
phone: +33 16908 3812
mailto: <a class=3D"moz-txt-link-abbreviated" href=3D"mailto:ansgar.rader=
[email protected]">[email protected]</a>
</pre>
</body>
</html>
--------------3EAADC075FFC96F956D5F2B3--