[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Incorrect return value



ozone CVS 9 Oct, Win/NT4.0, Sun SDK 1.3, Sun JRE 1.3, Forte 2.0.

A method in my application is returning an incorrect value.

The processing involves some recursion and the value being returned is  from 
the previous invocation of the same method. This example starts with an id 
of M102 which requires the evaluation of a string expression to derive its 
score. My comments are in [].

#1. The processing is initiated from the client side with:
     System.out.println(profile.getFinalScore(pComp.getId()));
    [this is the first call to this method, the pComp.getId is M102.]

the next method is:

#2. Profile public float getFinalScore(String pcId) {
    if (!profileComponentScores.containsKey(pcId)) {
       // the score isn't stored
       // look up the ProfileComponent by the pcId
       ProfileComponent pComp = (ProfileComponent) ((Map) 
Repository.getRepository(RepositoryType.PROFILECOMPONENTBYID)).get(pcId);
       // calculate and store the score
       float score = pComp.calculateFinalScore(this); 
System.out.println(pcId + " at profile " + score);
       profileComponentScores.put(pcId, new Float(score));
          }
      // return the stored score
      return ((Float)profileComponentScores.get(pcId)).floatValue();
    }
[since no scores are stored at this point every invocation results in a call 
to pComp.calculateFinalScore below]

#3 ProfileComponent:
public float calculateFinalScore(Profile p) {
   float score = getScoreCalculator().calculateFinalScore(p, this);      
System.out.println(id + " " + score);
   return score ;
}
[this method just passes the call through to the calculator]

[The calculator method calls a static method in a JavaCC parser/evaluator 
with the expression which in this case is (M40+M11)/2. ]

#4. Calculator.
public float calculateFinalScore(Profile profile, ProfileComponent pComp) {
            float score = 
PCIdExpressionEvaluator.evaluateExpression(expression, profile);
            System.out.println(((ProfileComponent)pComp).getId() + " 
returned score = " + score);
            return score;
        }

[The parser evaluates (M40+M11)/2 and return the result. It calls the same 
Profile.getFinalScore method that started this process with the M40 & M11 
ids as arguements. This is where the recursion occurs. The output from this 
iteration of the process follows. The process output lines start with **]

--------------------------------------------------------

** Wise Risk Taker M102 Expression Based Calculator [initial call to #2 
getFinalScore}
** (M40+M11)/2  [the expression]
** defaultCalculator Analyzes Pitfalls [second call to #2 getFinalScore, 
initiated by the expression evaluator]
** M40 scoreAtCalculator 3.7777777  [M40 score at #4 the calculator ]
** M40 3.7777777  [score at #3 the ProfileComponent pass through]
** M40 at profile 3.7777777 [near end of second call to #2]
** defaultCalculator Risking [the third call to #2, initiated by the 
expression evalator]
** M11 scoreAtCalculator 9.111111 [M11 score at #4 the calculator ]
** M11 9.111111  [score at #3 the ProfileComponent pass through]
** M11 at profile 9.1111111 [near end of 3rd call to #2]
** Result = 6.444444 [M102 score at the JavaCC expression evaluator, this is 
correct]
** M102 returned score = 6.444444 [score at #4 the calculator ]
** M102 6.444444 [score at #3 the ProfileComponent pass through, still fine]
** M102 at profile 9.111111 [now the initial call to #2 getFinalScore is 
back at the profile. oops!, should be 6.4444444. ]

------------------------------------------------------

Note that erroneous 9.1111111 value for M102 is the value from the previous 
call to #2 getFinalScore for M11.

I've stepped through the ozone processing from the #3 ProfileComponent 
return statement for the initial M102 iteration back to the calling 
statement in #2. The return value is correct (6.4444444) up through the 
DbInvoke.perform(Transaction) method during the ozone processing. However at 
DBLocalClient.send(Object) the return value has changed to 9.1111111 and the 
proxy id has also changed. The value returned to the method #2 is 9.1111111 
as shown above.

Sorry for the length of this, I hope it's clear enough to understand.
Any help would be greatly appreciated. Please let me know if there is any 
other information or any additional debugging I can do which would be 
helpful. I've recreated the database, the proxies, ozone, rewritten methods, 
etc. without success.

thanks,

don
_________________________________________________________________________
Get Your Private, Free E-mail from MSN Hotmail at http://www.hotmail.com.

Share information about yourself, create your own public profile at 
http://profiles.msn.com.