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

PropertyFetchingImpl getPropertyViaFieldAccess algorithm cannot find private fields on abstract classes #1102

Open
meostyles opened this issue Dec 16, 2024 · 0 comments
Labels
status: waiting-for-triage An issue we've not yet triaged

Comments

@meostyles
Copy link

PropertyFetchingImpl#getPropertyViaFieldAccess first looks for the field with Class#getField where it will not find the field because internally it calls Class#privateGetDeclaredFields(publicOnly: true). This method does however try to handle if the field is on a superclass

// Direct superclass, recursively
  if (!isInterface()) {
      Class<?> c = getSuperclass();
      if (c != null) {
          if ((res = c.getField0(name)) != null) {
              return res;
          }
      }
  }

The PropertyFetchingImpl then uses Class#getDeclaredField to access private fields via setAccessible. The problem is, although that method does call Class#privateGetDeclaredFields(publicOnly: false), it does not have any handling to look for the field on the superclass.

As such, Spring for GraphQL can resolve fields like so (without any public getters)

public class MyClass {
    private final ImmutableList<Id> ids;
}

but not fields like so (without any public getters)

public abstract class MyAbstractClass {
    private final ImmutableList<Id> ids;
}
@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged label Dec 16, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status: waiting-for-triage An issue we've not yet triaged
Projects
None yet
Development

No branches or pull requests

2 participants