harmony-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Regis <xu.re...@gmail.com>
Subject Re: [classlib] [luni] Should Improve File System Exception Messages
Date Wed, 10 Dec 2008 04:46:48 GMT


Tim Ellison wrote:
> Regis wrote:
>> I have attached a patch for this issue on JIRA.
> 
> See comments elsewhere why the patch needs some tweaking.
> 
>> I think that would be helpful to add file path in error messages when
>> throw FileNotFoundException, and that need to allocate new memory for
>> the new messages, I used hymem_allocate_memory to do this. But I don't
>> have chance to free that memory, since exception thrown, code back to
>> java. That may cause memory leak, I know define a enough large char
>> array could avoid this, but need more memory (path may be very long), is
>> there any other better way to do this? Thanks!
> 
> A code sample would be helpful to ensure I understand your situation
> correctly.
For example, the system message is "No such file or directory", I just 
like to append file path, like "No such file or directory: /home/a/c", 
so I need a new block of memory for holding the new string.
> 
> But the 'throw' in native code does not cause a function return (think
> of it as marking a pending throw upon return [1]).  The ThrowNew JNI
> call will copy the message string into a new Java String object, so you
> can free it before the native returns, i.e.
That's a little surprise, I need to refresh my head about the native 
code. Where can I find such details of JNI call? It seems JNI spec is so 
brief that I can't find more useful things.
> 
>  allocate memory
>  throw exception
>  free memory
>  return from native (causes throw to occur)
> 
> Of course, you can also just use a local var rather than allocate if you
> want too.
> 
> Make sense?
> Tim
> 

Thanks Tim, that's very clear :)

> [1] It's important to understand this, otherwise you'll be surprised
> about code running after your "native throw".  As a rule, you should
> tidy-up and return quite soon after raising the exception for clarity.
> 

Mime
View raw message