[
https://issues.apache.org/jira/browse/POLYGENE-249?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16009242#comment-16009242
]
Niclas Hedhman commented on POLYGENE-249:
-----------------------------------------
Yes, that is confirmed with the following test...
{code:java}
public class ClassLoaderTest
{
public static void main( String[] args )
throws Exception
{
URLClassLoader cl = (URLClassLoader)
ClassLoaderTest.class.getClassLoader();
URL[] urls = cl.getURLs();
ShinyClassLoader shiny = new ShinyClassLoader( urls, cl );
Class c1 = cl.loadClass( "org.apache.polygene.ClassLoaderTest$Hello" );
Class c2 = shiny.loadClass( "org.apache.polygene.ClassLoaderTest$Abc" );
}
class Hello
{}
class Abc extends Hello
{}
public static class ShinyClassLoader extends URLClassLoader{
public ShinyClassLoader( URL[] urls, ClassLoader parent )
{
super( urls, parent );
}
@Override
public Class<?> loadClass( String classname )
throws ClassNotFoundException
{
if( !classname.startsWith(
"org.apache.polygene.ClassLoaderTest$Abc" ))
return super.loadClass( classname );
byte[] buffer = new byte[10000];
String classSlash = classname.replace( '.','/' ) + ".class";
try
{
for( URL url : getURLs() )
{
URL resource = getResource( classSlash );
InputStream inputStream = resource.openStream();
int length = inputStream.read( buffer );
defineClass( null, buffer, 0, length );
}
}
catch( Exception e )
{
e.printStackTrace();
}
return null;
}
}
}
{code}
If "shiny.loadClass(" is changed to "cl.loadClass" there is no exception.
> private and package protected types are not accessible when the should be.
> --------------------------------------------------------------------------
>
> Key: POLYGENE-249
> URL: https://issues.apache.org/jira/browse/POLYGENE-249
> Project: Polygene
> Issue Type: Bug
> Reporter: Niclas Hedhman
>
> The FragmentClassLoader creates new subclasses (_Stub) in the same package as
> its superclass. Yet, the classloading of a
> {code:java}
> package org.apache.polygene.abc;
> class Abc
> implements SomeType
> {}
> {code}
> will insist that the Abc.class is public or protected and that the
> SomeType.class is public. Otherwise an IllegalAccessException is thrown.
> {code}
> java.lang.IllegalAccessError: class org.apache.polygene.abc.Abc_Stub cannot
> access its superclass org.apache.polygene.abc.Abc
> {code}
> and
> {code}
> java.lang.IllegalAccessError: tried to access class
> org.apache.polygene.abc.SomeType from class org.apache.polygene.abc.Abc_Stub
> {code}
> This is probably because the FragmentClassLoader is doing something wrong
> regarding packages. Maybe it is not enough to give the right name to the
> class, but also have to put in some type of package reference.
> The work-around is more 'public' and 'protected' fragment types, but that is
> not ideal.
--
This message was sent by Atlassian JIRA
(v6.3.15#6346)