Welcome!

Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Java Development

Reply
New Developer
Posts: 6
Registered: ‎06-25-2009
My Device: Not Specified

URLEncodedPostData.toString() throws java.lang.illegalstateexception error

A seemingly benign URLEncodedPostData.toString() call is throwing a java.lang.illegalstateexception error at the final line in the following code extract, though only sometimes:

 

                    URLEncodedPostData urlPost = new URLEncodedPostData(URLEncodedPostData.DEFAULT_CHARSET, false);
                    urlPost.append("type", "time");
                    urlPost.append("message", genericContent(false));
                    urlPost.append("email", defaultEmail());
                    urlPost.append("version", _versionString);
                    urlPost.append("route", routingParams[0]);
                    urlPost.append("networkID", getNetworkId());
                    urlPost.append("LAC", getLAC());
                    String networkName = getNetworkName();
                    if (isStringEmpty(networkName))
                        networkName = "none";
                    urlPost.append("netname", networkName);
                    urlPost.append("nettype", getNetworkType());
                    urlPost.append("mins", new Integer((int)(getOptions().getTotalOutboundCallDuration()/60)).toString());
                    urlPost.append("params", Integer.toString(getOptions().getParamVersion()));
                    urlPost.append("imsi", getIMSI());
                    urlPost.append("lasterror", getOptions().getLastUpdaterError());
                    if (_reason.equals(originalReason))
                        urlPost.append("reason", _reason);
                    else
                        urlPost.append("reason", originalReason + "/" + _reason);
                    String appendThis = urlPost.toString();// sometimes throws java.lang.illegalstateexception error

I have around 25 devices running this code though only two exhibit this behaviour (and then, only sometimes).  The two affected devices are both Bolds and both are on BES (different BES accounts/customers) on different UK mobile networks. One is running 4.6.0.126, the other 4.6.0.162 (note: 162 not 126!).

 
In the case of 4.6.0.126, I have one device (also a Bold) running the same OS version and that device is not throwing the error.  For 4.6.0.162 I have no other users running that OS so can't offer any additional information there.

The API documentation doesn't even show that a java.lang.illegalstateexception is possible with a URLEncodedPostData.toString() call.  As the problem is intermittent and does not present on the majority of devices, is this perhaps an example of a bug in the 4.6.0.162 and 4.6.0.126 APIs which only occurs in certain "states"?

 

With my thanks in advance to anyone who can contribute to resolving this.

Developer
Posts: 16,997
Registered: ‎07-29-2008
My Device: Z10 LE, Z30, Passport
My Carrier: O2 Germany

Re: URLEncodedPostData.toString() throws java.lang.illegalstateexception error

are you sure you do not fiddle with the event thread? like calling setText with the string value etc?
is there a detail message on the exception? can you debug on the live device?
----------------------------------------------------------
feel free to press the like button on the right side to thank the user that helped you.
please mark posts as solved if you found a solution.
@SimonHain on twitter
New Developer
Posts: 6
Registered: ‎06-25-2009
My Device: Not Specified

Re: URLEncodedPostData.toString() throws java.lang.illegalstateexception error

Hi Simon

 

I'm not aware that I've "fiddled" with event thread.  Bear in mind that this problem is intermittent yet - so far as I know - I never fiddle with the event thread in my application.  I confess to not knowing what "fiddling" might be though I certainly don't use setText anywhere in my code since you ask about that specifically.

 

Sadly, I can't debug on the live device as it belongs to a client/user, not me.

 

And forgive me if this question's dumb, but how do I get the "detail message" on the exception? I suspect you're alluding to e.getMessage() (where e is the exception) which I haven't tried as it happens and will now.  FYI, e.toString() is returning java.lang.illegalStateException as I think you will have gathered from my original description of the problem.

 

Many thanks.

 

Peter

Developer
Posts: 16,997
Registered: ‎07-29-2008
My Device: Z10 LE, Z30, Passport
My Carrier: O2 Germany

Re: URLEncodedPostData.toString() throws java.lang.illegalstateexception error

The most likely place for an IllegalStateException to occur is when you try to modify the UI (event thread) without being able to access it. One case is a connection thread where you call Dialog.alert or update your screen without using synchronize on the eventlock or using invokelater.

It would be a rare occasion though that the problem happens only on very few devices, usually this kind of error would be detected in the simulator.
I just wanted to be sure that this can be excluded.

i would suggest that you put the suspected line of code inside a try/catch block and put the retrievable information into the eventlog.
You can post here if you are able to get a detail message from the exception and verify the line of code where the exception happens.
----------------------------------------------------------
feel free to press the like button on the right side to thank the user that helped you.
please mark posts as solved if you found a solution.
@SimonHain on twitter
New Developer
Posts: 6
Registered: ‎06-25-2009
My Device: Not Specified

Re: URLEncodedPostData.toString() throws java.lang.illegalstateexception error

Thanks again, Simon.

 

Well I'm definitely not trying to modify the event thread in any way so I think that can be ruled out.

 

The offending line of code is already in a try/catch block which is how I know which line is the culprit.  I didn't include that detail in the code sample so you wouldn't have known that, of course.

 

Are you suggesting using the event log as a means of enabling the user to report to me what's going on? I ask because the device already automatically sends error reports (such as this one) to my server over the web which is how I know about the illegalStateException as it is.  Or is there some other benefit from using the event logger that I'm missing?

 

And once again, would you please confirm what you mean by "detail message" - is it e.getMessage() as I suspect?

 

Regards, Peter

Developer
Posts: 16,997
Registered: ‎07-29-2008
My Device: Z10 LE, Z30, Passport
My Carrier: O2 Germany

Re: URLEncodedPostData.toString() throws java.lang.illegalstateexception error

yes, i mean getMessage.
You can also try to catch Throwable and use printStackTrace, it should print the stack trace on the event log.

also see
http://supportforums.blackberry.com/rim/board/message?board.id=java_dev&message.id=1845
----------------------------------------------------------
feel free to press the like button on the right side to thank the user that helped you.
please mark posts as solved if you found a solution.
@SimonHain on twitter