DO NOT REPLY TO THIS EMAIL, BUT PLEASE POST YOUR BUGĀ·
RELATED COMMENTS THROUGH THE WEB INTERFACE AVAILABLE AT
<http://issues.apache.org/bugzilla/show_bug.cgi?id=42381>.
ANY REPLY MADE TO THIS MESSAGE WILL NOT BE COLLECTED ANDĀ·
INSERTED IN THE BUG DATABASE.

http://issues.apache.org/bugzilla/show_bug.cgi?id=42381

           Summary: NullPointerException in JSVGScrollPane.getViewBoxRect
                    when loading svg document with no viewBox attribute
           Product: Batik
           Version: 1.7
          Platform: PC
        OS/Version: Linux
            Status: NEW
          Keywords: ErrorMessage
          Severity: normal
          Priority: P4
         Component: SVG Viewer
        AssignedTo: [email protected]
        ReportedBy: [EMAIL PROTECTED]
                CC: [EMAIL PROTECTED]


When loading a document with no 'viewBox' attribute in the header, the last line
of the JSVGScrollPane.getViewBoxRect method throws a NullPointerException.  This
happens because the GraphicsNode (gn) is present (not null), but 'getBounds()'
returns null, so 'gn.getBounds().clone()' on the last line of the method throws
NullPointerException.

Suggested fix:
at the end of the JSVGScrollPane.getViewBoxRect method,
change
        return (Rectangle2D)gn.getBounds().clone();
to
        Rectangle2D bounds = gn.getBounds();
        if (bounds == null) return null;

        return (Rectangle2D) bounds.clone();
[end patch]

Impact of bug:  The bug is annoying but not severe: 
EventDispatcher.dispatchEvent catches the exception (as Throwable) and does
'.printStackTrace()', sending it to System.err.  It's annoying and causes people
to get nervous, to see a NullPointerException in the output/log every time an
image is loaded.  But other than that, the effect of the exception is about the
same as more careful null checking and returning null, as is done in most other
cases in the JSVGScrollPane.getViewBoxRect method:  Returning null pretty much
causes the callers to avoid doing any further processing, and the exception
accomplishes the same result, less gracefully.   ;->

Has been observed in both Microsoft Windows and Linux environments.


Example problem document:
<?xml version="1.0" standalone="no"?>
<svg xmlns="http://www.w3.org/2000/svg"; id="body" width="2048" height="1536" 
></svg>

Example good document:
<?xml version="1.0" standalone="no"?>
<svg xmlns="http://www.w3.org/2000/svg"; id="body" width="2048" height="1536"
viewBox="0 0 800 600" ></svg>


Stack trace:
java.lang.NullPointerException
        at 
org.apache.batik.swing.JSVGScrollPane.getViewBoxRect(JSVGScrollPane.java:607)
        at
org.apache.batik.swing.JSVGScrollPane.checkAndSetViewBoxRect(JSVGScrollPane.java:584)
        at 
org.apache.batik.swing.JSVGScrollPane.resizeScrollBars(JSVGScrollPane.java:451)
        at
org.apache.batik.swing.JSVGScrollPane$ScrollListener.gvtRenderingCompleted(JSVGScrollPane.java:391)
        at 
org.apache.batik.swing.gvt.GVTTreeRenderer$4.dispatch(GVTTreeRenderer.java:193)
        at 
org.apache.batik.util.EventDispatcher.dispatchEvent(EventDispatcher.java:103)
        at 
org.apache.batik.util.EventDispatcher.fireEvent(EventDispatcher.java:87)
        at org.apache.batik.util.EventDispatcher$1.run(EventDispatcher.java:46)
        at java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:199)
        at java.awt.EventQueue.dispatchEvent(EventQueue.java:461)
        at
java.awt.EventDispatchThread.pumpOneEventForHierarchy(EventDispatchThread.java:242)
        at
java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:163)
        at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:157)
        at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:149)
        at java.awt.EventDispatchThread.run(EventDispatchThread.java:110)

-- 
Configure bugmail: http://issues.apache.org/bugzilla/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are the assignee for the bug, or are watching the assignee.

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to