PDA

View Full Version : Bug in Count and Sum function?



Anonymous
05-31-2002, 03:11 PM
I have looked to see if this question has been answered yet but find nothing.

I have set up my reports with the available sum and count functions. But, when I view the report and then scroll through the pages, both the sum and the count keep incrementing.....even after it is being displayed. So they both just keep incrementing in value for as long as I keep changing the page.

Has anybody come across this themselves?

Cheers

Tom

Anonymous
05-31-2002, 03:37 PM
This one is fixed in the later versions. Version 0.7.2 is almost outdated (and has known bugs inside), just try the cvs version for a cleaner version.

Have more fun,
said Thomas

Anonymous
05-31-2002, 06:05 PM
Tom Ansley wrote:
> I have set up my reports with the available sum and count
> functions. But, when I view the report and then scroll
> through the pages, both the sum and the count keep
> incrementing.....even after it is being displayed. So they
> both just keep incrementing in value for as long as I keep
> changing the page.

A really good thing to do is write a small JUnit test that replicates the problem, if you can. Then when the bug gets fixed, it will stay fixed.

Thomas and I plan to extend the range of JUnit tests because it is critical that the reporting engine generates correct results...but it is also easy to break things when introducing new features. JUnit is a great tool for regression testing:

http://www.junit.org

Regards,

DG.

Anonymous
03-04-2003, 07:55 PM
Is this still a bug in jfreereport 0.7.6?

I have a report that is 30 pages long - it uses GroupSumFunctions.

For the first 11pages of the report, all GroupSum figures come out correctly, but from page 12 - 30, the GroupSum figures go a little funny - they aren't producing the proper figures. Despite all this, the 'overall report total', located in the reportfooter (that sums up each individual column in the report) is spot on. What is causing some of my GroupSum figures to come out incorrectly from the middle to the end of the report???

Anyone got a solution?? Please?!

-sandra

Anonymous
03-05-2003, 09:39 AM
Hi,

from a first look, this sounds like a clone/ or PageState bug.

The bug from May 2002 was fixed, this bug caused all GroupSums to went crazy, it seems that you discovered something new.

If you depend on the 0.7.6 version, then try to upgrade to the last CVS version, there were many bugs discovered and fixed from September to December. The last 0.7.6 version can be checked out using CVS with the Branch ID "VER_0_7_6", or can be downloaded from "www.sherito.org/jfreereport".

The preferred solution of course is to upgrade to the latest version of JFreeReport.

Have more fun,
said Thomas

Anonymous
03-06-2003, 06:58 PM
My GroupSum figures are fine for the first 10 pages of my report - but when I hit page 11 of the report, the GroupSum function figures are spitting out the exact same figures from Page 1, i.e:

* GroupSum figures on Page 1 are same as GroupSum figures on Page 11;
* GroupSum figures on Page 2 are same as GroupSum figures on Page 12;
* GroupSum figures on Page 3 are same as GroupSum figures on Page 13;
* etc, etc

I don't want to upgrade to the latest version of JFreeReport just yet, as I'm mid way through a project at the mo'.

So, was this bug fixed in the last release of 0.7.6?

Many Thanks,

-sandra

Anonymous
03-07-2003, 07:12 AM
Hi,

we didn't even know that there was such a bug...

A bug in the function cloning was found and fixed in after 0.8.0_3 was released. The bug was caused by an invalid cloning behaviour and caused bugs in all Total*Functions. This bug caused sideeffects to occur, when a report was repaginated and processed more than one time. The bugfix required a rewrite of the Functions handling of JFreeReport, so that functions are handled better.

It is almost sure that this bug is also contained in all older versions. If your sum values are only needed in the GroupFooter, then switching to the ItemSum- and ItemCountFunction is a workaround for that problem.
There is no quick-fix available, the only way to fix it is to rewrite the FunctionHandling.

If your calculated group sums are not used in the ItemBand or the GroupHeader, then it is safe to switch to the ItemSumFunction. Just replace the function class with com.jrefinery.report.function.ItemSumFunction to use the alternative function.

This function creates a running total for the specified field, in the group footer, the running total is equal to the TotalSum calculated by the TotalGroupSumFunction.

The ItemSumFunction does not use shared functions states and is therefore not afffected by the CloneBug.

Have more fun,
said Thomas

Anonymous
03-11-2003, 11:33 AM
Unfortunately I need the GroupSumFunction to insert totals into my GroupHeaders - so ItemSumFunction is no good to me.

So, the only way around this bug is to re-write the 'FunctionHandling'? Umm-ok... will check it out then..

thanks.

-sandra

Anonymous
03-11-2003, 02:18 PM
Hi,

if I remember right, the problem with that function type was, that they use a shared hashtable.

This should fix the problem for this function:
Try to change the functions implementation that a new instance of the shared memory is created on initialize instead of creating the hashtable in the constructor.

Additionally initialize all functions in the constructor of the start state:

public StartState (JFreeReport report);

The other constructor

public StartState (FinishState state);

is used to reinitialize the report processor during the repagination (by receiving a FinishState and continuing on a higher processing level). This constructor must not reinitialize the functions, or the pre-computed results get thrown away.

Have more fun,
said Thomas

sandra
03-18-2003, 06:55 AM
Hi.

Thanks for your response! Question is:

1. How do I
change the functions implementation that a new instance of the shared memory is created on initialize instead of creating the hashtable in the constructor? And where do I do this?
2. What functions should I initialise in the constructor of the start state?

