Hi Eric, just a brief follow-up on this. As per your suggestion I declared the field in the controller this way: FXML private TreeView<Path> treeView
And now everything is working again as expected without cast. *>> There have been recent changes in the area of raw types (TreeView field in this case). Instead of holding T as "?" or "? extends Object", it is now resolved to the erasure type "Object"* Good to know for the future. Thank you, Mirco Il Mar 3 Dic 2024, 15:49 Milles, Eric (TR Technology) < eric.mil...@thomsonreuters.com> ha scritto: > There have been recent changes in the area of raw types (TreeView field in > this case). Instead of holding T as "?" or "? extends Object", it is now > resolved to the erasure type "Object". So, TreeCell<Path> is not > compatible with TreeCell<Object> and an error is emitted. > > If you specified your field with a type argument, the return type checking > should be okay: > > @FXML private TreeView<Path> treeView > > > ------------------------------ > *From:* Mirco Colletta <mirch...@gmail.com> > *Sent:* Monday, December 2, 2024 4:42 PM > *To:* dev@groovy.apache.org <dev@groovy.apache.org> > *Cc:* Milles, Eric (TR Technology) <eric.mil...@thomsonreuters.com> > *Subject:* Re: [EXT] Static type checking error from groovy version 4.0.22 > > Hi Eric, > actually there isn't an explicit instantiation of the treeView in the code > since it's defined inside an .fxml file: > > <TreeView fx:id="treeView" styleClass="folder-tree" maxWidth="Infinity" > maxHeight="Infinity" VBox.vgrow="ALWAYS"/> > > that is eventually loaded inside the controller: > > FXMLLoader fxmlLoader = new > FXMLLoader(getClass().getResource(getClass().getSimpleName() + ".fxml")) > ... > fxmlLoader.load() > > But in the controller declaration I didn't specify the type of the generics > > @FXML private TreeView treeView > > so maybe a recent modification made the groovy type checker more strict. > > Thanks > > Il Lun 2 Dic 2024, 21:40 Milles, Eric (TR Technology) via dev < > dev@groovy.apache.org> ha scritto: > > The missing info from your description for me is how treeView is > declared. When I ensure that treeView is an instance of TreeView<Path>, > the checks work out fine. > > > interface Callback<P,R> { > R call(P param) > } > class TreeCell<T> { > } > class TreeView<T> { > void setCellFactory(Callback<TreeView<T>,TreeCell<T>> value) { > } > } > class Path { } > class PathTreeCell extends TreeCell<Path> { } > > *@groovy.transform.TypeChecked* test() { > def treeView = new TreeView<Path>() // not TreeView or TreeView<?> > treeView.setCellFactory({ /*TreeView<Path>*/ p -> > def treeCell = new PathTreeCell() > return treeCell > }) > } > > > ------------------------------ > *From:* Milles, Eric (TR Technology) via dev <dev@groovy.apache.org> > *Sent:* Monday, December 2, 2024 9:45 AM > *To:* dev@groovy.apache.org <dev@groovy.apache.org> > *Cc:* Milles, Eric (TR Technology) <eric.mil...@thomsonreuters.com> > *Subject:* Re: [EXT] Static type checking error from groovy version 4.0.22 > > Micro, > Please create a new bug report at issues.apache.org > <https://urldefense.com/v3/__http://issues.apache.org__;!!GFN0sa3rsbfR8OLyAw!ZOfYR2D6zT7F52tmV8qCubBdUFRDQNPfX56LZWLNMCdJMavUdhHk16eT0jgS-b3W4VkAxN5J0w3lU_GMAmvD7m8$> > and > I will have a look at what changed. > ------------------------------ > *From:* Mirco Colletta <mirch...@gmail.com> > *Sent:* Saturday, November 30, 2024 12:20 PM > *To:* dev@groovy.apache.org <dev@groovy.apache.org> > *Subject:* [EXT] Static type checking error from groovy version 4.0.22 > > *External Email:* Use caution with links and attachments. > > Hello, > recently I've updated the groovy version of my project (STC with > compiler-configuration) from 4.0.21 to 4.0.24 and in the process I've > encountered the following unexpected error: > *[Static type checking] - Cannot return value of type ...PathTreeCell for > closure expecting javafx.scene.control.TreeCell<java.lang.Object>* > (after further investigation it seems introduced from v4.0.22) > > The error came up calling this method of the JavaFx *TreeView *(with a > closure) > > https://openjfx.io/javadoc/21/javafx.controls/javafx/scene/control/TreeView.html#setCellFactory(javafx.util.Callback) > <https://urldefense.com/v3/__https://openjfx.io/javadoc/21/javafx.controls/javafx/scene/control/TreeView.html*setCellFactory(javafx.util.Callback)__;Iw!!GFN0sa3rsbfR8OLyAw!bhkxAtKCcCoBP6_yq_UXSTJtpdyaaP3fx207yBuyP6IrCOCFSCZBuachWG4pzvoKw3JK31poWMrMii3T5yhIza0$> > public final void setCellFactory(Callback<TreeView<T>,TreeCell<T>> value) > > My code: > public class PathTreeCell extends TreeCell<Path> { … } > ... > treeView.setCellFactory({ p -> > var treeCell = new PathTreeCell(this) > makeDraggable(treeCell) > > *// This doesn't work anymore // return treeCell* > *return (TreeCell<Path>)treeCell // OK* > }) > > This portion of code has always worked for every version of groovy STC > I've used up until now. > As above, the workaround is effortless, just an explicit cast to > *TreeCell<Path>* > Nevertheless I'm worried that it could be some sort of side effect of a > regression. > > Is this an intentional change of behaviour or a bug? > > Cheers, > Mirco > >