Skip to content

ReflectionConfigGenerator should not generate method section in subclass for private superclass methods (was: Bug in ReflectionConfigGenerator) #1274

@sebthom

Description

@sebthom

I am trying to compile a Java cli app with GraalVM native-image and realized that it emits warnings like WARNING: Method com.example.MyCommand.setVerbosity(boolean[]) not found.

The issue was, that the setVerbosity method was declared as private method in an abstract parent command class, but ReflectionConfigGenerator generates this reflect-config.json

[
  {
    "name" : "com.example.MyCommand",
    "allDeclaredConstructors" : true,
    "allPublicConstructors" : true,
    "allDeclaredMethods" : true,
    "allPublicMethods" : true,
    "methods" : [
      { "name" : "setVerbosity", "parameterTypes" : ["[Z"] }
    ]
  },
  {
    "name" : "com.example.AbstractCommand",
    "allDeclaredConstructors" : true,
    "allPublicConstructors" : true,
    "allDeclaredMethods" : true,
    "allPublicMethods" : true,
    "fields" : [
      { "name" : "commandSpec" }
    ],
    "methods" : [
      { "name" : "setVerbosity", "parameterTypes" : ["[Z"] }
    ]
  }
]

Looking at the ReflectionConfigGenerator I realized that the logic is broken at

if (!scope.getClass().equals(method.getDeclaringClass())) {

I actually believe it should say

if (scope.get().getClass().equals(method.getDeclaringClass())) {

instead of

if (!scope.getClass().equals(method.getDeclaringClass())) {

which always evaluates to true

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions