Fandy Akhmad
Fandy Akhmad

Reputation: 73

Error generating JasperReport in Development mode

i have problem when initialize report in program at startup. Sometime ago, it works correctly. But when i unistall JDK 1.7 update 17 to JDK 1.7 update 21, and fresh install Netbeans , the Exception exist :(

This is the error message :

Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 0
    at sun.font.ExtendedTextSourceLabel.createCharinfo(ExtendedTextSourceLabel.java:609)
    at sun.font.ExtendedTextSourceLabel.getCharinfo(ExtendedTextSourceLabel.java:509)
    at sun.font.ExtendedTextSourceLabel.getLineBreakIndex(ExtendedTextSourceLabel.java:455)
    at java.awt.font.TextMeasurer.calcLineBreak(TextMeasurer.java:325)
    at java.awt.font.TextMeasurer.getLineBreakIndex(TextMeasurer.java:561)
    at java.awt.font.LineBreakMeasurer.nextOffset(LineBreakMeasurer.java:358)
    at net.sf.jasperreports.engine.fill.SimpleTextLineWrapper.measureExactLineBreakIndex(SimpleTextLineWrapper.java:561)
    at net.sf.jasperreports.engine.fill.SimpleTextLineWrapper.measureExactLine(SimpleTextLineWrapper.java:535)
    at net.sf.jasperreports.engine.fill.SimpleTextLineWrapper.nextLine(SimpleTextLineWrapper.java:517)
    at net.sf.jasperreports.engine.fill.TextMeasurer.renderNextLine(TextMeasurer.java:649)
    at net.sf.jasperreports.engine.fill.TextMeasurer.renderParagraph(TextMeasurer.java:454)
    at net.sf.jasperreports.engine.fill.TextMeasurer.measure(TextMeasurer.java:395)
    at net.sf.jasperreports.engine.fill.JRFillTextElement.chopTextElement(JRFillTextElement.java:541)
    at net.sf.jasperreports.engine.fill.JRFillTextField.prepare(JRFillTextField.java:641)
    at net.sf.jasperreports.engine.fill.JRFillElementContainer.prepareElements(JRFillElementContainer.java:331)
    at net.sf.jasperreports.engine.fill.JRFillBand.fill(JRFillBand.java:379)
    at net.sf.jasperreports.engine.fill.JRFillBand.fill(JRFillBand.java:353)
    at net.sf.jasperreports.engine.fill.JRVerticalFiller.fillBandNoOverflow(JRVerticalFiller.java:458)
    at net.sf.jasperreports.engine.fill.JRVerticalFiller.fillPageHeader(JRVerticalFiller.java:421)
    at net.sf.jasperreports.engine.fill.JRVerticalFiller.fillReportStart(JRVerticalFiller.java:282)
    at net.sf.jasperreports.engine.fill.JRVerticalFiller.fillReport(JRVerticalFiller.java:151)
    at net.sf.jasperreports.engine.fill.JRBaseFiller.fill(JRBaseFiller.java:909)
    at net.sf.jasperreports.engine.fill.JRBaseFiller.fill(JRBaseFiller.java:822)
    at net.sf.jasperreports.engine.fill.JRFiller.fill(JRFiller.java:61)
    at net.sf.jasperreports.engine.JasperFillManager.fill(JasperFillManager.java:446)
    at net.sf.jasperreports.engine.JasperFillManager.fill(JasperFillManager.java:276)
    at net.sf.jasperreports.engine.JasperFillManager.fillReport(JasperFillManager.java:745)
    at com.ikbiz.gastroscope.controller.ReportController.initReport(ReportController.java:180)
    at com.ikbiz.gastroscope.controller.ReportController.<init>(ReportController.java:111)
    at com.ikbiz.gastroscope.view.PanelScope.<init>(PanelScope.java:32)
    at com.ikbiz.gastroscope.view.PanelEntry.initComponents(PanelEntry.java:199)
    at com.ikbiz.gastroscope.view.PanelEntry.<init>(PanelEntry.java:86)
    at com.ikbiz.gastroscope.view.Application.initComponents(Application.java:203)
    at com.ikbiz.gastroscope.view.Application.<init>(Application.java:35)
    at com.ikbiz.gastroscope.view.Application.getInstance(Application.java:43)
    at com.ikbiz.gastroscope.view.Application.main(Application.java:79)
Java Result: 1

And this is my code to initialize report.

public void initReport() {
        try {
            param.put("noMr", "0000");
            param.put("visitCode", "V-199208300000");
            param.put("templateLoco", iReportDir);
            param.put("tools", "Tools");
            param.put("medicine", "Medicine");
            param.put("result", "Data hasil disini");
            param.put("conclusion", "Data kesimpulan disini");
            param.put("suggestion", "Suggestion");
            param.put("SUBREPORT_DIR",iReportDir);

            String imageLoco = iReportDir +"image-sample.jpg";
            for (int i = 0; i < 20; i++) {        
                FileInputStream image = new FileInputStream(imageLoco);
                param.put("imgResult"+(i+1), image);
            }

            param.put("emptyImg", iReportDir+"logo.jpg");

            setTemplate("data/reports/templates/template_1.jasper");

            jasperPrint = JasperFillManager.fillReport(getTemplate(), param, DatabaseUtility.getConnection());
        } catch (JRException ex) {
            System.out.println(ex.getMessage());
        } catch (IOException ioe) {
            System.out.println(ioe.getMessage());
        }
    }

But, the And when I build to. Jar, the error disappears.

Please help, thanks before :)

