weird typing issue

I have a bit of a bizzare problem with my interpreted java script. It's behaving oddly with recognising various datatypes.

I've set the following session variables at various points in the scraping sessions (not in the same script as I'm calling them back). The only difference between the problem ones (the first two) and the other is how they are set:

session.setVariable("WRITE_CSV",1);
session.setVariable("APPEND_CSV",0);

pruneCount = 0;
session.setVariable("PRUNE_ID",pruneCount);

now the problem comes with the following snippet of code:

if (!(session.getVariable("APPEND_CSV"==1))
&& session.getVariable("WRITE_CSV")==1
&& session.getVariable("PRUNE_ID")==1)
{
csvOut = new FileWriter(csvOutputFile,false);
csvOut.close();
}

which results in:

fe - export: The error message was: Error in method invocation: Method getVariable( boolean ) not found in class'com.screenscraper.scraper.ScrapingSession' : at Line: 9.

What I've worked out is that it's something to do with the difference between the literal "boolean" and the class "Boolean" (capital 'B'). So using the booleanValue() method of the Boolean class I can solve the problem:

if (!(session.getVariable("APPEND_CSV"==1).booleanValue())
&& (session.getVariable("WRITE_CSV")==1).booleanValue()
&& session.getVariable("PRUNE_ID")==1)
{
csvOut = new FileWriter(csvOutputFile,false);
csvOut.close();
}

This works ok... What I don't understand though, is that the part after the last && in the if condition DOESNT seem to need this type conversion? It will work with or without calling the 'isBoolean()' method.

I'm not sure if it's something to do with how the session.setVariable method determines types? I don't know if:

session.setVariable("WRITE_CSV",1);
normalVar = session.getVariable("WRITE_CSV");

produces normalVar as type Integer, int, String or what?

I tried explicity typing
pruneCount = 0;
as both Integer and int to see if that would make it fail but it doesn't seem to?

Can anyone offer any insight? I can work around it but it's messy...

sorry Tim... that was

sorry Tim... that was actually a typo... my apologies...

I was messing around with so many different versions of the statement at the time I made the post I accidentally copied and pasted that one. I have actually tried it exactly as you posted the corrected version with the same result as I initially posted... I double checked it after I read your post to make sure.

I suspect this is something to do with whatever is underlying the issue I posted about in another thread titled "more wierdness with session vars"

I'll point out again that I'm using an eval of pro version at the latest alpha release 4.0.57a. I wonder if it's one of those undocumented features that often pop up in alphas?

If it doesn't magically fix itself after I wake up tomorrow I'll try spawning a new VM and doing a fresh install of everything so I can test in basic, then pro v4 then the alpha pro version...

Ah..

I think this might be a little simpler than you were anticipating..

The first line of the second snippet of code you wrote:
if (!(session.getVariable("APPEND_CSV"==1))
should be
if (!(session.getVariable("APPEND_CSV")==1)

You've got a parenthesis coming in too late; It should come before your equals sign. Otherwise, (as you have it currently), you're testing if the string "APPEND_CSV" is equal to the integer 1, all before you've retrieved the session variable.

The other parts of that same if statement look alright.

That was actually a typo when

That was actually a typo when I was writing the post... I've just checked back over the code and tested it both ways again with the paranthesis fixed up and I'm still getting the same result...

I was messing around quite a lot when I wrote that post and I must have copied a wrong version...