You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@harmony.apache.org by Andrew Zhang <zh...@gmail.com> on 2007/04/24 14:21:17 UTC

[classlib][nio][compatibility] Harmony doesn't support to call FileLock.release by reflection.

Hi folks,

Harmony doesn't support to call FileLock.release by reflection. Following
test case shows the problem. The failure reason is that our implementation
class FileLockImpl is not public. A jira issue (
https://issues.apache.org/jira/browse/HARMONY-3743) is filed. Shall we fix
it for compatibility reason? Thanks!

public void testRelease() throws Exception {
        File f = File.createTempFile("nio", "tmp");
        RandomAccessFile raf = new RandomAccessFile(f, "rw");
        FileChannel fc = raf.getChannel();
        FileLock lock = fc.lock();
        Method releaseMethod = lock.getClass().getMethod("release",
                (Class[]) null);
        releaseMethod.invoke(lock, (Object[]) null);
    }

-- 
Best regards,
Andrew Zhang

Re: [classlib][nio][compatibility] Harmony doesn't support to call FileLock.release by reflection.

Posted by Tim Ellison <t....@gmail.com>.
Andrew Zhang wrote:
> On 4/24/07, Tim Ellison <t....@gmail.com> wrote:
>>
>> Andrew Zhang wrote:
>> > On 4/24/07, Tim Ellison <t....@gmail.com> wrote:
>> Hmm. Can you fix the app to include a "getSuperclass()" to bring it up
>> to the public FileLock type?
>> e.g.
>>   lock.getClass().getSuperclass().getMethod("release", (Class[]) null);
>>
>> (for extra credit, they should walk up until they reach the right type
>> and not assume it is a direct subclass).
> 
> 
> fixed.  using Class.forName("java.nio.channels.FileChannel") to get the
> class.

Good.

> Tim, would you please help close Harmony-3743, although I can close it (our
> jira access bug? :)).

Done.

Regards,
Tim

Re: [classlib][nio][compatibility] Harmony doesn't support to call FileLock.release by reflection.

Posted by Andrew Zhang <zh...@gmail.com>.
On 4/24/07, Tim Ellison <t....@gmail.com> wrote:
>
> Andrew Zhang wrote:
> > On 4/24/07, Tim Ellison <t....@gmail.com> wrote:
> Hmm. Can you fix the app to include a "getSuperclass()" to bring it up
> to the public FileLock type?
> e.g.
>   lock.getClass().getSuperclass().getMethod("release", (Class[]) null);
>
> (for extra credit, they should walk up until they reach the right type
> and not assume it is a direct subclass).


fixed.  using Class.forName("java.nio.channels.FileChannel") to get the
class.

Tim, would you please help close Harmony-3743, although I can close it (our
jira access bug? :)).

Regards,
> Tim
>



-- 
Best regards,
Andrew Zhang

Re: [classlib][nio][compatibility] Harmony doesn't support to call FileLock.release by reflection.

Posted by Andrew Zhang <zh...@gmail.com>.
On 4/24/07, Tim Ellison <t....@gmail.com> wrote:
>
> Andrew Zhang wrote:
> > On 4/24/07, Tim Ellison <t....@gmail.com> wrote:
> >>
> >> Andrew Zhang wrote:
> >> > Harmony doesn't support to call FileLock.release by reflection.
> >> Following
> >> > test case shows the problem. The failure reason is that our
> >> implementation
> >> > class FileLockImpl is not public. A jira issue (
> >> > https://issues.apache.org/jira/browse/HARMONY-3743) is filed. Shall
> we
> >> fix
> >> > it for compatibility reason? Thanks!
> >> <snip>
> >>
> >> Is there some application that does this, or is it hypothetical?
> >
> >
> > Yes, it's from a real application. The intention of this strange code is
> to
> > keep the code compatible with jdk1.1. (The real code even uses
> > reflection to
> > get the FileChannel and FileLock object). The application has some other
> > mechanism to identify which version of jre is running currently.
>
> Hmm. Can you fix the app to include a "getSuperclass()" to bring it up
> to the public FileLock type?
> e.g.
>   lock.getClass().getSuperclass().getMethod("release", (Class[]) null);
>
> (for extra credit, they should walk up until they reach the right type
> and not assume it is a direct subclass).


hm... ok, if we won't change the  FileLockImpl to public, I'll fix the app.
It can call "Class.forName("java.nio.channels.FileLock");" instead of
calling lock.getClass() directly.

Regards,
> Tim
>



-- 
Best regards,
Andrew Zhang

Re: [classlib][nio][compatibility] Harmony doesn't support to call FileLock.release by reflection.

Posted by Tim Ellison <t....@gmail.com>.
Andrew Zhang wrote:
> On 4/24/07, Tim Ellison <t....@gmail.com> wrote:
>>
>> Andrew Zhang wrote:
>> > Harmony doesn't support to call FileLock.release by reflection.
>> Following
>> > test case shows the problem. The failure reason is that our
>> implementation
>> > class FileLockImpl is not public. A jira issue (
>> > https://issues.apache.org/jira/browse/HARMONY-3743) is filed. Shall we
>> fix
>> > it for compatibility reason? Thanks!
>> <snip>
>>
>> Is there some application that does this, or is it hypothetical?
> 
> 
> Yes, it's from a real application. The intention of this strange code is to
> keep the code compatible with jdk1.1. (The real code even uses
> reflection to
> get the FileChannel and FileLock object). The application has some other
> mechanism to identify which version of jre is running currently.

Hmm. Can you fix the app to include a "getSuperclass()" to bring it up
to the public FileLock type?
 e.g.
  lock.getClass().getSuperclass().getMethod("release", (Class[]) null);

(for extra credit, they should walk up until they reach the right type
and not assume it is a direct subclass).

Regards,
Tim

Re: [classlib][nio][compatibility] Harmony doesn't support to call FileLock.release by reflection.

Posted by Andrew Zhang <zh...@gmail.com>.
On 4/24/07, Tim Ellison <t....@gmail.com> wrote:
>
> Andrew Zhang wrote:
> > Harmony doesn't support to call FileLock.release by reflection.
> Following
> > test case shows the problem. The failure reason is that our
> implementation
> > class FileLockImpl is not public. A jira issue (
> > https://issues.apache.org/jira/browse/HARMONY-3743) is filed. Shall we
> fix
> > it for compatibility reason? Thanks!
> <snip>
>
> Is there some application that does this, or is it hypothetical?


Yes, it's from a real application. The intention of this strange code is to
keep the code compatible with jdk1.1. (The real code even uses reflection to
get the FileChannel and FileLock object). The application has some other
mechanism to identify which version of jre is running currently.

Regards,
> Tim
>



-- 
Best regards,
Andrew Zhang

Re: [classlib][nio][compatibility] Harmony doesn't support to call FileLock.release by reflection.

Posted by Tim Ellison <t....@gmail.com>.
Andrew Zhang wrote:
> Harmony doesn't support to call FileLock.release by reflection. Following
> test case shows the problem. The failure reason is that our implementation
> class FileLockImpl is not public. A jira issue (
> https://issues.apache.org/jira/browse/HARMONY-3743) is filed. Shall we fix
> it for compatibility reason? Thanks!
<snip>

Is there some application that does this, or is it hypothetical?

Regards,
Tim