- About Scala
- Documentation
- Code Examples
- Software
- Scala Developers
Re: Structural types and access bug
Thu, 2009-11-26, 17:00
> 3. There should be correct class passed to the method finding
> structural method declaration. Correct one.
Unless it's not possible:(
Fri, 2009-11-27, 12:47
#2
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:(
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?