I just wanted to flag a small problem I came across when I accidently edited a vertex label and left it with only a carriage-return ("\n") in it. This raises a "null pointer" exception

Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException
at com.mxgraph.util.mxRectangle.<init>(mxRectangle.java:41)
at com.mxgraph.util.mxUtils.getSizeForString(mxUtils.java:358)
at com.mxgraph.util.mxUtils.getLabelSize(mxUtils.java:110)
at com.mxgraph.util.mxUtils.getLabelPaintBounds(mxUtils.java:150)
at com.mxgraph.view.mxGraphView.updateLabelBounds(mxGraphView.java:833)
at com.mxgraph.view.mxGraphView.validatePoints(mxGraphView.java:681)

My analysis (and temporary fix) are as follows:

The root appears to be that java.lang.String.split("\n") returns 1 string in array when text = "" but 0 when text = "\n" or any number of them e.g. "\n\n\n" and in this case, because processing doesn't get into the for-loop "boundingBox" is null when passed on.

The temporary fix I have applied is:

== mxUtils.java, Line 331

    String[] lines = text.split("\n");

    Rectangle2D boundingBox = null;

     // Fix to avoid null pointer when string has only carriage returns in it
     if (lines.length == 0)
         boundingBox = font.getStringBounds("", frc);                    

     for (int i = 0; i < lines.length; i++)


asked 25 Jul '12, 13:28

dazed's gravatar image

accept rate: 0%

edited 25 Jul '12, 15:59

Thanks for the fix, this will go into the next release.


answered 26 Jul '12, 03:18

Gaudenz's gravatar image

accept rate: 39%

Your answer
toggle preview

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here



Answers and Comments

Markdown Basics

  • *italic* or _italic_
  • **bold** or __bold__
  • link:[text](http://url.com/ "title")
  • image?![alt text](/path/img.jpg "title")
  • numbered list: 1. Foo 2. Bar
  • to add a line break simply add two spaces to where you would like the new line to be.
  • basic HTML tags are also supported



Asked: 25 Jul '12, 13:28

Seen: 1,332 times

Last updated: 26 Jul '12, 03:18