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
Contributor
Posts: 44
Registered: ‎06-07-2010
My Device: 9630
My Carrier: Verizon

URLEncodedPostData.getBytes() and Illegal State Exception

I'm having a problem with URLEncodedPostData.getBytes() generating Illegal State Exception in a specific situation.  Although I did get around it by opting for a completely different way of encoding my data, but was still curious as to why I was having the original issue in the first place.

 

The exception is generated only when the device has Encryption enabled and is also in locked mode.  Following is a snippet of my code involved:

 

URLEncodedPostData encodedData = new URLEncodedPostData(URLEncodedPostData.DEFAULT_CHARSET, false);
encodedData.append("m", "blackberry");
byte[] postData = encodedData.getBytes();

 

The last line is where the exception occurs.  Odd thing is, no exception is generated if the Encryption is disabled for the device/simulator or if it's not in a locked mode.  Any insight into this will be appreciated.

Developer
Posts: 604
Registered: ‎12-27-2010
My Device: Not Specified

Re: URLEncodedPostData.getBytes() and Illegal State Exception

Are you able to get the message from the exception? Might help us get it figured out if it is giving you one.

Contributor
Posts: 44
Registered: ‎06-07-2010
My Device: 9630
My Carrier: Verizon

Re: URLEncodedPostData.getBytes() and Illegal State Exception

"java.lang.IllegalStateException" is the only message I get via the try-catch block.

Developer
Posts: 604
Registered: ‎12-27-2010
My Device: Not Specified

Re: URLEncodedPostData.getBytes() and Illegal State Exception

Is ise.getMessage() giving you anything or just returning null?

Contributor
Posts: 44
Registered: ‎06-07-2010
My Device: 9630
My Carrier: Verizon

Re: URLEncodedPostData.getBytes() and Illegal State Exception

It's simply returning null.

The IllegalStateException must be related to the fact that device is in LOCKED mode since that's the only situation where the exception occurs.  It also has to do with the Encryption being enabled for the device since without it, it doesn't occur.  I find that odd since I don't see why those conditions should matter to URLEncodedPostData.getBytes() call.

Developer
Posts: 604
Registered: ‎12-27-2010
My Device: Not Specified

Re: URLEncodedPostData.getBytes() and Illegal State Exception

I've had it happen to me before that the debugger claims that I have an exception on a certain line of code and it ended up being something like forgetting to put a UI update on the event thread from a separate thread. Is it possible that you have some UI update occurring while it's in that state?

Contributor
Posts: 44
Registered: ‎06-07-2010
My Device: 9630
My Carrier: Verizon

Re: URLEncodedPostData.getBytes() and Illegal State Exception

I'm familiar with the situation you're describing (happend to me also in the past), but this one is definitely a different animal.  It's such a simple line of code and the fact that it's occurring only in a specific situationi is what confuses me.  That's why I'm interested in finding out the reason even though I have found a work-around for the issue.

 

The closest reason I could find while searching on this forum is that this might be related to the following link:

 

http://supportforums.blackberry.com/t5/Java-Development/IllegalStateException-on-Connector-open/m-p/...

 

Since URLEncodedPostData.getBytes() routine is defined within the net.rim.blackberry.api.browser  package, internal implementation could be calling something that requires User confirmation (based on Encryption being enabled).  If so, I suppose there could be some UI issue conflict while being in LOCKED mode.  If this is indeed the case, then it's very counter-intuitive given that one would normally expect URLEncodedPostData.getBytes() to be used without considering such situation.

Contributor
Posts: 44
Registered: ‎06-07-2010
My Device: 9630
My Carrier: Verizon

Re: URLEncodedPostData.getBytes() and Illegal State Exception

Bump...

 

Calling Mark Sohm on this issue...

Nothing urgent, but very curious since this issue has caused me plenty of sleep-less hours trying to debug it, let alone identifying the exact config settings where the error occurs.