Apologies if my questions are ridiculously simple - but this side of jfreereport is new to me. Please provide as much details as possible to the above questions...please?!

Thanks :)

-sandra

Taqua
03-18-2003, 02:43 PM
Hi,

for the TotalGroupSumFunction, change the implemenation of the initalize function to:



public void initialize() throws FunctionInitializeException
{
super.initialize();
if (getProperty(FIELD_PROPERTY) == null)
{
throw new FunctionInitializeException("Field is required");
}

// copied from the constructor ...
groupResult = new GroupSum();
datasource = new StaticDataSource();
parser = new DecimalFormatParser();
parser.setNullValue(ZERO);
parser.setDataSource(datasource);
results = new ArrayList();
}



Now this function does no longer share any object with anyone else... all private object references now point to new objects.

Now the initialization:



public StartState (JFreeReport report)
{
...

//call initialize on all functions, it can never be wrong :)
for&#40;int i = 0; i < getFunctions&#40;&#41;.size&#40;&#41;; i++&#41;
&#123;
try
&#123;
getFunctions&#40;&#41;.getExpression&#40;i&#41;.initialize&#40;&#41;;
&#125;
catch &#40;FunctionInitializeException fe&#41;
&#123;
// ignore me ... should not happen here ...
&#125;
&#125;
&#125;


This should solve your problem, as the functions now get reinitialized whenever a new report processing will be started. And with the change of the initialize functions above, we made sure, that no previous operation of the function will have an influence on the reinitialized version of the function.

Don't worry if the whole function cloning/handling confuses you, sometimes I think the only reason for that part of the code is to drive programmers into insanity ... :)

Have more fun,
said Thomas

sandra
03-26-2003, 01:36 PM
Hi.

I implemented the initialise function into the TotalGroupSumFunction - compiled no probs. But where do I put the StartStart() method?

I did a search of my jfreereport 0.7.6 source code and found no StartState class, to put that method into. Maybe my copy of jfreereport 0.7.6 source is missing some classes?

So...where can I get another copy of the JfreeReport 0.7.6 source code?

Thanks,

-sandra

Taqua
03-26-2003, 01:46 PM
Hi,

yes there is :)

class "com.jrefinery.report.ReportState" contains several inner class, and there is the "StartState" class. In the old days, classes were a hidden and and secret knowledge :)

Have more fun,
said Thomas

sandra
03-27-2003, 08:24 AM
Apologies for dragging this on...but the problem with the TotalGroupSumFunction is still occurring! :cry:

Ok, I put in the suggested code changes into the JFreeReport 0.7.6 source code - but I had to slightly change the code for the Start State method from:

getFunctions&#40;&#41;.getExpression&#40;i&#41;.initialize&#40;&#41;;

to:

getFunctions&#40;&#41;.getFunction&#40;i&#41;.initialize&#40;&#41;;

'cos I was getting a compile error for the initial code change:


com/jrefinery/report/ReportState.java [85:1] cannot resolve symbol
symbol : method getExpression (int)
location: class com.jrefinery.report.FunctionCollection
getFunctions().getExpression(i).initialize();

1 error
Errors compiling ReportState.


I compiled the JFreeReport source code and put the source code into the classpath of my project, and removed the 'previous version' jfreereport-0.7.6.jar from my classpath.

I debugged my project to make sure that it was using the methods and code changes suggested in this forum...(i.e. TotalGroupSumFunction.initialize() AND ReportState.Start())....but the problem with the TotalGroupSum is still happening - the code changes have made no difference to the TotalGroupSum figures (from page 11 onwards, in the report). :(

Where should I go from here? What else could possibly be causing my problem??

-sandra

sandra
03-27-2003, 11:41 AM
OK! I changed a bit of code in two classes and my report is now working!! :D

In ReportStateList.java, I changed the code from:

private static final int MASTERPOSITIONS = 10;

to:

private static final int MASTERPOSITIONS = 100;

And in KeyedQueue, I changed the code in the constructor from:

this &#40;10&#41;;

to:

this &#40;100&#41;;

Making these changes, seems to have fixed my problem of TotalGroupSum figures 'repeating' themselves after page 10.

Question is - will changing the above classes from 10 to 100 have any negative impact on other SumFunctions? Should I have used a number smaller than 100??

thanks.

-sandra

Taqua
03-28-2003, 02:28 PM
Hi,

argh! Right, the ReportStateList does also replay the report and therefore this can also have an impact. My apologies, a long time passed by since I touched that code :)

Changing the MasterPositions should not have a negative impact on the report itself, you may notice a slowdown when browsing through the report pages in the preview, but the reporting itself will not suffer in any way.

These masterpositions define fallback points, on which the report should be restarted if the garbage collector destroyed one of the saved states. The main purpose of this class is to keep the memory footprint small. As long as your reports are small (< 100 pages), this list is not really needed, as the overall memory consumption of the report states won't be that huge. If in doubt (and your reports are no >100 page reports, you could simply replace the used WeakReferenceList by an ordinary list without any negative impact.

The 100 pages I mention here, are fully fictional :) Depending on your available memory, this value can be extended to 1000 or more without problems ... but 100 is a fairly safe value.

The KeyedQueue is not connected to the problem (and is only used in the ImageReferenceFilter). The change in that class just increases the default size of the contained List to 100. This change has no impact at all (except a small loss of performance :) ).

If your reports are expected to grow to more than 100 pages, you should consider increasing the value (or just removing the WeakReferenceList, to be sure).

Have more fun,
said Thomas