Jump to content
We've recently updated our Privacy Statement, available here ×

Infinite looping, out of memory errors


mmastrangelo

Recommended Posts

For various reasons, it is possible for the JasperReports engine to enter into an infinite loop while filling a report. Within this infinite loop, memory is slowly consumed until an OutOfMemoryError occurs, thus rendering the JVM useless until is is restarted. This behavior has been documented many times on this forum, and the typical response is that a report design issue is to blame.

 

In my opinion, this makes JasperReports a danger to run in a production environment. Our application allows users to create their own reports and run them on the system. If they make a "mistake" on the design, however, they can actually cause a memory-chewing infinite loop on the production system.

 

Is this going to be addressed in a future release? Aside from this problem, JasperReports is a great product. This is definitely a huge concern for anyone wanting to integrate it into a mission critical application.

Post edited by: mmastrangelo, at: 2006/09/28 15:35

Link to comment
Share on other sites

  • Replies 17
  • Created
  • Last Reply

Top Posters In This Topic

Teodor,

 

Thanks for replying. We have addressed this issue by introducing a tolerance level in JRVerticalFiller. The tolerance level specifies the number of loops to allow; if it is exceeded, an exception is thrown.

 

A possible solution could be to add a new attribute to the report design XML that allows users to specify such a tolerance level. This way it could be tailored to the needs of the report.

 

Thanks,

Matt

Link to comment
Share on other sites

  • 2 weeks later...

Hello,

 

The tolerance level is a solution I implemented on my own by changing the source code. It is not part of JasperReports.

 

I suggested this as a possible solution to prevent the infinite looping. I would be willing to share this code if Teodor thinks it could be useful.

 

Matt

Post edited by: mmastrangelo, at: 2006/10/10 15:07

Link to comment
Share on other sites

Hello,

 

Well I am in a situation where extremely large reports are possible and I want to put a limit to the size of a particular report, so this tolerance level seems like the perfect solution because I am gettin out of memory errors on some reports. I would really appreciate your enhancement, unless there is a standard way to do this within jasper already.

Link to comment
Share on other sites

Hi,

 

Matt did not post yet his patch.

We have thought about such a solution lately, but did not do anything in the code yet.

 

Note that even if we are going to do something about abruptly getting out of infinite loops, it will not solve the problem with your report templates not working.

 

This is because they have a layout problem and you need to review and refactor them to avoid it. Otherwise, the reports will still break, even with such patch in place.

 

So if the deadline is approaching, you'd be better off rearranging the structure of your report template, to prevent infinit loops. Avoid using large bands and paying attention to subreports.

 

I hope this helps.

Teodor

Link to comment
Share on other sites

Hello teodord:

I have solve the Infinite looping by re-layout a new report...~_~"

My partner has find out if a band large then some value,

the report will crashed

We are not sure the certainty value yet.

.

.

By the way, where I will find the "tolerance level setting

"?

Will it take some effect?

 

 

Thanks for your reply & suggestion:cheer:

 

--

We are coming from TAIWAN

Link to comment
Share on other sites

  • 11 months later...

Hi,

I have the same kind of problem :

java.lang.OutOfMemoryError: Java heap space

net.sf.jasperreports.engine.JRRuntimeException: java.lang.OutOfMemoryError: Java heap space

at net.sf.jasperreports.engine.fill.JRFillSubreport.prepare(JRFillSubreport.java:625)

at net.sf.jasperreports.engine.fill.JRFillElementContainer.prepareElements(JRFillElementContainer.java:343)

 

In my report, I have 2 subreports. In debuggage, I see that the program fill report, subreport1, subreport2, subreport2, subreport1, subreport1, subreport1 ...

 

It's normal ?

The problem run in a database but not in other database. It's data problem ?

 

I'm desperate ... an idea please ??

Link to comment
Share on other sites

  • 3 weeks later...

Hi,

 

I have the exact same problem with the subreport that ends up in a infinite loop. What I noticed is that when rendering the report, the subreport datasource call keeps rewinding, ending up in an infinite loop (next(), ..., next(), moveFirst(), next()...).

 

The subreport is in the detail section of the main report. This seems to happen only when the subreport is big enough to cause the report to overflow to more than 1 page. If the report can fit in 1 page, the report can be generated without any problem.

 

If this is a report layout issue, how do I fix the report layout? What do I have to look out for when designing the report to avoid the infinite loop problem?

 

Thanks in advance.

Henry

Link to comment
Share on other sites

  • 2 months later...

Hi,

 

Are there any work done in regards to prevent the infinite loop from happening? I have just tested the same report with version 2.0.4 and it still have the infinite loop problem. I debugged it and it boils down to the this snippet JRVerticalFiller.fillColumnBand() that ends up in an infinite loop when filling the detail section.

 

Code:

while (band.willOverflow())
{
fillColumnBreak(evaluation, evaluation);
printBand = band.fill(columnFooterOffsetY - offsetY - band.getHeight());

fillBand(printBand);
offsetY += printBand.getHeight();
}

 

columnFooterOffsetY = 726

offsetY = 234

band.getHeight() = 290

 

It just having the exact same values when it is looping.

 

I figured that it must have something to do with the detail section that might cause jasper into the infinite loop. In the detail section, there is a subreport and some static labels and text fields in it. So, I tried moving those labels and fields out of the detail section to the summary section and leaving the detail section contains only the subreport. This time the report is generated successfully, no infinite loop! Is that the cause of the infinite loop problem? Is it allow to have a detail band to have a subreport and at the same time with some labels and fields below the subreport?

 

One thing I noticed is that the summary section does not fit in the rest of the first page(expected) and it is moved to the second page but the second page have no pageHeader nor pageFooter(unexpected)? I tried adding a lastPageFooter but it did not show on the summary page either? Isn't the pageHeader and pageFooter supposed to show on all pages? Any ideas?

 

Another question - is it possible to create multiple band of the same band type, e.g., 2 detail bands? Basically, I want each detail band to hold certain fields and has its own band properties.

 

Thanks in advance for your responses.

 

Henry

Link to comment
Share on other sites

Henry,

 

I also identified that as the infinite while loop. This behavior has been very problematic for us as we allow users to customize their own reports in a production environment.

 

To address this, I have created a forked version of JRVerticalFiller that implements a tolerance level of 100 max fill attempts. This seems to have greatly reduced the occurrences of the infinite loop.

 

To implement this, the code snippet changes as follows:

 

Code:

while (band.willOverflow())
{
fillPageBreak(false, evaluation, evaluation, true);

printBand = band.fill(columnFooterOffsetY - offsetY - band.getHeight());

fillBand(printBand);
offsetY += printBand.getHeight();

loopCount++;

if (loopCount > MAX_FILL_ATTEMPTS)
{
throw new JRException("Max page band fill attempts exceeded"«»);
}
}

 

Ultimately, it would be nice if this behavior was built into the JasperReports engine. The MAX_FILL_ATTEMPTS constant could become an optional parameter.

 

Hope this helps.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×
×
  • Create New...