Uploaded image for project: 'Keikai'
  1. Keikai
  2. KEIKAI-332

handle exceptions better in PdfExporter

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Fixed
    • Icon: Normal Normal
    • 5.6.0
    • 5.3.0, 5.5.0
    • None
    • None

      Steps to reproduce

      1. to enforce an error during exporting pdf when drawing a chart
      add

          <library-property>
              <name>io.keikai.chart.render.server.url</name>
              <value>http://127.0.0.1:3003</value>
          </library-property>
      

      2. call PdfExporter to export demo_sample.xlsx

      Current result

      It consumes the real error and print the exception of close()

       java.io.IOException: The document has no pages.
      	at com.lowagie.text.pdf.PdfPages.writePageTree(Unknown Source)
      	at com.lowagie.text.pdf.PdfWriter.close(Unknown Source)
      	at com.lowagie.text.pdf.PdfDocument.close(Unknown Source)
      	at com.lowagie.text.Document.close(Unknown Source)
      	at io.keikai.model.impl.pdf.PdfExporter.export(PdfExporter.java:281)
      
      

      Expected Result

      print or throw the real exception. Since current implementation will hide the real root cause.

      SEVERE: failed to export
      java.io.IOException: Make sure the rendering server and network work well. Server URL: http://127.0.0.1:3003
      	at io.keikaiex.util.ChartDrawer.drawChartImage(ChartDrawer.java:98)
      
      

      PdfExport should handle all exceptions well, at least print it.

      The original use case

      On the production server, there is an error during exporting PDF. We can only see the error:
      java.io.IOException: The document has no pages.

      But the original root cause is:

      java.lang.NullPointerException
      	at sun.awt.FontConfiguration.getVersion(FontConfiguration.java:1264)
      	at sun.awt.FontConfiguration.readFontConfigFile(FontConfiguration.java:219)
      	at sun.awt.FontConfiguration.init(FontConfiguration.java:107)
      	at sun.awt.X11FontManager.createFontConfiguration(X11FontManager.java:774)
      	at sun.font.SunFontManager$2.run(SunFontManager.java:431)
      	at java.security.AccessController.doPrivileged(AccessController.java:678)
      	at sun.font.SunFontManager.<init>(SunFontManager.java:376)
      	at sun.awt.FcFontManager.<init>(FcFontManager.java:35)
      	at sun.awt.X11FontManager.<init>(X11FontManager.java:57)
      	at java.lang.J9VMInternals.newInstanceImpl(Native Method)
      	at java.lang.Class.newInstance(Class.java:1852)
      	at sun.font.FontManagerFactory$1.run(FontManagerFactory.java:83)
      	at java.security.AccessController.doPrivileged(AccessController.java:678)
      	at sun.font.FontManagerFactory.getInstance(FontManagerFactory.java:74)
      	at sun.font.SunFontManager.getInstance(SunFontManager.java:250)
      	at sun.font.FontDesignMetrics.getMetrics(FontDesignMetrics.java:264)
      	at sun.java2d.SunGraphics2D.getFontMetrics(SunGraphics2D.java:863)
      	at org.jfree.text.TextFragment.calculateDimensions(TextFragment.java:230)
      	at org.jfree.text.TextLine.calculateDimensions(TextLine.java:194)
      	at org.jfree.text.TextBlock.calculateDimensions(TextBlock.java:171)
      	at org.jfree.chart.block.LabelBlock.arrange(LabelBlock.java:316)
      	at org.jfree.chart.block.BorderArrangement.arrangeNN(BorderArrangement.java:210)
      	at org.jfree.chart.block.BorderArrangement.arrange(BorderArrangement.java:137)
      	at org.jfree.chart.block.BlockContainer.arrange(BlockContainer.java:179)
      	at org.jfree.chart.block.CenterArrangement.arrangeNN(CenterArrangement.java:284)
      	at org.jfree.chart.block.CenterArrangement.arrange(CenterArrangement.java:98)
      	at org.jfree.chart.block.BlockContainer.arrange(BlockContainer.java:179)
      	at org.jfree.chart.block.ColumnArrangement.arrangeNN(ColumnArrangement.java:320)
      	at org.jfree.chart.block.ColumnArrangement.arrangeRR(ColumnArrangement.java:264)
      	at org.jfree.chart.block.ColumnArrangement.arrange(ColumnArrangement.java:157)
      	at org.jfree.chart.block.BlockContainer.arrange(BlockContainer.java:179)
      	at org.jfree.chart.title.LegendTitle.arrange(LegendTitle.java:501)
      	at org.jfree.chart.JFreeChart.drawTitle(JFreeChart.java:1340)
      	at org.jfree.chart.JFreeChart.draw(JFreeChart.java:1222)
      	at org.jfree.chart.JFreeChart.createBufferedImage(JFreeChart.java:1411)
      	at io.keikaiex.util.ChartDrawer.drawChartImage(ChartDrawer.java:47)
      
      

      But we can't get this error at first since the exception is hidden by the previous exception.

      Ref: http://gitlab.potix.com:3000/keikai/demo/issues/1

            RaymondChao RaymondChao
            hawk hawk
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: