fujaba / fulibFx

A framework for JavaFX applications that is designed for MVC pattern projects.
https://fujaba.github.io/fulibFx/
MIT License
2 stars 0 forks source link

Component sidecar accessing protected property `children` when extending `javafx.scene.Parent` #113

Closed ruffrick closed 2 months ago

ruffrick commented 2 months ago

Describe the bug The generated sidecar classes for components extending javafx.scene.Parent tries to access the components children property, which is protected in Parent. Only children of javafx.scene.layout.Pane, itself a child of Parent, have this property publicly accessible, resulting in an exception when creating components extending e.g. javafx.scene.control.ListView. The exception only occurrs if the component specifies a view resource (FXML).

To Reproduce Steps to reproduce the behavior:

  1. Create a class extending ListView (a child of Parent but not of Pane)
  2. Annotate the Class with @Component and specify the view argument
  3. Create a corresponding FXML file
  4. Compile & See error

Expected behavior The component is appropriately initialized and rendered.

Desktop

Additional context Relevant fulibFx snippet: https://github.com/fujaba/fulibFx/blob/master/annotation-processor/src/main/java/org/fulib/fx/FxClassGenerator.java#L306-L307

// javafx.scene.Parent
protected ObservableList<Node> getChildren() {
    return children;
}
// javafx.scene.layout.Pane
@Override public ObservableList<Node> getChildren() {
    return super.getChildren();
}
LeStegii commented 2 months ago

Thanks for the report, when not using the annotation processor, everything should work fine as then reflection is used to access the method:

if (root instanceof Parent parent) {
    ReflectionUtil.getChildrenList(instance.getClass(), parent).clear();
}

This should therefore be a relatively easy fix.

Clashsoft commented 2 months ago

@LeStegii We could statically check whether the component type extends Pane in the processor and have it decide whether to generate the efficient getChildren call or the ReflectionUtil fallback.

LeStegii commented 2 months ago

Yep, I'd have suggested the same thing. We could also implement this in the reflection sidecar.

Clashsoft commented 2 months ago

I will do that.