This page is no longer maintained — Please continue to the home page at www.scala-lang.org

Re: Structural types and access bug

2 replies
Vladimir Kirichenko
Joined: 2009-02-19,
User offline. Last seen 42 years 45 weeks ago.

> 3. There should be correct class passed to the method finding
> structural method declaration. Correct one.

Unless it's not possible:(

Vladimir Kirichenko
Joined: 2009-02-19,
User offline. Last seen 42 years 45 weeks ago.
Structural types and access bug

Here we have:

package a;

public abstract class A {
public abstract void m();.
public static A create() {
return new B();
}
}

class B extends A {
public void m() {
System.out.println("invoked");
}
}

Notice that instance will be with non-public access:

scala> a.A.create
res0: a.A = a.B@4c4936f3

scala> def f[X <: {def m()}](x:X) = x.m
f: [X <: AnyRef{def m(): Unit}](X)Unit

scala> f(res0)
java.lang.IllegalAccessException: Class can not access a member of
class a.B with modifiers "public"
at sun.reflect.Reflection.ensureMemberAccess(Reflection.java:65)
at java.lang.reflect.Method.invoke(Method.java:588)
at .f(:4)
at .(:7)
at .()
at RequestResult$.(:3)
at RequestResult$.()
at RequestResult$...

Class B is not accessible outside package "a" - it is the reason of exception.

There are 3 possible ways to fix:
1. Fast&Rough: method.setAccessible(true). Not good one, because
overrides all modifiers.
2. Slow: Find any parent that satisfy visibility using
getDeclaredMethod instead of getMethod. Disadvantage: could find
totally unrelated type.
3. There should be correct class passed to the method finding
structural method declaration. Correct one.

Should I fill the ticket?

dubochet
Joined: 2008-06-30,
User offline. Last seen 1 year 36 weeks ago.
Re: Re: Structural types and access bug

Hello Vladimir:

The problem you mention is a known issue.

https://lampsvn.epfl.ch/trac/scala/ticket/2318

There is a proposed fix for it: it will be part of the next batch of changes to structural method dispatch.

Cheers,
Gilles.

>> 3. There should be correct class passed to the method finding
>> structural method declaration. Correct one.
>
> Unless it's not possible:(

Copyright © 2012 École Polytechnique Fédérale de Lausanne (EPFL), Lausanne, Switzerland