Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Uncaught TypeError: b is undefined when using reflection on a class that implements an interface #1008

Open
rsv-code opened this issue Feb 22, 2025 · 0 comments

Comments

@rsv-code
Copy link

I've run into an issue I haven't been able to work through with reflection. It occurs when a reflected class implements any interface. The error that's produced is something like this:

Uncaught TypeError: b is undefined

If I remove the interface from the class the error doesn't occur. The error is triggered on Class.getMethods(). I found that I can call Class.getName() without exception, it appears to only be on getMethods().

Class<?> aclass = ...
aclass.getMethods()

Here is my ReflectionSupplierImpl:

public class ReflectionSupplierImpl implements ReflectionSupplier {
    @Override
    public Collection<String> getAccessibleFields(ReflectionContext context, String className) {
        var cls = context.getClassSource().get(className);
        console.get().info("ReflectionSupplierImpl.getAccessibleFields(): " + className);
        var fields = new HashSet<String>();
        for (var field : cls.getFields()) {
            if (field.getAnnotations().get(Reflectable.class.getName()) != null) {
                fields.add(field.getName());
            }
        }
        return fields;
    }

    @Override
    public Collection<MethodDescriptor> getAccessibleMethods(ReflectionContext context, String className) {
        var cls = context.getClassSource().get(className);
        console.get().info("ReflectionSupplierImpl.getAccessibleMethods(): " + className);
        var methods = new HashSet<MethodDescriptor>();
        for (var method : cls.getMethods()) {
            if (method.getAnnotations().get(Reflectable.class.getName()) != null) {
                methods.add(method.getDescriptor());
            }
        }
        return methods;
    }
}

Thanks for your assistance.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant