j2objc: The [IOSClass getDeclaredClasses] method fails when called on a class that has prefix applied

Assume I have a Java class as follows:

package com.mycompany.mysdk;

public class SomeClass {
    public class Inner {
    }
}

If I translate this Java class to Objective-C without applying a prefix, then making the following call…

IOSObjectArray *declaredClasses = [ComMycompanyMysdkSomeClass_class_() getDeclaredClasses];

… succeeds and I get a sensible array for declaredClasses.

However, if I translate the Java class to Objective-C with a prefix applied (albeit an empty prefix), then making the following call…

IOSObjectArray *declaredClasses = [SomeClass_class_() getDeclaredClasses];

… results in a JavaLangClassNotFoundException being thrown with this message: "com.mycompany.mysdk.SomeClass$Inner".

About this issue

  • Original URL
  • State: closed
  • Created 8 years ago
  • Comments: 16 (9 by maintainers)

Most upvoted comments

Right, that’s why the issue is still open. 😃

Do not use the initWithClass: method, as it’s private to j2objc’s runtime. Only use methods that are part of the public java.lang.Class API https://docs.oracle.com/javase/7/docs/api/java/lang/Class.html, which doesn’t have any public constructors.

On Wed, May 18, 2016 at 6:41 AM Adil Hussain notifications@github.com wrote:

@kstanger https://github.com/kstanger Whenever you or anyone gets around to investigating this… as well as issues around creating an IOSClass with the [IOSClass forName:] method when a prefix is applied I’m also seeing issues around the [IOSClass initWithClass:] method.

— You are receiving this because you are subscribed to this thread. Reply to this email directly or view it on GitHub https://github.com/google/j2objc/issues/746#issuecomment-220029113