NPE in MarlinGraphics2D

29 views
Skip to first unread message

Botond Kósa

unread,
Dec 27, 2018, 6:47:39 PM12/27/18
to marlin-renderer
Hi Laurent!

I have found 3 wrong checks in MarlinGraphics2D.java that all cause NPEs:
1. In the drawArc method, the "arc != null" should be "arc == null"
2. In the fillArc method, the "arc != null" should be "arc == null"
3. In the createPath method, the "path != null" should be "path == null"

Line numbers also seem to differ slightly from the ones in the compiled jar file. The createPath method is this in the source jar:
332    private Path2D.Float createPath(int[] xPoints, int[] yPoints, 
333                                      int nPoints, boolean close) {
334        if (path != null) {
335            path = new Path2D.Float(Path2D.WIND_EVEN_ODD, 
336                                    Math.max(1000, nPoints));
337        }
338        final Path2D.Float p = this.path;
339        p.reset();
340        p.moveTo(xPoints[0], yPoints[0]);
341        
342        for (int i = 1; i < nPoints; i++) {
343            p.lineTo(xPoints[i], yPoints[i]);
344        }
345        if (close) {
346            p.closePath();
347        }
348        return p;
349    }

I got the following NPE:
java.lang.NullPointerException: null
at org.marlin.graphics.MarlinGraphics2D.createPath(MarlinGraphics2D.java:345)
at org.marlin.graphics.MarlinGraphics2D.fillPolygon(MarlinGraphics2D.java:319)
...

It says that the NPE is thrown in line 345, but it's actually in 339 (the first dereference of p).

Botond

Laurent Bourgès

unread,
Dec 28, 2018, 5:10:29 PM12/28/18
to marlin-...@googlegroups.com
Hi Botond,
Thank you for the bug report, you're right these checks were incorrect (inverted).

I fixed them and also added a junit test covering the MarlinGraphics2D public API: passed OK.

Here is the Marlin-Graphics 0.2.4 release:

Laurent

Botond Kósa

unread,
Dec 29, 2018, 2:35:58 AM12/29/18
to marlin-renderer
Thanks for the quick fix, it works now.

Botond
Reply all
Reply to author
Forward
0 new messages