Upvotes: 4

Views: 5128

Answers (3)

rockey91
rockey91

Reputation: 156

We were upgrading our jdk from b24 to b27 version of 1.6.

As we found the same problem, we got it fixed by font changes as following:

In iReport designer, for any element if we don't specify the font properties (fontName and fontSize), it will be set to default. Hope this was giving problem.

So, we "specified the font properties (esp. fontName) for every element in each of our reports" and tried. This has fixed the problem.

Root cause as expected: In older versions of jdk the font manager is handling the default properties for the elements where font property is not specified. In latest versions, may be the jdk is not able to handle the default font properties.

Upvotes: 0

sparkle
sparkle

Reputation: 168

I've also run into this issue and done a bit more testing on this. Here's the findings in short, but I've also commented on the OTN thread.

  • effected by the 1.6.0u45 and 1.7.0u21 Windows JVMs
  • only effected by the Calibri, Calibri Bold, Calibri Bold Italic, Calibri Italic and Cambria Bold fonts
  • most likely fixed in the non-public 1.6.0u51
  • fixed in 1.7.0u25

Upvotes: 3

Ryan
Ryan

Reputation: 2091

Are you using the Calibri font? I've found that this is a jdk 1.7.0_21 bug and seems to be specific to Calibri. Try switching the font to Arial and the error should go away.

If you have lots of reports and subreports to modify, this might help:

find . *.jrxml -type f -print0 |xargs -0 grep -lZ "Calibri" |xargs -0 sed -i 's/Calibri/Arial/g' 

I have an application that also calls into the same JasperFillManager method and I can confirm that I see the same stacktrace in jdk 1.7_0_21. If I changing the jdk to 1.7_0_17 or 1.7_0_07 the error does not occur. The class is in the rt.jar and as far as I know, source is not available. But 1.7 was based on openjdk and very similar source can be found at jdk7src.

Debugging the application, I can see that createCharinfo gets a StandardGlyphVector object and queries it for the number of glyphs, which returns 0. StandardGlyphVector.getGlyphCharIndices(0,0,null) then returns a non-null but empty array. The sun.font.ExtendedTextSourceLabel code doesn't check for null or empty array return cases and tries to access into the array which correctly throws the AIOOBE.

There seems to be a related bug report here.

Upvotes: 4

Related Questions