changeset 5748:193adf0b36f1

Fix for RT-34146: FXMLLoader no longer inject variables when controller is a private static class Reviewed by Martin Sladecek
author Lubomir Nerad <lubomir.nerad@oracle.com>
date Tue, 19 Nov 2013 14:28:17 +0100
parents 93560e195ac2
children 1ed0794d3ed3
files modules/fxml/src/main/java/javafx/fxml/FXMLLoader.java modules/fxml/src/test/java/javafx/fxml/RT_34146Test.java modules/fxml/src/test/resources/javafx/fxml/rt_34146.fxml
diffstat 3 files changed, 100 insertions(+), 7 deletions(-) [+]
line wrap: on
line diff
--- a/modules/fxml/src/main/java/javafx/fxml/FXMLLoader.java	Tue Nov 19 15:24:02 2013 +0200
+++ b/modules/fxml/src/main/java/javafx/fxml/FXMLLoader.java	Tue Nov 19 14:28:17 2013 +0100
@@ -3254,7 +3254,7 @@
         private static final int PACKAGE = 4;
         private static final int PRIVATE = 8;
         private static final int INITIAL_CLASS_ACCESS =
-                PUBLIC | PACKAGE;
+                PUBLIC | PACKAGE | PRIVATE;
         private static final int INITIAL_MEMBER_ACCESS =
                 PUBLIC | PROTECTED | PACKAGE | PRIVATE;
 
@@ -3267,14 +3267,14 @@
         private Map<String, Field> controllerFields;
         private Map<SupportedType, Map<String, Method>> controllerMethods;
 
-        public void setController(final Object controller) {
+        void setController(final Object controller) {
             if (this.controller != controller) {
                 this.controller = controller;
                 reset();
             }
         }
 
-        public void setCallerClass(final Class<?> callerClass) {
+        void setCallerClass(final Class<?> callerClass) {
             final ClassLoader newCallerClassLoader =
                     (callerClass != null) ? callerClass.getClassLoader()
                                           : null;
@@ -3284,12 +3284,12 @@
             }
         }
 
-        public void reset() {
+        void reset() {
             controllerFields = null;
             controllerMethods = null;
         }
 
-        public Map<String, Field> getControllerFields() {
+        Map<String, Field> getControllerFields() {
             if (controllerFields == null) {
                 controllerFields = new HashMap<>();
 
@@ -3307,7 +3307,7 @@
             return controllerFields;
         }
 
-        public Map<SupportedType, Map<String, Method>> getControllerMethods() {
+        Map<SupportedType, Map<String, Method>> getControllerMethods() {
             if (controllerMethods == null) {
                 controllerMethods = new EnumMap<>(SupportedType.class);
                 for (SupportedType t: SupportedType.values()) {
@@ -3430,7 +3430,6 @@
                 final int memberModifiers = method.getModifiers();
 
                 if (((memberModifiers & (Modifier.STATIC
-                                             | Modifier.ABSTRACT
                                              | Modifier.NATIVE)) != 0)
                         || ((getAccess(memberModifiers) & allowedMemberAccess)
                                 == 0)
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/modules/fxml/src/test/java/javafx/fxml/RT_34146Test.java	Tue Nov 19 14:28:17 2013 +0100
@@ -0,0 +1,64 @@
+/*
+ * Copyright (c) 2010, 2013, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+package javafx.fxml;
+
+import java.io.IOException;
+import org.junit.Assert;
+import org.junit.Test;
+
+public final class RT_34146Test {
+    @Test
+    public void testCanCallAbstractMethodFromPrivateClass() throws IOException {
+        final FXMLLoader fxmlLoader =
+                new FXMLLoader(getClass().getResource("rt_34146.fxml"));
+        
+        final ConcreteController concreteController =
+                new ConcreteController();
+        fxmlLoader.setController(concreteController);
+        final Widget widget = fxmlLoader.<Widget>load();
+        widget.fire();
+
+        Assert.assertTrue(concreteController.getActionHandlerCalled());
+    }
+
+    private static abstract class AbstractController {
+        @FXML
+        protected abstract void actionHandler();
+    }
+
+    private static final class ConcreteController extends AbstractController {
+        private boolean actionHandlerCalled;
+
+        @Override
+        protected void actionHandler() {
+            actionHandlerCalled = true;
+        }
+
+        boolean getActionHandlerCalled() {
+            return actionHandlerCalled;
+        }
+    }
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/modules/fxml/src/test/resources/javafx/fxml/rt_34146.fxml	Tue Nov 19 14:28:17 2013 +0100
@@ -0,0 +1,30 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+Copyright (c) 2010, 2012, Oracle and/or its affiliates. All rights reserved.
+DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+
+This code is free software; you can redistribute it and/or modify it
+under the terms of the GNU General Public License version 2 only, as
+published by the Free Software Foundation.  Oracle designates this
+particular file as subject to the "Classpath" exception as provided
+by Oracle in the LICENSE file that accompanied this code.
+
+This code is distributed in the hope that it will be useful, but WITHOUT
+ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+version 2 for more details (a copy is included in the LICENSE file that
+accompanied this code).
+
+You should have received a copy of the GNU General Public License version
+2 along with this work; if not, write to the Free Software Foundation,
+Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+
+Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+or visit www.oracle.com if you need additional information or have any
+questions.
+-->
+
+<?import javafx.fxml.*?>
+
+<Widget onAction="#actionHandler" />
+