JavaProxyClassFactory and JavaClass should use getDeclaredConstructors to get 
all public/protected constructors
---------------------------------------------------------------------------------------------------------------

                 Key: JRUBY-2551
                 URL: http://jira.codehaus.org/browse/JRUBY-2551
             Project: JRuby
          Issue Type: Bug
          Components: Java Integration
    Affects Versions: JRuby 1.1.1
            Reporter: Charles Oliver Nutter
             Fix For: JRuby 1.1.2


This code in JavaProxyClassFactory is incorrect, since getConstructors only 
gets public constructors:

{code}
    private static void generateConstructors(Class superClass, Type selfType,
            ClassVisitor cw) {
        Constructor[] cons = superClass.getConstructors();
        for (int i = 0; i < cons.length; i++) {
            Constructor constructor = cons[i];

            int acc = constructor.getModifiers();
            if (Modifier.isProtected(acc) || Modifier.isPublic(acc)) {
                // ok, it's publix or protected
            } else if (!Modifier.isPrivate(acc)
                    && packageName(constructor.getDeclaringClass()).equals(
                            packageName(selfType.getClassName()))) {
                // ok, it's package scoped and we're in the same package
            } else {
                // it's unaccessible
                continue;
            }

            generateConstructor(selfType, constructor, cw);
        }
    }
{code}

Changing it to getDeclaredConstructors allow subclassing classes with protected 
constructors correctly. Here is a simple class and test case as well:

{code}
public class ProtectedConstructor {
  protected ProtectedConstructor() {}
}
{code}

And script:

{code}
import 'ProtectedConstructor'; class Foo < ProtectedConstructor; def 
initialize; super; end; end; Foo.new()
{code}

-- 
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators: 
http://jira.codehaus.org/secure/Administrators.jspa
-
For more information on JIRA, see: http://www.atlassian.com/software/jira

        

---------------------------------------------------------------------
To unsubscribe from this list, please visit:

    http://xircles.codehaus.org/manage_email


Reply via email to